Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(397)

Side by Side Diff: third_party/grpc/test/cpp/common/secure_auth_context_test.cc

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 *
3 * Copyright 2015, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
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
15 * distribution.
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.
19 *
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.
31 *
32 */
33
34 #include <grpc/grpc_security.h>
35 #include <grpc++/security/auth_context.h>
36 #include <gtest/gtest.h>
37 #include "src/cpp/common/secure_auth_context.h"
38 #include "test/cpp/util/string_ref_helper.h"
39
40 extern "C" {
41 #include "src/core/security/security_context.h"
42 }
43
44 using grpc::testing::ToString;
45
46 namespace grpc {
47 namespace {
48
49 class SecureAuthContextTest : public ::testing::Test {};
50
51 // Created with nullptr
52 TEST_F(SecureAuthContextTest, EmptyContext) {
53 SecureAuthContext context(nullptr, true);
54 EXPECT_TRUE(context.GetPeerIdentity().empty());
55 EXPECT_TRUE(context.GetPeerIdentityPropertyName().empty());
56 EXPECT_TRUE(context.FindPropertyValues("").empty());
57 EXPECT_TRUE(context.FindPropertyValues("whatever").empty());
58 EXPECT_TRUE(context.begin() == context.end());
59 }
60
61 TEST_F(SecureAuthContextTest, Properties) {
62 grpc_auth_context* ctx = grpc_auth_context_create(NULL);
63 SecureAuthContext context(ctx, true);
64 context.AddProperty("name", "chapi");
65 context.AddProperty("name", "chapo");
66 context.AddProperty("foo", "bar");
67 EXPECT_TRUE(context.SetPeerIdentityPropertyName("name"));
68
69 std::vector<grpc::string_ref> peer_identity = context.GetPeerIdentity();
70 EXPECT_EQ(2u, peer_identity.size());
71 EXPECT_EQ("chapi", ToString(peer_identity[0]));
72 EXPECT_EQ("chapo", ToString(peer_identity[1]));
73 EXPECT_EQ("name", context.GetPeerIdentityPropertyName());
74 std::vector<grpc::string_ref> bar = context.FindPropertyValues("foo");
75 EXPECT_EQ(1u, bar.size());
76 EXPECT_EQ("bar", ToString(bar[0]));
77 }
78
79 TEST_F(SecureAuthContextTest, Iterators) {
80 grpc_auth_context* ctx = grpc_auth_context_create(NULL);
81 SecureAuthContext context(ctx, true);
82 context.AddProperty("name", "chapi");
83 context.AddProperty("name", "chapo");
84 context.AddProperty("foo", "bar");
85 EXPECT_TRUE(context.SetPeerIdentityPropertyName("name"));
86
87 AuthPropertyIterator iter = context.begin();
88 EXPECT_TRUE(context.end() != iter);
89 AuthProperty p0 = *iter;
90 ++iter;
91 AuthProperty p1 = *iter;
92 iter++;
93 AuthProperty p2 = *iter;
94 EXPECT_EQ("name", ToString(p0.first));
95 EXPECT_EQ("chapi", ToString(p0.second));
96 EXPECT_EQ("name", ToString(p1.first));
97 EXPECT_EQ("chapo", ToString(p1.second));
98 EXPECT_EQ("foo", ToString(p2.first));
99 EXPECT_EQ("bar", ToString(p2.second));
100 ++iter;
101 EXPECT_EQ(context.end(), iter);
102 }
103
104 } // namespace
105 } // namespace grpc
106
107 int main(int argc, char** argv) {
108 ::testing::InitGoogleTest(&argc, argv);
109 return RUN_ALL_TESTS();
110 }
OLDNEW
« no previous file with comments | « third_party/grpc/test/cpp/common/channel_arguments_test.cc ('k') | third_party/grpc/test/cpp/end2end/async_end2end_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698