From 4fe1589d82430cc453e17bbf798eb8475010959d Mon Sep 17 00:00:00 2001
From: erm-g <110920239+erm-g@users.noreply.github.com>
Date: Tue, 23 Jul 2024 15:53:01 +0000
Subject: [PATCH] Automated change: Fix sanity tests

---
 CMakeLists.txt                                |  52 +++++++++
 build_autogenerated.yaml                      |  29 +++++
 .../local/local_security_connector.cc         |  14 +--
 .../security/local_security_connector_test.cc | 100 ++++++++----------
 tools/run_tests/generated/tests.json          |  24 +++++
 5 files changed, 155 insertions(+), 64 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 ad431e06e75bc..0abd29a36adb0 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
@@ -146,13 +146,13 @@ void local_check_peer(tsi_peer peer, grpc_endpoint* ep,
   // Set security level to NONE for TCP type, privacy&integrity otherwise.
   const char* security_level;
   switch (type) {
-  case UDS:
-    security_level = tsi_security_level_to_string(TSI_PRIVACY_AND_INTEGRITY);
-    break;
-  default:
-    security_level = tsi_security_level_to_string(TSI_SECURITY_NONE);
-    break;
-}
+    case UDS:
+      security_level = tsi_security_level_to_string(TSI_PRIVACY_AND_INTEGRITY);
+      break;
+    default:
+      security_level = tsi_security_level_to_string(TSI_SECURITY_NONE);
+      break;
+  }
   tsi_result result = tsi_construct_string_peer_property_from_cstring(
       TSI_SECURITY_LEVEL_PEER_PROPERTY, security_level,
       &peer.properties[peer.property_count]);
diff --git a/test/core/security/local_security_connector_test.cc b/test/core/security/local_security_connector_test.cc
index aeb61c0c52330..43ad08670cf5c 100644
--- a/test/core/security/local_security_connector_test.cc
+++ b/test/core/security/local_security_connector_test.cc
@@ -18,12 +18,14 @@
 
 #include <gtest/gtest.h>
 
+#include "googletest/include/gtest/gtest.h"
+
+#include <grpc/impl/grpc_types.h>
+
+#include "src/core/client_channel/client_channel_filter.h"
 #include "src/core/lib/security/context/security_context.h"
 #include "src/core/tsi/transport_security.h"
 #include "test/core/test_util/test_config.h"
