Imported Upstream version 1.33.0
[platform/upstream/grpc.git] / test / core / security / insecure_security_connector_test.cc
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
33 TEST(InsecureSecurityConnector, MakeAuthContextTest) {
34   auto auth_context = InsecureChannelSecurityConnector::MakeAuthContext();
35   // Verify that peer identity is set
36   auto it = grpc_auth_context_peer_identity(auth_context.get());
37   const grpc_auth_property* prop = grpc_auth_property_iterator_next(&it);
38   ASSERT_NE(prop, nullptr);
39   EXPECT_STREQ(prop->name, GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME);
40   EXPECT_STREQ(prop->value, kInsecureTransportSecurityType);
41   // Verify that security level is set to none
42   it = grpc_auth_context_find_properties_by_name(
43       auth_context.get(), GRPC_TRANSPORT_SECURITY_LEVEL_PROPERTY_NAME);
44   prop = grpc_auth_property_iterator_next(&it);
45   ASSERT_NE(prop, nullptr);
46   EXPECT_EQ(grpc_tsi_security_level_string_to_enum(prop->value),
47             GRPC_SECURITY_NONE);
48 }
49
50 }  // namespace
51 }  // namespace testing
52 }  // namespace grpc_core
53
54 int main(int argc, char** argv) {
55   ::testing::InitGoogleTest(&argc, argv);
56   grpc::testing::TestEnvironment env(argc, argv);
57   const auto result = RUN_ALL_TESTS();
58   return result;
59 }