From c9f3c977d34bd14f7a80180723265702c59b1fb2 Mon Sep 17 00:00:00 2001 From: erm-g <110920239+erm-g@users.noreply.github.com> Date: Sun, 21 Jul 2024 15:02:08 +0000 Subject: [PATCH] Automated change: Fix sanity tests --- CMakeLists.txt | 52 +++++++++++++++ build_autogenerated.yaml | 29 +++++++++ .../local/local_security_connector.cc | 3 +- .../security/local_security_connector_test.cc | 65 +++++++++---------- tools/run_tests/generated/tests.json | 24 +++++++ 5 files changed, 139 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3fcae603d42e7..00f7233800b1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1242,6 +1242,7 @@ if(gRPC_BUILD_TESTS) endif() add_dependencies(buildtests_cxx load_config_test) add_dependencies(buildtests_cxx load_file_test) + add_dependencies(buildtests_cxx local_security_connector_test) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX) add_dependencies(buildtests_cxx lock_free_event_test) endif() @@ -19926,6 +19927,57 @@ target_link_libraries(load_file_test ) +endif() +if(gRPC_BUILD_TESTS) + +add_executable(local_security_connector_test + test/core/security/local_security_connector_test.cc + test/core/test_util/cmdline.cc + test/core/test_util/fuzzer_util.cc + test/core/test_util/grpc_profiler.cc + test/core/test_util/histogram.cc + test/core/test_util/mock_endpoint.cc + test/core/test_util/parse_hexstring.cc + test/core/test_util/resolve_localhost_ip46.cc + test/core/test_util/slice_splitter.cc + test/core/test_util/tracer_util.cc +) +if(WIN32 AND MSVC) + if(BUILD_SHARED_LIBS) + target_compile_definitions(local_security_connector_test + PRIVATE + "GPR_DLL_IMPORTS" + "GRPC_DLL_IMPORTS" + ) + endif() +endif() +target_compile_features(local_security_connector_test PUBLIC cxx_std_14) +target_include_directories(local_security_connector_test + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} + ${_gRPC_RE2_INCLUDE_DIR} + ${_gRPC_SSL_INCLUDE_DIR} + ${_gRPC_UPB_GENERATED_DIR} + ${_gRPC_UPB_GRPC_GENERATED_DIR} + ${_gRPC_UPB_INCLUDE_DIR} + ${_gRPC_XXHASH_INCLUDE_DIR} + ${_gRPC_ZLIB_INCLUDE_DIR} + third_party/googletest/googletest/include + third_party/googletest/googletest + third_party/googletest/googlemock/include + third_party/googletest/googlemock + ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(local_security_connector_test + ${_gRPC_ALLTARGETS_LIBRARIES} + gtest + grpc_test_util +) + + endif() if(gRPC_BUILD_TESTS) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_POSIX) diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index b68115b43c2b0..483e38026841e 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -13306,6 +13306,35 @@ targets: - gtest - grpc_test_util uses_polling: false +- name: local_security_connector_test + gtest: true + build: test + language: c++ + headers: + - test/core/test_util/cmdline.h + - test/core/test_util/evaluate_args_test_util.h + - test/core/test_util/fuzzer_util.h + - test/core/test_util/grpc_profiler.h + - test/core/test_util/histogram.h + - test/core/test_util/mock_endpoint.h + - test/core/test_util/parse_hexstring.h + - test/core/test_util/resolve_localhost_ip46.h + - test/core/test_util/slice_splitter.h + - test/core/test_util/tracer_util.h + src: + - test/core/security/local_security_connector_test.cc + - test/core/test_util/cmdline.cc + - test/core/test_util/fuzzer_util.cc + - test/core/test_util/grpc_profiler.cc + - test/core/test_util/histogram.cc + - test/core/test_util/mock_endpoint.cc + - test/core/test_util/parse_hexstring.cc + - test/core/test_util/resolve_localhost_ip46.cc + - test/core/test_util/slice_splitter.cc + - test/core/test_util/tracer_util.cc + deps: + - gtest + - grpc_test_util - name: lock_free_event_test gtest: true build: test diff --git a/src/core/lib/security/security_connector/local/local_security_connector.cc b/src/core/lib/security/security_connector/local/local_security_connector.cc index 3e71ea0e425c8..9551e5d77e3d3 100644 --- a/src/core/lib/security/security_connector/local/local_security_connector.cc +++ b/src/core/lib/security/security_connector/local/local_security_connector.cc @@ -266,7 +266,8 @@ class grpc_local_server_security_connector final }; } // namespace -// just pass local and uds in the format of Chttp2FullstackLocalIpv4, Chttp2FullstackLocalIpv6, Chttp2FullstackLocalUds, check for results +// just pass local and uds in the format of Chttp2FullstackLocalIpv4, +// Chttp2FullstackLocalIpv6, Chttp2FullstackLocalUds, check for results grpc_core::RefCountedPtr grpc_local_channel_security_connector_create( diff --git a/test/core/security/local_security_connector_test.cc b/test/core/security/local_security_connector_test.cc index dc61bd45eb65d..9b33f508d4db4 100644 --- a/test/core/security/local_security_connector_test.cc +++ b/test/core/security/local_security_connector_test.cc @@ -16,8 +16,6 @@ // // -#include "src/core/lib/security/security_connector/tls/tls_security_connector.h" - #include #include @@ -25,6 +23,7 @@ #include #include "absl/log/check.h" +#include "googletest/include/gtest/gtest.h" #include #include @@ -39,10 +38,10 @@ #include "src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h" #include "src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h" #include "src/core/lib/security/credentials/tls/tls_credentials.h" +#include "src/core/lib/security/security_connector/tls/tls_security_connector.h" #include "src/core/tsi/transport_security.h" #include "test/core/test_util/test_config.h" #include "test/core/test_util/tls_utils.h" -#include "googletest/include/gtest/gtest.h" namespace grpc_core { namespace testing { @@ -69,9 +68,7 @@ static void me_delete_from_pollset_set(grpc_endpoint* /*ep*/, static void me_destroy(grpc_endpoint* ep) {} -static absl::string_view me_get_peer(grpc_endpoint* /*ep*/) { - return ""; -} +static absl::string_view me_get_peer(grpc_endpoint* /*ep*/) { return ""; } static absl::string_view me_get_local_address_unix(grpc_endpoint* /*ep*/) { return "unix:"; @@ -82,38 +79,40 @@ static int me_get_fd(grpc_endpoint* /*ep*/) { return -1; } static bool me_can_track_err(grpc_endpoint* /*ep*/) { return false; } static const grpc_endpoint_vtable vtable_unix = {me_read, - me_write, - me_add_to_pollset, - me_add_to_pollset_set, - me_delete_from_pollset_set, - me_destroy, - me_get_peer, - me_get_local_address_unix, - me_get_fd, - me_can_track_err}; + me_write, + me_add_to_pollset, + me_add_to_pollset_set, + me_delete_from_pollset_set, + me_destroy, + me_get_peer, + me_get_local_address_unix, + me_get_fd, + me_can_track_err}; static absl::string_view me_get_local_address_local(grpc_endpoint* /*ep*/) { return "ipv4:127.0.0.1:12667"; } static const grpc_endpoint_vtable vtable_local = {me_read, - me_write, - me_add_to_pollset, - me_add_to_pollset_set, - me_delete_from_pollset_set, - me_destroy, - me_get_peer, - me_get_local_address_local, - me_get_fd, - me_can_track_err}; + me_write, + me_add_to_pollset, + me_add_to_pollset_set, + me_delete_from_pollset_set, + me_destroy, + me_get_peer, + me_get_local_address_local, + me_get_fd, + me_can_track_err}; static void check_tsi_security_level(grpc_local_connect_type connect_type, - tsi_security_level level, grpc_endpoint ep) { - grpc_server_credentials* server_creds = grpc_local_server_credentials_create(connect_type); + tsi_security_level level, + grpc_endpoint ep) { + grpc_server_credentials* server_creds = + grpc_local_server_credentials_create(connect_type); ChannelArgs args; EXPECT_NE(server_creds, nullptr); - RefCountedPtr connector = server_creds-> - create_security_connector(args); + RefCountedPtr connector = + server_creds->create_security_connector(args); EXPECT_NE(connector, nullptr); tsi_peer peer; CHECK(tsi_construct_peer(0, &peer) == TSI_OK); @@ -136,17 +135,17 @@ static void check_tsi_security_level(grpc_local_connect_type connect_type, // TEST_F(LocalSecurityConnectorTest, CheckUDSType) { -// auto server_creds = grpc_local_server_credentials_create(LOCAL_TCP); + // auto server_creds = grpc_local_server_credentials_create(LOCAL_TCP); grpc_endpoint ep = { - .vtable = &vtable_unix, - }; + .vtable = &vtable_unix, + }; check_tsi_security_level(UDS, TSI_PRIVACY_AND_INTEGRITY, ep); } TEST_F(LocalSecurityConnectorTest, CheckLocalType) { grpc_endpoint ep = { - .vtable = &vtable_local, - }; + .vtable = &vtable_local, + }; check_tsi_security_level(LOCAL_TCP, TSI_SECURITY_NONE, ep); } diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index b1539ab9fff52..4f914307028b9 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -5929,6 +5929,30 @@ ], "uses_polling": false }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": true, + "language": "c++", + "name": "local_security_connector_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, { "args": [ "--benchmark_min_time=0.001s"