3
* Copyright 2015, Google Inc.
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions are
10
* * Redistributions of source code must retain the above copyright
11
* notice, this list of conditions and the following disclaimer.
12
* * Redistributions in binary form must reproduce the above
13
* copyright notice, this list of conditions and the following disclaimer
14
* in the documentation and/or other materials provided with the
16
* * Neither the name of Google Inc. nor the names of its
17
* contributors may be used to endorse or promote products derived from
18
* this software without specific prior written permission.
20
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
#include <grpc++/auth_context.h>
35
#include <gtest/gtest.h>
36
#include "src/cpp/common/secure_auth_context.h"
37
#include "src/core/security/security_context.h"
42
class SecureAuthContextTest : public ::testing::Test {};
44
// Created with nullptr
45
TEST_F(SecureAuthContextTest, EmptyContext) {
46
SecureAuthContext context(nullptr);
47
EXPECT_TRUE(context.GetPeerIdentity().empty());
48
EXPECT_TRUE(context.GetPeerIdentityPropertyName().empty());
49
EXPECT_TRUE(context.FindPropertyValues("").empty());
50
EXPECT_TRUE(context.FindPropertyValues("whatever").empty());
53
TEST_F(SecureAuthContextTest, Properties) {
54
grpc_auth_context* ctx = grpc_auth_context_create(NULL, 3);
55
ctx->properties[0] = grpc_auth_property_init_from_cstring("name", "chapi");
56
ctx->properties[1] = grpc_auth_property_init_from_cstring("name", "chapo");
57
ctx->properties[2] = grpc_auth_property_init_from_cstring("foo", "bar");
58
ctx->peer_identity_property_name = ctx->properties[0].name;
60
SecureAuthContext context(ctx);
61
std::vector<grpc::string> peer_identity = context.GetPeerIdentity();
62
EXPECT_EQ(2, peer_identity.size());
63
EXPECT_EQ("chapi", peer_identity[0]);
64
EXPECT_EQ("chapo", peer_identity[1]);
65
EXPECT_EQ("name", context.GetPeerIdentityPropertyName());
66
std::vector<grpc::string> bar = context.FindPropertyValues("foo");
67
EXPECT_EQ(1, bar.size());
68
EXPECT_EQ("bar", bar[0]);
74
int main(int argc, char **argv) {
75
::testing::InitGoogleTest(&argc, argv);
76
return RUN_ALL_TESTS();