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