• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 //
3 // Copyright 2020 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 <gmock/gmock.h>
20 #include <gtest/gtest.h>
21 
22 #include <grpc/grpc_security.h>
23 
24 #include "src/core/lib/security/security_connector/insecure/insecure_security_connector.h"
25 #include "src/core/lib/security/security_connector/ssl_utils.h"
26 #include "src/core/tsi/transport_security.h"
27 #include "test/core/util/test_config.h"
28 
29 namespace grpc_core {
30 namespace testing {
31 namespace {
32 
TEST(InsecureSecurityConnector,MakeAuthContextTest)33 TEST(InsecureSecurityConnector, MakeAuthContextTest) {
34   auto auth_context = TestOnlyMakeInsecureAuthContext();
35   // Verify that peer is not authenticated
36   EXPECT_EQ(auth_context->is_authenticated(), false);
37   // Verify that GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME is set
38   auto it = grpc_auth_context_find_properties_by_name(
39       auth_context.get(), GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME);
40   const grpc_auth_property* prop = grpc_auth_property_iterator_next(&it);
41   ASSERT_NE(prop, nullptr);
42   EXPECT_STREQ(prop->name, GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME);
43   EXPECT_STREQ(prop->value, kInsecureTransportSecurityType);
44   // Verify that security level is set to none
45   it = grpc_auth_context_find_properties_by_name(
46       auth_context.get(), GRPC_TRANSPORT_SECURITY_LEVEL_PROPERTY_NAME);
47   prop = grpc_auth_property_iterator_next(&it);
48   ASSERT_NE(prop, nullptr);
49   EXPECT_EQ(grpc_tsi_security_level_string_to_enum(prop->value),
50             GRPC_SECURITY_NONE);
51 }
52 
53 }  // namespace
54 }  // namespace testing
55 }  // namespace grpc_core
56 
main(int argc,char ** argv)57 int main(int argc, char** argv) {
58   ::testing::InitGoogleTest(&argc, argv);
59   grpc::testing::TestEnvironment env(argc, argv);
60   const auto result = RUN_ALL_TESTS();
61   return result;
62 }
63