-#include "src/core/client_channel/client_channel_filter.h"
-#include "include/grpc/impl/grpc_types.h"
-#include "googletest/include/gtest/gtest.h"
 
 namespace grpc_core {
 namespace testing {
@@ -33,40 +35,28 @@ absl::string_view me_get_local_address_unix(grpc_endpoint* /*ep*/) {
   return "unix:";
 }
 
-const grpc_endpoint_vtable vtable_unix = {nullptr,
-                                                 nullptr,
-                                                 nullptr,
-                                                 nullptr,
-                                                 nullptr,
-                                                 nullptr,
-                                                 nullptr,
-                                                 me_get_local_address_unix,
-                                                 nullptr,
-                                                 nullptr};
+const grpc_endpoint_vtable vtable_unix = {
+    nullptr, nullptr, nullptr, nullptr,
+    nullptr, nullptr, nullptr, me_get_local_address_unix,
+    nullptr, nullptr};
 
 absl::string_view me_get_local_address_local(grpc_endpoint* /*ep*/) {
   return "ipv4:127.0.0.1:12667";
 }
 
-const grpc_endpoint_vtable vtable_local = {nullptr,
-                                                  nullptr,
-                                                  nullptr,
-                                                  nullptr,
-                                                  nullptr,
-                                                  nullptr,
-                                                  nullptr,
-                                                  me_get_local_address_local,
-                                                  nullptr,
-                                                  nullptr};
+const grpc_endpoint_vtable vtable_local = {
+    nullptr, nullptr, nullptr, nullptr,
+    nullptr, nullptr, nullptr, me_get_local_address_local,
+    nullptr, nullptr};
 
 void check_tsi_security_level_server(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;
-  RefCountedPtr<grpc_server_security_connector> connector = server_creds->
-      create_security_connector(args);
+  RefCountedPtr<grpc_server_security_connector> connector =
+      server_creds->create_security_connector(args);
   ASSERT_NE(connector, nullptr);
   tsi_peer peer;
   CHECK(tsi_construct_peer(0, &peer) == TSI_OK);
@@ -84,21 +74,21 @@ void check_tsi_security_level_server(grpc_local_connect_type connect_type,
   grpc_server_credentials_release(server_creds);
 }
 
-static void check_tsi_security_level_channel(grpc_local_connect_type connect_type,
-                                             tsi_security_level level,
-                                             grpc_endpoint ep) {
-  grpc_channel_credentials
-      * channel_creds = grpc_local_credentials_create(connect_type);
+void check_tsi_security_level_channel(grpc_local_connect_type connect_type,
+                                      tsi_security_level level,
+                                      grpc_endpoint ep) {
+  grpc_channel_credentials* channel_creds =
+      grpc_local_credentials_create(connect_type);
   ChannelArgs args;
-  args = args.Set((char*) GRPC_ARG_SERVER_URI, (char*) "unix:");
+  args = args.Set((char*)GRPC_ARG_SERVER_URI, (char*)"unix:");
   const char* target_name;
   if (connect_type == UDS) {
     target_name = "unix:";
   } else {
     target_name = "localhost";
   }
-  RefCountedPtr<grpc_channel_security_connector> connector = channel_creds->
-      create_security_connector(nullptr, "unix:", &args);
+  RefCountedPtr<grpc_channel_security_connector> connector =
+      channel_creds->create_security_connector(nullptr, "unix:", &args);
 
   ASSERT_NE(connector, nullptr);
   tsi_peer peer;
@@ -124,35 +114,31 @@ static void check_tsi_security_level_channel(grpc_local_connect_type connect_typ
 //
 
 TEST(LocalSecurityConnectorTest, CheckUDSType) {
-grpc_endpoint ep = {
-    .vtable = &vtable_unix,
-};
-check_tsi_security_level_server(UDS, TSI_PRIVACY_AND_INTEGRITY, ep
-);
+  grpc_endpoint ep = {
+      .vtable = &vtable_unix,
+  };
+  check_tsi_security_level_server(UDS, TSI_PRIVACY_AND_INTEGRITY, ep);
 }
 
 TEST(LocalSecurityConnectorTest, CheckLocalType) {
-grpc_endpoint ep = {
-    .vtable = &vtable_local,
-};
-check_tsi_security_level_server(LOCAL_TCP, TSI_SECURITY_NONE, ep
-);
+  grpc_endpoint ep = {
+      .vtable = &vtable_local,
+  };
+  check_tsi_security_level_server(LOCAL_TCP, TSI_SECURITY_NONE, ep);
 }
 
 TEST(LocalSecurityConnectorTest, CheckUDSTypeChannel) {
-grpc_endpoint ep = {
-    .vtable = &vtable_unix,
-};
-check_tsi_security_level_channel(UDS, TSI_PRIVACY_AND_INTEGRITY, ep
-);
+  grpc_endpoint ep = {
+      .vtable = &vtable_unix,
+  };
+  check_tsi_security_level_channel(UDS, TSI_PRIVACY_AND_INTEGRITY, ep);
 }
 
 TEST(LocalSecurityConnectorTest, CheckLocalTypeChannel) {
-grpc_endpoint ep = {
-    .vtable = &vtable_local,
-};
-check_tsi_security_level_channel(LOCAL_TCP, TSI_SECURITY_NONE, ep
-);
+  grpc_endpoint ep = {
+      .vtable = &vtable_local,
+  };
+  check_tsi_security_level_channel(LOCAL_TCP, TSI_SECURITY_NONE, ep);
 }
 
 }  // namespace
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"