3 // Copyright 2020 gRPC authors.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "src/core/lib/security/security_connector/insecure/insecure_security_connector.h"
21 #include <gmock/gmock.h>
22 #include <gtest/gtest.h>
24 #include <grpc/grpc_security.h>
26 #include "src/core/lib/security/security_connector/ssl_utils.h"
27 #include "src/core/tsi/transport_security.h"
28 #include "test/core/util/test_config.h"
34 TEST(InsecureSecurityConnector, MakeAuthContextTest) {
35 auto auth_context = TestOnlyMakeInsecureAuthContext();
36 // Verify that peer is not authenticated
37 EXPECT_EQ(auth_context->is_authenticated(), false);
38 // Verify that GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME is set
39 auto it = grpc_auth_context_find_properties_by_name(
40 auth_context.get(), GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME);
41 const grpc_auth_property* prop = grpc_auth_property_iterator_next(&it);
42 ASSERT_NE(prop, nullptr);
43 EXPECT_STREQ(prop->name, GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME);
44 EXPECT_STREQ(prop->value, kInsecureTransportSecurityType);
45 // Verify that security level is set to none
46 it = grpc_auth_context_find_properties_by_name(
47 auth_context.get(), GRPC_TRANSPORT_SECURITY_LEVEL_PROPERTY_NAME);
48 prop = grpc_auth_property_iterator_next(&it);
49 ASSERT_NE(prop, nullptr);
50 EXPECT_EQ(grpc_tsi_security_level_string_to_enum(prop->value),
55 } // namespace testing
56 } // namespace grpc_core
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();