auth_property_iterator_test.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #include <gtest/gtest.h>
20 
21 #include <grpc/grpc_security.h>
23 
27 
29 
30 namespace grpc {
31 namespace {
32 
33 class TestAuthPropertyIterator : public AuthPropertyIterator {
34  public:
35  TestAuthPropertyIterator() {}
36  TestAuthPropertyIterator(const grpc_auth_property* property,
38  : AuthPropertyIterator(property, iter) {}
39 };
40 
41 class AuthPropertyIteratorTest : public ::testing::Test {
42  protected:
43  void SetUp() override {
44  ctx_ = grpc_core::MakeRefCounted<grpc_auth_context>(nullptr);
45  grpc_auth_context_add_cstring_property(ctx_.get(), "name", "chapi");
46  grpc_auth_context_add_cstring_property(ctx_.get(), "name", "chapo");
47  grpc_auth_context_add_cstring_property(ctx_.get(), "foo", "bar");
49  "name"));
50  }
52 };
53 
54 TEST_F(AuthPropertyIteratorTest, DefaultCtor) {
55  TestAuthPropertyIterator iter1;
56  TestAuthPropertyIterator iter2;
57  EXPECT_EQ(iter1, iter2);
58 }
59 
60 TEST_F(AuthPropertyIteratorTest, GeneralTest) {
63  const grpc_auth_property* property =
65  TestAuthPropertyIterator iter(property, &c_iter);
66  TestAuthPropertyIterator empty_iter;
67  EXPECT_FALSE(iter == empty_iter);
68  AuthProperty p0 = *iter;
69  ++iter;
70  AuthProperty p1 = *iter;
71  iter++;
72  AuthProperty p2 = *iter;
73  EXPECT_EQ("name", ToString(p0.first));
74  EXPECT_EQ("chapi", ToString(p0.second));
75  EXPECT_EQ("name", ToString(p1.first));
76  EXPECT_EQ("chapo", ToString(p1.second));
77  EXPECT_EQ("foo", ToString(p2.first));
78  EXPECT_EQ("bar", ToString(p2.second));
79  ++iter;
80  EXPECT_EQ(empty_iter, iter);
81 }
82 
83 } // namespace
84 } // namespace grpc
85 
86 int main(int argc, char** argv) {
87  ::testing::InitGoogleTest(&argc, argv);
88  return RUN_ALL_TESTS();
89 }
EXPECT_FALSE
#define EXPECT_FALSE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1970
grpc
Definition: grpcpp/alarm.h:33
secure_auth_context.h
ctx_
ClientContext ctx_
Definition: client_interceptors_end2end_test.cc:289
grpc_security.h
main
int main(int argc, char **argv)
Definition: auth_property_iterator_test.cc:86
testing::Test
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:402
grpc_auth_property_iterator_next
const GRPCAPI grpc_auth_property * grpc_auth_property_iterator_next(grpc_auth_property_iterator *it)
Definition: security_context.cc:182
grpc_auth_context_set_peer_identity_property_name
GRPCAPI int grpc_auth_context_set_peer_identity_property_name(grpc_auth_context *ctx, const char *name)
Definition: security_context.cc:151
grpc_core::RefCountedPtr< grpc_auth_context >
ToString
std::string ToString(const grpc::string_ref &r)
Definition: string_ref_helper.cc:24
grpc_auth_property_iterator
Definition: grpc_security.h:36
grpc_auth_context_add_cstring_property
GRPCAPI void grpc_auth_context_add_cstring_property(grpc_auth_context *ctx, const char *name, const char *value)
Definition: security_context.cc:268
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2471
grpc_auth_property
Definition: grpc_security.h:43
grpc_auth_context_property_iterator
GRPCAPI grpc_auth_property_iterator grpc_auth_context_property_iterator(const grpc_auth_context *ctx)
Definition: security_context.cc:173
security_context.h
testing::InitGoogleTest
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6106
grpc::EXPECT_EQ
EXPECT_EQ(grpc::StatusCode::INVALID_ARGUMENT, status.error_code())
grpc::AuthProperty
std::pair< string_ref, string_ref > AuthProperty
Definition: grpcpp/impl/codegen/security/auth_context.h:35
iter
Definition: test_winkernel.cpp:47
auth_context.h
string_ref_helper.h
TEST_F
#define TEST_F(test_fixture, test_name)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2367


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:45