diff --git a/CMakeLists.txt b/CMakeLists.txt index a0dfdb2b1f90d..ed24272097a41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,9 +28,11 @@ include_directories(${ENVOY_DEPENDENCIES_ROOT}/gens/prometheus) SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /LIBPATH:${ENVOY_DEPENDENCIES_ROOT}/gens/lib/debug") SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /LIBPATH:${ENVOY_DEPENDENCIES_ROOT}/vcpkg/installed/x64-windows-static/debug/lib") SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /LIBPATH:${ENVOY_DEPENDENCIES_ROOT}/vcpkg/installed/x64-windows/debug/lib") +SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /LIBPATH:${ENVOY_DEPENDENCIES_ROOT}/vcpkg/installed/x64-windows-static/debug/lib/manual-link") SET(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /LIBPATH:${ENVOY_DEPENDENCIES_ROOT}/gens/lib") SET(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /LIBPATH:${ENVOY_DEPENDENCIES_ROOT}/vcpkg/installed/x64-windows-static/lib") SET(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /LIBPATH:${ENVOY_DEPENDENCIES_ROOT}/vcpkg/installed/x64-windows/lib") +SET(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /LIBPATH:${ENVOY_DEPENDENCIES_ROOT}/vcpkg/installed/x64-windows-static/lib/manual-link") if (MSVC) foreach (flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) @@ -41,3 +43,4 @@ if (MSVC) endif(MSVC) add_subdirectory(source) +add_subdirectory(test) \ No newline at end of file diff --git a/source/common/filesystem/filesystem_impl.cc b/source/common/filesystem/filesystem_impl.cc index d03a8bddb7034..d157f8232043e 100644 --- a/source/common/filesystem/filesystem_impl.cc +++ b/source/common/filesystem/filesystem_impl.cc @@ -54,10 +54,10 @@ bool directoryExists(const std::string& path) { #endif } -std::string fileReadToEnd(const std::string& path) { +std::string fileReadToEnd(const std::string& path, std::ios_base::openmode mode) { std::ios::sync_with_stdio(false); - std::ifstream file(path); + std::ifstream file(path, mode); if (!file) { throw EnvoyException(fmt::format("unable to read file: {}", path)); } diff --git a/source/common/filesystem/filesystem_impl.h b/source/common/filesystem/filesystem_impl.h index fffda39fb2b60..b1bc0cac3337e 100644 --- a/source/common/filesystem/filesystem_impl.h +++ b/source/common/filesystem/filesystem_impl.h @@ -45,7 +45,7 @@ bool directoryExists(const std::string& path); * @return full file content as a string. * Be aware, this is not most highly performing file reading method. */ -std::string fileReadToEnd(const std::string& path); +std::string fileReadToEnd(const std::string& path, std::ios_base::openmode mode = std::ios_base::in); /** * This is a file implementation geared for writing out access logs. It turn out that in certain diff --git a/source/common/filter/CMakeLists.txt b/source/common/filter/CMakeLists.txt index 15076620acd15..6c6816d69af3e 100644 --- a/source/common/filter/CMakeLists.txt +++ b/source/common/filter/CMakeLists.txt @@ -7,3 +7,5 @@ add_library(ratelimit_lib_filter ratelimit.cc) add_library(tcp_proxy_lib tcp_proxy.cc) add_subdirectory(auth) +add_subdirectory(listener) + diff --git a/source/common/filter/listener/CMakeLists.txt b/source/common/filter/listener/CMakeLists.txt new file mode 100644 index 0000000000000..8e202236a88c6 --- /dev/null +++ b/source/common/filter/listener/CMakeLists.txt @@ -0,0 +1,3 @@ +add_library(original_dst_lib original_dst.cc) + +add_library(proxy_protocol_lib proxy_protocol.cc) \ No newline at end of file diff --git a/source/common/filter/listener/proxy_protocol.cc b/source/common/filter/listener/proxy_protocol.cc index d10415e3e7694..bdbff8a8fff23 100644 --- a/source/common/filter/listener/proxy_protocol.cc +++ b/source/common/filter/listener/proxy_protocol.cc @@ -1,6 +1,8 @@ #include "common/filter/listener/proxy_protocol.h" +#if !defined(WIN32) #include +#endif #include #include diff --git a/source/common/network/connection_impl.cc b/source/common/network/connection_impl.cc index e8a43a7a17441..5f2c9a1f1fe27 100644 --- a/source/common/network/connection_impl.cc +++ b/source/common/network/connection_impl.cc @@ -167,14 +167,32 @@ void ConnectionImpl::noDelay(bool enable) { } // Don't set NODELAY for unix domain sockets +#if defined(WIN32) + // AF_UNIX is now supported on windows as well, hence keeping this logic. + // With sockaddr, getsockname returns 10014 for IPV6 addresses. + // Use sockaddr_storage since it is sufficiently large to store address information for IPv4, IPv6, or other address families. + // TODO: Can use this on linux as well instead of sockaddr + sockaddr_storage addr; + socklen_t len = sizeof(addr); + + int rc = getsockname(fd(), (struct sockaddr *)&addr, &len); + RELEASE_ASSERT(rc == 0); + + if (addr.ss_family == AF_UNIX) { + return; + } +#else + // Don't set NODELAY for unix domain sockets sockaddr addr; socklen_t len = sizeof(addr); + int rc = getsockname(fd(), &addr, &len); RELEASE_ASSERT(rc == 0); if (addr.sa_family == AF_UNIX) { return; } +#endif // Set NODELAY int new_value = enable; diff --git a/source/common/ssl/context_config_impl.cc b/source/common/ssl/context_config_impl.cc index 3c576d4cfa997..f27828102b062 100644 --- a/source/common/ssl/context_config_impl.cc +++ b/source/common/ssl/context_config_impl.cc @@ -23,21 +23,15 @@ namespace Ssl { const std::string ContextConfigImpl::DEFAULT_CIPHER_SUITES = "[ECDHE-ECDSA-AES128-GCM-SHA256|ECDHE-ECDSA-CHACHA20-POLY1305]:" "[ECDHE-RSA-AES128-GCM-SHA256|ECDHE-RSA-CHACHA20-POLY1305]:" - "ECDHE-ECDSA-AES128-SHA256:" - "ECDHE-RSA-AES128-SHA256:" "ECDHE-ECDSA-AES128-SHA:" "ECDHE-RSA-AES128-SHA:" "AES128-GCM-SHA256:" - "AES128-SHA256:" "AES128-SHA:" "ECDHE-ECDSA-AES256-GCM-SHA384:" "ECDHE-RSA-AES256-GCM-SHA384:" - "ECDHE-ECDSA-AES256-SHA384:" - "ECDHE-RSA-AES256-SHA384:" "ECDHE-ECDSA-AES256-SHA:" "ECDHE-RSA-AES256-SHA:" "AES256-GCM-SHA384:" - "AES256-SHA256:" "AES256-SHA"; const std::string ContextConfigImpl::DEFAULT_ECDH_CURVES = "X25519:P-256"; @@ -77,10 +71,11 @@ ContextConfigImpl::ContextConfigImpl(const envoy::api::v2::CommonTlsContext& con } const std::string ContextConfigImpl::readDataSource(const envoy::api::v2::DataSource& source, - bool allow_empty) { + bool allow_empty, + std::ios_base::openmode mode) { switch (source.specifier_case()) { case envoy::api::v2::DataSource::kFilename: - return Filesystem::fileReadToEnd(source.filename()); + return Filesystem::fileReadToEnd(source.filename(), mode); case envoy::api::v2::DataSource::kInlineBytes: return source.inline_bytes(); case envoy::api::v2::DataSource::kInlineString: @@ -142,7 +137,7 @@ ServerContextConfigImpl::ServerContextConfigImpl(const envoy::api::v2::Downstrea switch (config.session_ticket_keys_type_case()) { case envoy::api::v2::DownstreamTlsContext::kSessionTicketKeys: for (const auto& datasource : config.session_ticket_keys().keys()) { - validateAndAppendKey(ret, readDataSource(datasource, false)); + validateAndAppendKey(ret, readDataSource(datasource, false, std::ios_base::binary)); } break; case envoy::api::v2::DownstreamTlsContext::kSessionTicketKeysSdsSecretConfig: diff --git a/source/common/ssl/context_config_impl.h b/source/common/ssl/context_config_impl.h index 83212fa722e33..d72373460b295 100644 --- a/source/common/ssl/context_config_impl.h +++ b/source/common/ssl/context_config_impl.h @@ -44,7 +44,8 @@ class ContextConfigImpl : public virtual Ssl::ContextConfig { ContextConfigImpl(const envoy::api::v2::CommonTlsContext& config); static const std::string readDataSource(const envoy::api::v2::DataSource& source, - bool allow_empty); + bool allow_empty, + std::ios_base::openmode mode = std::ios_base::in); static const std::string getDataSourcePath(const envoy::api::v2::DataSource& source); private: diff --git a/source/server/CMakeLists.txt b/source/server/CMakeLists.txt index b273c6c4534f8..e53174e7e1af0 100644 --- a/source/server/CMakeLists.txt +++ b/source/server/CMakeLists.txt @@ -32,6 +32,7 @@ add_library(watchdog_lib watchdog_impl.cc) add_library(worker_lib worker_impl.cc) +add_subdirectory(config/access_log) add_subdirectory(config/http) add_subdirectory(config/network) add_subdirectory(config_validation) diff --git a/source/server/config/access_log/CMakeLists.txt b/source/server/config/access_log/CMakeLists.txt new file mode 100644 index 0000000000000..2add2ce74e2a5 --- /dev/null +++ b/source/server/config/access_log/CMakeLists.txt @@ -0,0 +1,3 @@ +project(server_config_access_log) + +add_library(file_access_log_lib file_access_log.cc) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000000000..d31c41643fa0e --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,27 @@ +include_directories(${PROJECT_SOURCE_DIR}) + +add_library(test_main main.cc) +target_link_libraries(test_main + thread_lib + libevent_lib + environment_lib + printers_lib + version_lib + test_common_utility_lib +) + +target_link_libraries(test_main + debug gmockd.lib + debug gtestd.lib +) + +target_link_libraries(test_main + optimized gmock.lib + optimized gtest.lib +) + +add_subdirectory(common) +add_subdirectory(test_common) +add_subdirectory(mocks) +#add_subdirectory(proto) +#add_subdirectory(integration) \ No newline at end of file diff --git a/test/common/CMakeLists.txt b/test/common/CMakeLists.txt new file mode 100644 index 0000000000000..b603297ee0463 --- /dev/null +++ b/test/common/CMakeLists.txt @@ -0,0 +1,33 @@ +add_subdirectory(access_log) +add_subdirectory(api) +add_subdirectory(buffer) +add_subdirectory(common) +add_subdirectory(config) +#TBD add_subdirectory(dynamo) +add_subdirectory(event) +add_subdirectory(filesystem) +#TBD add_subdirectory(filter) +#TBD add_subdirectory(grpc) +add_subdirectory(html) +add_subdirectory(http) +add_subdirectory(json) +add_subdirectory(network) +add_subdirectory(protobuf) +add_subdirectory(ratelimit) +add_subdirectory(request_info) +add_subdirectory(router) +#TBD add_subdirectory(runtime) +#TBD add_subdirectory(singleton) +add_subdirectory(ssl) +#TBD add_subdirectory(stats) +add_subdirectory(thread_local) +add_subdirectory(tracing) +add_subdirectory(upstream) + + +#TODO Source not compiled for Win32, hence skipping test folders +#add_subdirectory(compressor) +#add_subdirectory(decompressor) +#add_subdirectory(local_info) +#add_subdirectory(mongo) +#add_subdirectory(redis) \ No newline at end of file diff --git a/test/common/access_log/CMakeLists.txt b/test/common/access_log/CMakeLists.txt new file mode 100644 index 0000000000000..e51f218b163ff --- /dev/null +++ b/test/common/access_log/CMakeLists.txt @@ -0,0 +1,108 @@ +add_executable(access_log_impl_test access_log_impl_test.cc) +target_link_libraries(access_log_impl_test + access_log_lib + filter_json_lib + utility_lib + + access_log_mocks + event_mocks + filesystem_mocks + runtime_mocks + server_mocks + upstream_mocks + test_common_utility_lib + +#dependencies + logger_lib + config_utility_lib + http_utility_lib + uuid_util_lib + http_tracer_lib + well_known_names_lib + hex_lib + filesystem_lib + common_lib + config_schemas_lib + utility_lib_protobuf + stats_lib + buffer_lib + message_lib + header_map_lib + json_loader_lib + network_utility_lib + runtime_lib + access_log_formatter_lib + common_request_info_utility + base64_lib + zero_copy_input_stream_lib + + crypto.lib + decrepit.lib + ssl.lib +) + +target_link_libraries(access_log_impl_test + debug gtestd.lib + debug gtest_maind.lib +) + +target_link_libraries(access_log_impl_test + optimized gtest.lib + optimized gtest_main.lib +) + +add_executable(access_log_formatter_test access_log_formatter_test.cc) +target_link_libraries(access_log_formatter_test + access_log_formatter_lib + utility_lib + logger_lib + header_map_lib + common_request_info_utility + access_log_mocks + event_mocks + filesystem_mocks + runtime_mocks + server_mocks + upstream_mocks + test_common_utility_lib + test_main +) + +target_link_libraries(access_log_formatter_test + debug gtestd.lib +) + +target_link_libraries(access_log_formatter_test + optimized gtest.lib +) + + +#source file to be ported to Windows, hence skipping test +#add_executable(grpc_access_log_impl_test grpc_access_log_impl_test.cc) + +add_executable(access_log_manager_impl_test access_log_manager_impl_test.cc) +target_link_libraries(access_log_manager_impl_test + access_log_manager_lib + stats_lib + access_log_mocks + filesystem_mocks + api_mocks + event_mocks + +#dependencies + logger_lib + utility_lib + well_known_names_lib + utility_lib_protobuf + config_schemas_lib + config_utility_lib + test_main +) + +target_link_libraries(access_log_manager_impl_test + debug gtestd.lib +) +target_link_libraries(access_log_manager_impl_test + optimized gtest.lib +) + diff --git a/test/common/access_log/access_log_impl_test.cc b/test/common/access_log/access_log_impl_test.cc index 42b09aa5468f5..1c6493e9819fc 100644 --- a/test/common/access_log/access_log_impl_test.cc +++ b/test/common/access_log/access_log_impl_test.cc @@ -24,6 +24,10 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" +#if defined(WIN32) +#define timegm _mkgmtime +#endif + using testing::NiceMock; using testing::Return; using testing::SaveArg; diff --git a/test/common/api/CMakeLists.txt b/test/common/api/CMakeLists.txt new file mode 100644 index 0000000000000..4c92de2702b30 --- /dev/null +++ b/test/common/api/CMakeLists.txt @@ -0,0 +1,65 @@ +add_executable(api_impl_test api_impl_test.cc) +target_link_libraries(api_impl_test + api_lib + environment_lib + +#dependencies + dispatcher_lib + watcher_lib + connection_lib + dns_lib + listener_lib + connection_lib_ssl + logger_lib + utility_lib + address_lib + listen_socket_lib + libevent_lib + context_lib + hex_lib + common_ssl_ssl_socket_lib + test_common_utility_lib + config_schemas_lib + config_utility_lib + stats_lib + well_known_names_lib + filter_manager_lib + os_sys_calls_impl + buffer_lib + thread_lib + version_lib + json_loader_lib + watermark_buffer_lib + xxhash.lib + event.lib + event_core.lib + event_extra.lib + cares.lib + crypto.lib + decrepit.lib + ssl.lib + + test_main +) + +#dependencies +target_link_libraries(api_impl_test + debug libyaml-cppmdd.lib + optimized libyaml-cppmd.lib +) + +#dependencies +target_link_libraries(api_impl_test + optimized absl_base.lib + optimized absl_strings.lib +) + +target_link_libraries(api_impl_test + debug gtestd.lib + debug gmockd.lib +) + +target_link_libraries(api_impl_test + optimized gtest.lib + optimized gmock.lib +) \ No newline at end of file diff --git a/test/common/buffer/CMakeLists.txt b/test/common/buffer/CMakeLists.txt new file mode 100644 index 0000000000000..5469a428abf49 --- /dev/null +++ b/test/common/buffer/CMakeLists.txt @@ -0,0 +1,86 @@ +add_executable(owned_impl_test owned_impl_test.cc) +target_link_libraries(owned_impl_test + buffer_lib + +#dependencies + libevent_lib + logger_lib + event.lib + event_core.lib + event_extra.lib + ws2_32.lib + fmt.lib + + config_schemas_lib + config_utility_lib + stats_lib + test_main +) + +target_link_libraries(owned_impl_test + debug gtestd.lib +) + +target_link_libraries(owned_impl_test + optimized gtest.lib +) + +add_executable(watermark_buffer_test watermark_buffer_test.cc) +target_link_libraries(watermark_buffer_test + buffer_lib + watermark_buffer_lib + +#dependencies + libevent_lib + logger_lib + event.lib + event_core.lib + event_extra.lib + ws2_32.lib + fmt.lib + + stats_lib + config_schemas_lib + config_utility_lib + json_loader_lib + test_common_utility_lib + test_main +) + +target_link_libraries(watermark_buffer_test + debug gtestd.lib + debug gmockd.lib +) + +target_link_libraries(watermark_buffer_test + optimized gtest.lib + optimized gmockd.lib +) + +add_executable(zero_copy_input_stream_test zero_copy_input_stream_test.cc) +target_link_libraries(zero_copy_input_stream_test + zero_copy_input_stream_lib + buffer_lib + +#dependencies + libevent_lib + logger_lib + event.lib + event_core.lib + event_extra.lib + ws2_32.lib + fmt.lib + + stats_lib + config_schemas_lib + config_utility_lib + test_main +) + +target_link_libraries(zero_copy_input_stream_test + debug gtestd.lib +) + +target_link_libraries(zero_copy_input_stream_test + optimized gtest.lib +) \ No newline at end of file diff --git a/test/common/buffer/watermark_buffer_test.cc b/test/common/buffer/watermark_buffer_test.cc index 1514de59a15a6..e86d1fcdc447a 100644 --- a/test/common/buffer/watermark_buffer_test.cc +++ b/test/common/buffer/watermark_buffer_test.cc @@ -4,7 +4,10 @@ #include "common/buffer/watermark_buffer.h" #include "gtest/gtest.h" - +#if defined(WIN32) +#include +#include +#endif namespace Envoy { namespace Buffer { namespace { @@ -122,7 +125,11 @@ TEST_F(WatermarkBufferTest, MoveOneByte) { TEST_F(WatermarkBufferTest, WatermarkFdFunctions) { int pipe_fds[2] = {0, 0}; +#if defined(WIN32) + ASSERT_EQ(0, _pipe(pipe_fds, 256, _O_TEXT)); +#else ASSERT_EQ(0, pipe(pipe_fds)); +#endif buffer_.add(TEN_BYTES, 10); buffer_.add(TEN_BYTES, 10); diff --git a/test/common/common/CMakeLists.txt b/test/common/common/CMakeLists.txt new file mode 100644 index 0000000000000..470212d312aee --- /dev/null +++ b/test/common/common/CMakeLists.txt @@ -0,0 +1,119 @@ +#include(GoogleTest) + +add_executable(base64_test base64_test.cc) +target_link_libraries(base64_test + buffer_lib + base64_lib + fmt.lib + logger_lib + libevent_lib + event.lib + event_core.lib + event_extra.lib + Ws2_32.lib +) + +target_link_libraries(base64_test + debug gtestd.lib + debug gtest_maind.lib +) + +target_link_libraries(base64_test + optimized gtest.lib + optimized gtest_main.lib +) + +add_executable(hex_test hex_test.cc) +target_link_libraries(hex_test + hex_lib + utility_lib + fmt.lib +) + +target_link_libraries(hex_test + debug absl_based.lib + debug absl_stringsd.lib + debug gtestd.lib + debug gtest_maind.lib +) + +target_link_libraries(hex_test + optimized gtest.lib + optimized gtest_main.lib + optimized absl_base.lib + optimized absl_strings.lib +) + +add_executable(utility_test utility_test.cc) +target_link_libraries(utility_test + utility_lib + test_common_utility_lib +) + +target_link_libraries(utility_test + debug gtestd.lib + debug gtest_maind.lib +) + +target_link_libraries(utility_test + optimized gtest.lib + optimized gtest_main.lib +) + +add_executable(to_lower_table_test to_lower_table_test.cc) +target_link_libraries(to_lower_table_test + to_lower_table_lib +) + +target_link_libraries(to_lower_table_test + debug gtestd.lib + debug gtest_maind.lib +) + +target_link_libraries(to_lower_table_test + optimized gtest.lib + optimized gtest_main.lib +) + +add_executable(log_macros_test log_macros_test.cc) +target_link_libraries(log_macros_test + logger_lib + filesystem_lib + http_mocks + network_mocks + upstream_mocks + request_info_mocks + libevent_lib +) + +target_link_libraries(log_macros_test + googleapis.lib + protoc-gen-validate.lib + gogoproto.lib + event.lib + event_core.lib + event_extra.lib +) + + +target_link_libraries(log_macros_test + debug gtestd.lib + debug gtest_maind.lib + + debug libprotobufd.lib + debug libprotocd.lib +) + +target_link_libraries(log_macros_test + optimized gtest.lib + optimized gtest_main.lib + + optimized libprotobuf.lib + optimized libprotoc.lib +) + +target_link_libraries(log_macros_test + data-plane-api.lib +) + +#gtest_discover_tests(base64_test) diff --git a/test/common/config/CMakeLists.txt b/test/common/config/CMakeLists.txt new file mode 100644 index 0000000000000..1b3b29614c483 --- /dev/null +++ b/test/common/config/CMakeLists.txt @@ -0,0 +1,74 @@ +add_executable(filesystem_subscription_impl_test filesystem_subscription_impl_test.cc) +target_link_libraries(filesystem_subscription_impl_test + filesystem_subscription_test_harness + test_main +) + +target_link_libraries(filesystem_subscription_impl_test + debug gtestd.lib +) + +target_link_libraries(filesystem_subscription_impl_test + optimized gtest.lib +) + +add_library(filesystem_subscription_test_harness INTERFACE) +target_link_libraries(filesystem_subscription_test_harness INTERFACE + utility_lib + dispatcher_lib + config_mocks + environment_lib + test_common_utility_lib + +#dependencies + logger_lib + config_utility_lib + utility_lib_protobuf + json_loader_lib + config_schemas_lib + filesystem_lib + os_sys_calls_impl + thread_lib + buffer_lib + logger_lib + libevent_lib + watcher_lib + connection_lib + dns_lib + listener_lib + connection_lib_ssl + address_lib + listen_socket_lib + context_lib + hex_lib + common_ssl_ssl_socket_lib + filter_manager_lib + watermark_buffer_lib + stats_lib + version_lib + stats_mocks + + cares.lib + fmt.lib + event.lib + event_core.lib + event_extra.lib + ws2_32.lib + xxhash.lib + + crypto.lib + decrepit.lib + ssl.lib +) + +target_link_libraries(filesystem_subscription_test_harness INTERFACE + debug absl_based.lib + debug absl_stringsd.lib + debug gmockd.lib +) + +target_link_libraries(filesystem_subscription_test_harness INTERFACE + optimized absl_based.lib + optimized absl_stringsd.lib + optimized gmock.lib +) diff --git a/test/common/event/CMakeLists.txt b/test/common/event/CMakeLists.txt new file mode 100644 index 0000000000000..13f983cb9e959 --- /dev/null +++ b/test/common/event/CMakeLists.txt @@ -0,0 +1,59 @@ +add_executable(dispatcher_impl_test dispatcher_impl_test.cc) +target_link_libraries(dispatcher_impl_test + dispatcher_lib + test_mocks_common_lib + test_main + +#dependencies + envoy_all_lib +) + +target_link_libraries(dispatcher_impl_test + debug gtestd.lib +) + +target_link_libraries(dispatcher_impl_test + optimized gtest.lib +) + +add_executable(file_event_impl_test file_event_impl_test.cc) +target_link_libraries(file_event_impl_test + dispatcher_lib + test_mocks_common_lib + environment_lib + + test_main + +#dependencies + envoy_all_lib +) + +target_link_libraries(file_event_impl_test + debug gtestd.lib +) + +target_link_libraries(file_event_impl_test + optimized gtest.lib +) + +add_executable(dispatched_thread_impl_test dispatched_thread_impl_test.cc) +target_link_libraries(dispatched_thread_impl_test + utility_lib + dispatched_thread_lib + guarddog_lib + test_mocks_common_lib + server_mocks + stats_mocks + test_main + +#dependencies + envoy_all_lib +) + +target_link_libraries(dispatched_thread_impl_test + debug gtestd.lib +) + +target_link_libraries(dispatched_thread_impl_test + optimized gtest.lib +) \ No newline at end of file diff --git a/test/common/event/file_event_impl_test.cc b/test/common/event/file_event_impl_test.cc index e6b0566ca35c3..cc8ad3fe01ebf 100644 --- a/test/common/event/file_event_impl_test.cc +++ b/test/common/event/file_event_impl_test.cc @@ -9,13 +9,21 @@ #include "gtest/gtest.h" +#if defined(WIN32) +#include "socketpair.h" +#endif + namespace Envoy { namespace Event { class FileEventImplTest : public testing::Test { public: void SetUp() override { +#if defined(WIN32) + int rc = socketpair(AF_UNIX, SOCK_DGRAM, 0, fds_); +#else int rc = socketpair(AF_UNIX, SOCK_DGRAM, 0, fds_); +#endif ASSERT_EQ(0, rc); int data = 1; rc = write(fds_[1], &data, sizeof(data)); diff --git a/test/common/event/socketpair.h b/test/common/event/socketpair.h new file mode 100644 index 0000000000000..4f1b843f4fee3 --- /dev/null +++ b/test/common/event/socketpair.h @@ -0,0 +1,109 @@ +/* socketpair.c +Copyright 2007, 2010 by Nathan C. Myers +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + The name of the author must not be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(WIN32) +#include + +# include /* socklen_t, et al (MSVC20xx) */ +# include +# include + +/* dumb_socketpair: + * If make_overlapped is nonzero, both sockets created will be usable for + * "overlapped" operations via WSASend etc. If make_overlapped is zero, + * socks[0] (only) will be usable with regular ReadFile etc., and thus + * suitable for use as stdin or stdout of a child process. Note that the + * sockets must be closed with closesocket() regardless. + */ + +int socketpair(int domain, int type, int protocol, int socks[2]) +{ + union { + struct sockaddr_in inaddr; + struct sockaddr addr; + } a; + SOCKET listener; + int e; + socklen_t addrlen = sizeof(a.inaddr); + int reuse = 1; + + if (socks == 0) { + WSASetLastError(WSAEINVAL); + return SOCKET_ERROR; + } + socks[0] = socks[1] = -1; + + listener = socket(domain, type, protocol); + if (listener == -1) + return SOCKET_ERROR; + + memset(&a, 0, sizeof(a)); + a.inaddr.sin_family = AF_INET; + a.inaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + a.inaddr.sin_port = 0; + + for (;;) { + if (setsockopt(listener, SOL_SOCKET, SO_REUSEADDR, + (char*) &reuse, (socklen_t) sizeof(reuse)) == -1) + break; + if (bind(listener, &a.addr, sizeof(a.inaddr)) == SOCKET_ERROR) + break; + + memset(&a, 0, sizeof(a)); + if (getsockname(listener, &a.addr, &addrlen) == SOCKET_ERROR) + break; + // win32 getsockname may only set the port number, p=0.0005. + // ( http://msdn.microsoft.com/library/ms738543.aspx ): + a.inaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + a.inaddr.sin_family = AF_INET; + + if (listen(listener, 1) == SOCKET_ERROR) + break; + + socks[0] = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0, 0); + if (socks[0] == -1) + break; + if (connect(socks[0], &a.addr, sizeof(a.inaddr)) == SOCKET_ERROR) + break; + + socks[1] = accept(listener, NULL, NULL); + if (socks[1] == -1) + break; + + closesocket(listener); + return 0; + } + + e = WSAGetLastError(); + closesocket(listener); + closesocket(socks[0]); + closesocket(socks[1]); + WSASetLastError(e); + socks[0] = socks[1] = -1; + return SOCKET_ERROR; +} +#endif \ No newline at end of file diff --git a/test/common/filesystem/CMakeLists.txt b/test/common/filesystem/CMakeLists.txt new file mode 100644 index 0000000000000..d9a275d76d78c --- /dev/null +++ b/test/common/filesystem/CMakeLists.txt @@ -0,0 +1,29 @@ +add_executable(filesystem_impl_test filesystem_impl_test.cc) +target_link_libraries(filesystem_impl_test + os_sys_calls_impl + thread_lib + dispatcher_lib + filesystem_lib + stats_lib + api_mocks + event_mocks + filesystem_mocks + environment_lib + + test_main + +#dependencies + envoy_all_lib +) + +add_executable(watcher_impl_test watcher_impl_test.cc) +target_link_libraries(watcher_impl_test + dispatcher_lib + watcher_lib + environment_lib + + test_main + +#dependencies + envoy_all_lib +) diff --git a/test/common/filesystem/watcher_impl_test.cc b/test/common/filesystem/watcher_impl_test.cc index 0e45db987f304..81ef70a064cae 100644 --- a/test/common/filesystem/watcher_impl_test.cc +++ b/test/common/filesystem/watcher_impl_test.cc @@ -3,7 +3,11 @@ #include "common/common/assert.h" #include "common/event/dispatcher_impl.h" +#if defined(WIN32) +#include "common/filesystem/win32/watcher_impl.h" +#else #include "common/filesystem/watcher_impl.h" +#endif #include "test/test_common/environment.h" @@ -27,16 +31,33 @@ TEST(WatcherImplTest, All) { unlink(TestEnvironment::temporaryPath("envoy_test/watcher_new_target").c_str()); unlink(TestEnvironment::temporaryPath("envoy_test/watcher_new_link").c_str()); +#if defined(WIN32) + _mkdir(TestEnvironment::temporaryPath("envoy_test").c_str()); +#else mkdir(TestEnvironment::temporaryPath("envoy_test").c_str(), S_IRWXU); +#endif + { std::ofstream file(TestEnvironment::temporaryPath("envoy_test/watcher_target")); } +#if defined(WIN32) + int rc = CreateSymbolicLink(TestEnvironment::temporaryPath("envoy_test/watcher_target").c_str(), + TestEnvironment::temporaryPath("envoy_test/watcher_link").c_str(), 0); + EXPECT_NE(0, rc); +#else int rc = symlink(TestEnvironment::temporaryPath("envoy_test/watcher_target").c_str(), TestEnvironment::temporaryPath("envoy_test/watcher_link").c_str()); EXPECT_EQ(0, rc); +#endif { std::ofstream file(TestEnvironment::temporaryPath("envoy_test/watcher_new_target")); } +#if defined(WIN32) + rc = CreateSymbolicLink(TestEnvironment::temporaryPath("envoy_test/watcher_new_target").c_str(), + TestEnvironment::temporaryPath("envoy_test/watcher_new_link").c_str(), 0); + EXPECT_NE(0, rc); +#else rc = symlink(TestEnvironment::temporaryPath("envoy_test/watcher_new_target").c_str(), TestEnvironment::temporaryPath("envoy_test/watcher_new_link").c_str()); EXPECT_EQ(0, rc); +#endif WatchCallback callback; EXPECT_CALL(callback, called(Watcher::Events::MovedTo)).Times(2); @@ -50,9 +71,15 @@ TEST(WatcherImplTest, All) { TestEnvironment::temporaryPath("envoy_test/watcher_link").c_str()); dispatcher.run(Event::Dispatcher::RunType::Block); +#if defined(WIN32) + rc = CreateSymbolicLink(TestEnvironment::temporaryPath("envoy_test/watcher_new_target").c_str(), + TestEnvironment::temporaryPath("envoy_test/watcher_new_link").c_str(), 0); + EXPECT_NE(0, rc); +#else rc = symlink(TestEnvironment::temporaryPath("envoy_test/watcher_new_target").c_str(), TestEnvironment::temporaryPath("envoy_test/watcher_new_link").c_str()); EXPECT_EQ(0, rc); +#endif rename(TestEnvironment::temporaryPath("envoy_test/watcher_new_link").c_str(), TestEnvironment::temporaryPath("envoy_test/watcher_link").c_str()); dispatcher.run(Event::Dispatcher::RunType::Block); @@ -67,7 +94,12 @@ TEST(WatcherImplTest, Create) { unlink(TestEnvironment::temporaryPath("envoy_test/watcher_new_link").c_str()); unlink(TestEnvironment::temporaryPath("envoy_test/other_file").c_str()); +#if defined(WIN32) + _mkdir(TestEnvironment::temporaryPath("envoy_test").c_str()); +#else mkdir(TestEnvironment::temporaryPath("envoy_test").c_str(), S_IRWXU); +#endif + { std::ofstream file(TestEnvironment::temporaryPath("envoy_test/watcher_target")); } WatchCallback callback; @@ -81,9 +113,16 @@ TEST(WatcherImplTest, Create) { { std::ofstream file(TestEnvironment::temporaryPath("envoy_test/other_file")); } dispatcher.run(Event::Dispatcher::RunType::NonBlock); +#if defined(WIN32) + int rc = + CreateSymbolicLink(TestEnvironment::temporaryPath("envoy_test/watcher_target").c_str(), + TestEnvironment::temporaryPath("envoy_test/watcher_new_link").c_str(), 0); + EXPECT_NE(0, rc); +#else int rc = symlink(TestEnvironment::temporaryPath("envoy_test/watcher_target").c_str(), TestEnvironment::temporaryPath("envoy_test/watcher_new_link").c_str()); EXPECT_EQ(0, rc); +#endif rc = rename(TestEnvironment::temporaryPath("envoy_test/watcher_new_link").c_str(), TestEnvironment::temporaryPath("envoy_test/watcher_link").c_str()); @@ -109,7 +148,11 @@ TEST(WatcherImplTest, ParentDirectoryRemoved) { Event::DispatcherImpl dispatcher; Filesystem::WatcherPtr watcher = dispatcher.createFilesystemWatcher(); +#if defined(WIN32) + _mkdir(TestEnvironment::temporaryPath("envoy_test_empty").c_str()); +#else mkdir(TestEnvironment::temporaryPath("envoy_test_empty").c_str(), S_IRWXU); +#endif WatchCallback callback; EXPECT_CALL(callback, called(testing::_)).Times(0); diff --git a/test/common/grpc/CMakeLists.txt b/test/common/grpc/CMakeLists.txt new file mode 100644 index 0000000000000..4d910f1d1f10d --- /dev/null +++ b/test/common/grpc/CMakeLists.txt @@ -0,0 +1,140 @@ +add_executable(grpc_async_client_impl_test async_client_impl_test.cc) +target_link_libraries(grpc_async_client_impl_test + async_client_lib + http_mocks + tracing_mocks + upstream_mocks + helloworld_lib + + test_main + +#dependencies + envoy_all_lib +) + +add_executable(async_client_manager_impl_test async_client_manager_impl_test.cc) +target_link_libraries(async_client_manager_impl_test + common_grpc_async_client_manager_lib + stats_mocks + thread_local_mocks + upstream_mocks + test_common_utility_lib + + test_main + +#dependencies + envoy_all_lib +) + +add_executable(codec_test codec_test.cc) +target_link_libraries(codec_test + buffer_lib + codec_lib + helloworld_lib + + test_main + +#dependencies + envoy_all_lib +) + +add_executable(common_test common_test.cc) +target_link_libraries(common_test + common_lib + upstream_mocks + helloworld_lib + test_common_utility_lib + + test_main + +#dependencies + envoy_all_lib +) + +add_library(grpc_client_integration_lib INTERFACE) +target_link_libraries(grpc_client_integration_lib INTERFACE + test_common_utility_lib +) + +add_executable(grpc_client_integration_test grpc_client_integration_test.cc) +target_link_libraries(grpc_client_integration_test + grpc_client_integration_lib + dispatcher_lib + async_client_lib + http2_conn_pool_lib + connection_lib + common_network_raw_buffer_socket_lib + stats_lib + integration_lib + grpc_mocks + http_mocks + local_info_mocks + router_mocks + runtime_mocks + tracing_mocks + upstream_mocks + helloworld_lib + environment_lib + + test_main + +#dependencies + envoy_all_lib +) + +add_executable(http1_bridge_filter_test http1_bridge_filter_test.cc) +target_link_libraries(http1_bridge_filter_test + buffer_lib + http1_bridge_filter_lib + header_map_lib + http_mocks + upstream_mocks + test_common_utility_lib + + test_main + +#dependencies + envoy_all_lib +) + +add_executable(google_grpc_test google_grpc_test.cc) +target_link_libraries(google_grpc_test + test_main + +#dependencies + envoy_all_lib + gpr.lib + grpc.lib + grpc++.lib + + ssl.lib + crypto.lib + decrepit.lib + cares.lib +) +target_link_libraries(google_grpc_test + debug zlibd.lib +) +target_link_libraries(google_grpc_test + optimized zlib.lib +) + +add_executable(grpc_web_filter_test grpc_web_filter_test.cc) +target_link_libraries(grpc_web_filter_test + grpc_web_filter_lib + http_mocks + upstream_mocks + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) + +file(COPY ${PROJECT_SOURCE_DIR}/test/proto/bookstore.proto DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +#file(COPY bookstore_proto_descriptor DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + +#source not compiled for windows +#add_executable(json_transcoder_filter_test json_transcoder_filter_test.cc) +#source not compiled for windows +#add_executable(transcoder_input_stream_test transcoder_input_stream_test.cc) diff --git a/test/common/grpc/google_grpc_test.cc b/test/common/grpc/google_grpc_test.cc index a8bb0fba46b00..c08b3cd457e73 100644 --- a/test/common/grpc/google_grpc_test.cc +++ b/test/common/grpc/google_grpc_test.cc @@ -1,3 +1,6 @@ +#if defined(WIN32) && !defined(_WIN32_WINNT) +#define _WIN32_WINNT 0x0A00 +#endif #include "grpc++/channel.h" #include "grpc++/grpc++.h" #include "gtest/gtest.h" diff --git a/test/common/html/CMakeLists.txt b/test/common/html/CMakeLists.txt new file mode 100644 index 0000000000000..117d5a5b789fc --- /dev/null +++ b/test/common/html/CMakeLists.txt @@ -0,0 +1,8 @@ +add_executable(html_utility_test utility_test.cc) +target_link_libraries(html_utility_test + common_html_utility + test_main + +#dependencies + envoy_all_lib +) \ No newline at end of file diff --git a/test/common/http/CMakeLists.txt b/test/common/http/CMakeLists.txt new file mode 100644 index 0000000000000..3b353fe17ce62 --- /dev/null +++ b/test/common/http/CMakeLists.txt @@ -0,0 +1,258 @@ +add_executable(async_client_impl_test async_client_impl_test.cc) +target_link_libraries(async_client_impl_test + buffer_lib + async_client_lib + http_utility_lib + test_mocks_common_lib + http_common_lib + + buffer_mocks + http_mocks + local_info_mocks + router_mocks + runtime_mocks + stats_mocks + upstream_mocks + + test_main + +#dependencies + envoy_all_lib +) + +target_link_libraries(async_client_impl_test + debug gtestd.lib +) + +target_link_libraries(async_client_impl_test + optimized gtest.lib +) + +add_executable(codec_client_test codec_client_test.cc) +target_link_libraries(codec_client_test + buffer_lib + dispatcher_lib + codec_client_lib + network_utility_lib + upstream_lib + upstream_utility_lib + test_mocks_common_lib + event_mocks + http_mocks + network_mocks + upstream_mocks + environment_lib + test_network_utility_lib + test_common_utility_lib + + test_main + +#dependencies + envoy_all_lib +) + +target_link_libraries(codec_client_test + debug gtestd.lib +) + +target_link_libraries(codec_client_test + optimized gtest.lib +) + +add_executable(codes_test codes_test.cc) +target_link_libraries(codes_test + codes_lib + header_map_lib + stats_lib + test_common_utility_lib + stats_mocks + test_main + +#dependencies + envoy_all_lib +) + +target_link_libraries(codes_test + debug gtestd.lib +) + +target_link_libraries(codes_test + optimized gtest.lib +) + +add_library(http_common_lib common.cc) +target_link_libraries(http_common_lib + test_mocks_common_lib + +#dependencies +) + +target_link_libraries(http_common_lib + debug gtestd.lib +) + +target_link_libraries(http_common_lib + optimized gtest.lib +) + +add_executable(conn_manager_impl_test conn_manager_impl_test.cc) +target_link_libraries(conn_manager_impl_test + access_log_formatter_lib + access_log_lib + buffer_lib + dispatcher_lib + conn_manager_lib + date_provider_lib + header_map_lib + address_lib + stats_lib + upstream_lib + + test_mocks_common_lib + access_log_mocks + buffer_mocks + http_mocks + local_info_mocks + network_mocks + runtime_mocks + ssl_mocks + tracing_mocks + upstream_mocks + + test_main + +#dependencies + test_common_utility_lib + +#dependencies + envoy_all_lib +) + +target_link_libraries(conn_manager_impl_test + debug gtestd.lib +) + +target_link_libraries(conn_manager_impl_test + optimized gtest.lib +) + +add_executable(conn_manager_utility_test conn_manager_utility_test.cc) +target_link_libraries(conn_manager_utility_test + dispatcher_lib + conn_manager_lib + address_lib + network_utility_lib + runtime_lib + uuid_util_lib + + http_mocks + local_info_mocks + network_mocks + runtime_mocks + ssl_mocks + upstream_mocks + test_common_utility_lib + + test_main + +#dependencies + envoy_all_lib +) + +target_link_libraries(conn_manager_utility_test + debug gtestd.lib +) + +target_link_libraries(conn_manager_utility_test + optimized gtest.lib +) + +add_executable(date_provider_impl_test date_provider_impl_test.cc) +target_link_libraries(date_provider_impl_test + date_provider_lib + header_map_lib + event_mocks + thread_local_mocks + + test_main + +#dependencies + envoy_all_lib +) + +target_link_libraries(date_provider_impl_test + debug gtestd.lib +) + +target_link_libraries(date_provider_impl_test + optimized gtest.lib +) + +add_executable(header_map_impl_test header_map_impl_test.cc) +target_link_libraries(header_map_impl_test + header_map_lib + test_common_utility_lib + + test_main + +#dependencies + envoy_all_lib +) + +target_link_libraries(header_map_impl_test + debug gtestd.lib +) + +target_link_libraries(header_map_impl_test + optimized gtest.lib +) + +add_executable(user_agent_test user_agent_test.cc) +target_link_libraries(user_agent_test + header_map_lib + user_agent_lib + stats_mocks + test_common_utility_lib + + test_main + +#dependencies + envoy_all_lib +) + +target_link_libraries(user_agent_test + debug gtestd.lib +) + +target_link_libraries(user_agent_test + optimized gtest.lib +) + +add_executable(http_utility_test utility_test.cc) +target_link_libraries(http_utility_test + header_map_lib + http_utility_lib + address_lib + + http_mocks + upstream_mocks + test_common_utility_lib + + test_main + +#dependencies + logger_lib + fmt.lib +) + +target_link_libraries(http_utility_test + debug gtestd.lib +) + +target_link_libraries(http_utility_test + optimized gtest.lib +) + +add_subdirectory(filter) +add_subdirectory(http1) +add_subdirectory(http2) \ No newline at end of file diff --git a/test/common/http/codec_client_test.cc b/test/common/http/codec_client_test.cc index 20014cb3dfa6f..608750accd4b8 100644 --- a/test/common/http/codec_client_test.cc +++ b/test/common/http/codec_client_test.cc @@ -249,7 +249,12 @@ class CodecNetworkTest : public testing::TestWithParam client_; std::shared_ptr cluster_{new NiceMock()}; diff --git a/test/common/http/conn_manager_utility_test.cc b/test/common/http/conn_manager_utility_test.cc index ce88ea1bda527..8564532686aa6 100644 --- a/test/common/http/conn_manager_utility_test.cc +++ b/test/common/http/conn_manager_utility_test.cc @@ -353,6 +353,8 @@ TEST_F(ConnectionManagerUtilityTest, ExternalAddressExternalRequestDontUseRemote EXPECT_EQ("60.0.0.1", headers.get_("x-forwarded-for")); } +// TODO-WIN: PipeInstance not ported to Windows, hence disabling test. +#if !defined(WIN32) // Verify that if XFF is invalid we fall back to remote address, even if it is a pipe. TEST_F(ConnectionManagerUtilityTest, PipeAddressInvalidXFFtDontUseRemote) { connection_.remote_address_ = std::make_shared("/blah"); @@ -362,6 +364,7 @@ TEST_F(ConnectionManagerUtilityTest, PipeAddressInvalidXFFtDontUseRemote) { EXPECT_EQ((MutateRequestRet{"/blah", false}), callMutateRequestHeaders(headers, Protocol::Http2)); EXPECT_FALSE(headers.has("x-envoy-external-address")); } +#endif // Verify that we treat a request as external even if the direct remote is internal and XFF // includes only internal addresses. Note that this is legacy behavior. See the comments diff --git a/test/common/http/filter/CMakeLists.txt b/test/common/http/filter/CMakeLists.txt new file mode 100644 index 0000000000000..9ef3f5a63454f --- /dev/null +++ b/test/common/http/filter/CMakeLists.txt @@ -0,0 +1,107 @@ +add_executable(buffer_filter_test buffer_filter_test.cc) +target_link_libraries(buffer_filter_test + header_map_lib + buffer_filter_lib + stats_lib + buffer_mocks + http_mocks + upstream_mocks + test_main + +#dependencies + envoy_all_lib +) + +target_link_libraries(buffer_filter_test + debug gtestd.lib +) + +target_link_libraries(buffer_filter_test + optimized gtest.lib +) + +# TODO-WIN cors_filter not compiled for Windows. +#add_executable(cors_filter_test cors_filter_test.cc) + +add_executable(fault_filter_test fault_filter_test.cc) +target_link_libraries(fault_filter_test + buffer_lib + filter_json_lib + header_map_lib + fault_filter_lib + stats_lib + common_lib + http_mocks + runtime_mocks + upstream_mocks + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) + +target_link_libraries(fault_filter_test + debug gtestd.lib +) + +target_link_libraries(fault_filter_test + optimized gtest.lib +) + +add_executable(ip_tagging_filter_test ip_tagging_filter_test.cc) +target_link_libraries(ip_tagging_filter_test + buffer_lib + filter_json_lib + header_map_lib + fault_filter_lib + stats_lib + common_lib + http_mocks + runtime_mocks + upstream_mocks + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) + +target_link_libraries(ip_tagging_filter_test + debug gtestd.lib +) + +target_link_libraries(ip_tagging_filter_test + optimized gtest.lib +) + +add_executable(ratelimit_test ratelimit_test.cc) +target_link_libraries(ratelimit_test + buffer_lib + filter_json_lib + ratelimit_lib + http_ratelimit_lib + fault_filter_lib + http_mocks + runtime_mocks + ratelimit_mocks + tracing_mocks + upstream_mocks + local_info_mocks + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) + +target_link_libraries(ratelimit_test + debug gtestd.lib +) + +target_link_libraries(ratelimit_test + optimized gtest.lib +) + +#TODO-WIN. lua source not compiled for windows +#add_subdirectory(lua) \ No newline at end of file diff --git a/test/common/http/header_map_impl_test.cc b/test/common/http/header_map_impl_test.cc index 4ae84ba208e3e..3c3c8cc59d300 100644 --- a/test/common/http/header_map_impl_test.cc +++ b/test/common/http/header_map_impl_test.cc @@ -274,8 +274,8 @@ TEST(HeaderStringTest, All) { EXPECT_FALSE(string.caseInsensitiveContains("alive")); EXPECT_FALSE(string.caseInsensitiveContains("grade")); - const std::string small("close"); - string.setCopy(small.c_str(), small.size()); + const std::string small_string("close"); + string.setCopy(small_string.c_str(), small_string.size()); EXPECT_FALSE(string.caseInsensitiveContains("keep-alive")); const std::string empty(""); diff --git a/test/common/http/http1/CMakeLists.txt b/test/common/http/http1/CMakeLists.txt new file mode 100644 index 0000000000000..2f842805e62da --- /dev/null +++ b/test/common/http/http1/CMakeLists.txt @@ -0,0 +1,54 @@ +add_executable(http1_codec_impl_test codec_impl_test.cc) +target_link_libraries(http1_codec_impl_test + buffer_lib + dispatcher_lib + header_map_lib + http1_codec_lib + buffer_mocks + http_mocks + network_mocks + upstream_mocks + test_main + +#dependencies + envoy_all_lib +) + +target_link_libraries(http1_codec_impl_test + debug gtestd.lib +) + +target_link_libraries(http1_codec_impl_test + optimized gtest.lib +) + +add_executable(http1_conn_pool_test conn_pool_test.cc) +target_link_libraries(http1_conn_pool_test + buffer_lib + dispatcher_lib + http1_conn_pool_lib + network_utility_lib + upstream_lib + upstream_utility_lib + common_lib + buffer_mocks + event_mocks + http_mocks + network_mocks + runtime_mocks + upstream_mocks + test_common_utility_lib + + test_main + +#dependencies + envoy_all_lib +) + +target_link_libraries(http1_conn_pool_test + debug gtestd.lib +) + +target_link_libraries(http1_conn_pool_test + optimized gtest.lib +) \ No newline at end of file diff --git a/test/common/http/http2/CMakeLists.txt b/test/common/http/http2/CMakeLists.txt new file mode 100644 index 0000000000000..42b05e7b282f6 --- /dev/null +++ b/test/common/http/http2/CMakeLists.txt @@ -0,0 +1,58 @@ +add_executable(http2_codec_impl_test codec_impl_test.cc) +target_link_libraries(http2_codec_impl_test + buffer_lib + dispatcher_lib + header_map_lib + http2_codec_lib + http_common_lib + http_utility_lib + stats_lib + common_lib + buffer_mocks + http_mocks + network_mocks + upstream_mocks + test_main + +#dependencies + envoy_all_lib +) + +target_link_libraries(http2_codec_impl_test + debug gtestd.lib +) + +target_link_libraries(http2_codec_impl_test + optimized gtest.lib +) + +add_executable(http2_conn_pool_test conn_pool_test.cc) +target_link_libraries(http2_conn_pool_test + buffer_lib + dispatcher_lib + http2_conn_pool_lib + network_utility_lib + upstream_lib + upstream_utility_lib + common_lib + buffer_mocks + event_mocks + http_mocks + network_mocks + runtime_mocks + upstream_mocks + test_common_utility_lib + + test_main + +#dependencies + envoy_all_lib +) + +target_link_libraries(http2_conn_pool_test + debug gtestd.lib +) + +target_link_libraries(http2_conn_pool_test + optimized gtest.lib +) \ No newline at end of file diff --git a/test/common/http/utility_test.cc b/test/common/http/utility_test.cc index b5aa83d25901d..e341aa5813478 100644 --- a/test/common/http/utility_test.cc +++ b/test/common/http/utility_test.cc @@ -69,12 +69,16 @@ TEST(HttpUtility, appendXff) { EXPECT_EQ("10.0.0.1, 127.0.0.1", headers.get_("x-forwarded-for")); } +#if !defined(WIN32) + //TODO-WIN: PipeInstance not yet ported to windows. Hence disabling test. { TestHeaderMapImpl headers{{"x-forwarded-for", "10.0.0.1"}}; Network::Address::PipeInstance address("/foo"); Utility::appendXff(headers, address); EXPECT_EQ("10.0.0.1", headers.get_("x-forwarded-for")); } +#endif + } TEST(HttpUtility, createSslRedirectPath) { diff --git a/test/common/json/CMakeLists.txt b/test/common/json/CMakeLists.txt new file mode 100644 index 0000000000000..eaa3f7e52845c --- /dev/null +++ b/test/common/json/CMakeLists.txt @@ -0,0 +1,22 @@ +add_executable(config_schemas_test config_schemas_test.cc) +target_link_libraries(config_schemas_test + config_schemas_lib + json_loader_lib + environment_lib + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) +file(COPY config_schemas_test_data DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + +add_executable(json_loader_test json_loader_test.cc) +target_link_libraries(json_loader_test + json_loader_lib + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) \ No newline at end of file diff --git a/test/common/json/config_schemas_test.cc b/test/common/json/config_schemas_test.cc index e5e4aea31ff86..c961a214f6bc8 100644 --- a/test/common/json/config_schemas_test.cc +++ b/test/common/json/config_schemas_test.cc @@ -17,8 +17,12 @@ namespace Envoy { namespace Json { std::vector generateTestInputs() { +// TODO: For Win32, run the generate_test_data.py script manually (post build) to generate the schema files. +// Remove this ifdef once TestEnvironment::exec handles python scripts on windows. +#if !defined(WIN32) TestEnvironment::exec({TestEnvironment::runfilesPath( "test/common/json/config_schemas_test_data/generate_test_data")}); +#endif std::string test_path = TestEnvironment::temporaryDirectory() + "/config_schemas_test"; auto file_list = TestUtility::listFiles(test_path, false); diff --git a/test/common/network/CMakeLists.txt b/test/common/network/CMakeLists.txt new file mode 100644 index 0000000000000..878db7b9e4045 --- /dev/null +++ b/test/common/network/CMakeLists.txt @@ -0,0 +1,316 @@ +#include(GoogleTest) + +add_executable(address_impl_test address_impl_test.cc) +target_link_libraries(address_impl_test + address_lib + network_utility_lib + environment_lib + test_network_utility_lib + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) + +target_link_libraries(address_impl_test + debug gtestd.lib +) + +target_link_libraries(address_impl_test + optimized gtest.lib +) + +add_executable(cidr_range_test cidr_range_test.cc) +target_link_libraries(cidr_range_test + address_lib + cidr_range_lib + json_loader_lib + test_main + +#dependencies + envoy_all_lib +) + +target_link_libraries(cidr_range_test + debug gtestd.lib + debug absl_based.lib + debug absl_stringsd.lib + +) + +target_link_libraries(cidr_range_test + optimized gtest.lib + optimized absl_base.lib + optimized absl_strings.lib +) + +add_executable(connection_impl_test connection_impl_test.cc) +target_link_libraries(connection_impl_test + buffer_lib + dispatcher_lib + connection_lib + listen_socket_lib + network_utility_lib + stats_lib + + buffer_mocks + event_mocks + network_mocks + server_mocks + stats_mocks + environment_lib + test_network_utility_lib + test_main + +#dependencies + utility_lib + logger_lib + libevent_lib + watcher_lib + connection_lib + dns_lib + listener_lib + connection_lib_ssl + listen_socket_lib + address_lib + context_lib + hex_lib + filter_manager_lib + common_ssl_ssl_socket_lib + fmt.lib + event.lib + event_core.lib + event_extra.lib + ws2_32.lib + cares.lib + envoy_all_lib +) + +target_link_libraries(connection_impl_test + debug gtestd.lib +) + +target_link_libraries(connection_impl_test + optimized gtest.lib +) + +add_executable(dns_impl_test dns_impl_test.cc) +target_link_libraries(dns_impl_test + buffer_lib + dispatcher_lib + dns_lib + listen_socket_lib + network_utility_lib + stats_lib + + network_mocks + environment_lib + test_network_utility_lib + test_main + +#dependencies + envoy_all_lib +) + +target_link_libraries(dns_impl_test + debug gtestd.lib +) + +target_link_libraries(dns_impl_test + optimized gtest.lib +) + +add_executable(filter_manager_impl_test filter_manager_impl_test.cc) +target_link_libraries(filter_manager_impl_test + buffer_lib + filter_json_lib + ratelimit_lib + dispatcher_lib + ratelimit_lib_filter + tcp_proxy_lib + filter_manager_lib + stats_lib + + upstream_lib + upstream_utility_lib + buffer_mocks + network_mocks + ratelimit_mocks + runtime_mocks + server_mocks + tracing_mocks + host_mocks + upstream_mocks + logger_lib + + test_main + +#dependencies + access_log_lib + uuid_util_lib + utility_lib + http_tracer_lib + fmt.lib + crypto.lib + decrepit.lib + ssl.lib + envoy_all_lib +) + +target_link_libraries(filter_manager_impl_test + debug gtestd.lib +) + +target_link_libraries(filter_manager_impl_test + optimized gtest.lib +) + +add_executable(listen_socket_impl_test listen_socket_impl_test.cc) +target_link_libraries(listen_socket_impl_test + listen_socket_lib + network_utility_lib + environment_lib + test_network_utility_lib + test_main + +#dependencies + utility_lib + config_utility_lib + listen_socket_lib + fmt.lib + logger_lib + config_schemas_lib + envoy_all_lib +) + +target_link_libraries(listen_socket_impl_test + debug gtestd.lib +) + +target_link_libraries(listen_socket_impl_test + optimized gtest.lib +) + +add_executable(listener_impl_test listener_impl_test.cc) +target_link_libraries(listener_impl_test + dispatcher_lib + address_lib + listener_lib + utility_lib + stats_lib + network_mocks + server_mocks + network_utility_lib + environment_lib + test_main + +#dependencies + watcher_lib + connection_lib + dns_lib + listener_lib + connection_lib_ssl + common_ssl_ssl_socket_lib + context_lib + hex_lib + logger_lib + filter_manager_lib + common_ssl_ssl_socket_lib + envoy_all_lib + utility_lib + fmt.lib + crypto.lib + decrepit.lib + ssl.lib + cares.lib +) + +target_link_libraries(listener_impl_test + debug gtestd.lib +) + +target_link_libraries(listener_impl_test + optimized gtest.lib +) + +add_executable(proxy_protocol_test proxy_protocol_test.cc) +target_link_libraries(proxy_protocol_test + buffer_lib + dispatcher_lib + listener_lib + utility_lib + stats_lib + connection_handler_lib + buffer_mocks + network_mocks + server_mocks + + network_utility_lib + environment_lib + test_main + +#dependencies + utility_lib + watcher_lib + connection_lib + dns_lib + listener_lib + connection_lib_ssl + common_ssl_ssl_socket_lib + context_lib + hex_lib + fmt.lib + envoy_all_lib +) + +target_link_libraries(proxy_protocol_test + debug gtestd.lib +) + +target_link_libraries(proxy_protocol_test + optimized gtest.lib +) + +add_executable(resolver_test resolver_impl_test.cc) +target_link_libraries(resolver_test + address_lib + resolver_impl_lib + network_mocks + + environment_lib + test_main + +#dependencies + envoy_all_lib +) + +target_link_libraries(resolver_test + debug gtestd.lib +) + +target_link_libraries(resolver_test + optimized gtest.lib +) + +add_executable(network_utility_test utility_test.cc) +target_link_libraries(network_utility_test + address_lib + utility_lib + environment_lib + test_main + +#dependencies + logger_lib + utility_lib + fmt.lib + envoy_all_lib +) + +target_link_libraries(network_utility_test + debug gtestd.lib +) + +target_link_libraries(network_utility_test + optimized gtest.lib +) \ No newline at end of file diff --git a/test/common/network/address_impl_test.cc b/test/common/network/address_impl_test.cc index 6808c9cf00375..b76c49f990ac4 100644 --- a/test/common/network/address_impl_test.cc +++ b/test/common/network/address_impl_test.cc @@ -1,10 +1,13 @@ +#if defined(WIN32) +typedef unsigned int sa_family_t; +#else #include -#include #include #include #include #include - +#endif +#include #include #include "envoy/common/exception.h" @@ -32,11 +35,13 @@ bool addressesEqual(const InstanceConstSharedPtr& a, const Instance& b) { } } +#if !defined(WIN32) void makeFdBlocking(int fd) { - const int flags = ::fcntl(fd, F_GETFL, 0); + const int flags = fcntl(fd, F_GETFL, 0); ASSERT_GE(flags, 0); - ASSERT_EQ(::fcntl(fd, F_SETFL, flags & (~O_NONBLOCK)), 0); + ASSERT_EQ(fcntl(fd, F_SETFL, flags & (~O_NONBLOCK)), 0); } +#endif void testSocketBindAndConnect(Network::Address::IpVersion ip_version, bool v6only) { auto addr_port = Network::Utility::parseInternetAddressAndPort( @@ -58,7 +63,12 @@ void testSocketBindAndConnect(Network::Address::IpVersion ip_version, bool v6onl if (addr_port->ip()->version() == IpVersion::v6) { int socket_v6only = 0; socklen_t size_int = sizeof(socket_v6only); +#if !defined(WIN32) ASSERT_GE(::getsockopt(listen_fd, IPPROTO_IPV6, IPV6_V6ONLY, &socket_v6only, &size_int), 0); +#else + ASSERT_GE(::getsockopt(listen_fd, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&socket_v6only, &size_int), + 0); +#endif EXPECT_EQ(v6only, socket_v6only); } @@ -77,11 +87,13 @@ void testSocketBindAndConnect(Network::Address::IpVersion ip_version, bool v6onl ASSERT_GE(client_fd, 0) << addr_port->asString(); ScopedFdCloser closer2(client_fd); +#if !defined(WIN32) // Instance::socket creates a non-blocking socket, which that extends all the way to the // operation of ::connect(), so connect returns with errno==EWOULDBLOCK before the tcp // handshake can complete. For testing convenience, re-enable blocking on the socket // so that connect will wait for the handshake to complete. makeFdBlocking(client_fd); +#endif // Connect to the server. const int rc = addr_port->connect(client_fd); @@ -280,12 +292,15 @@ TEST(Ipv6InstanceTest, BadAddress) { EXPECT_THROW(Ipv6Instance("bar", 1), EnvoyException); } +// TODO-WIN: PipeInstance not compiled for Windows. Hence disabling test. +#if !defined(WIN32) TEST(PipeInstanceTest, Basic) { PipeInstance address("/foo"); EXPECT_EQ("/foo", address.asString()); EXPECT_EQ(Type::Pipe, address.type()); EXPECT_EQ(nullptr, address.ip()); } +#endif TEST(AddressFromSockAddr, IPv4) { sockaddr_storage ss; @@ -330,6 +345,7 @@ TEST(AddressFromSockAddr, IPv6) { addressFromSockAddr(ss, sizeof(sockaddr_in6), true)->asString()); } +#if !defined(WIN32) TEST(AddressFromSockAddr, Pipe) { sockaddr_storage ss; auto& sun = reinterpret_cast(ss); @@ -349,6 +365,7 @@ TEST(AddressFromSockAddr, Pipe) { addressFromSockAddr(ss, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(sun.sun_path)), EnvoyException); } +#endif } // namespace Address } // namespace Network diff --git a/test/common/network/cidr_range_test.cc b/test/common/network/cidr_range_test.cc index 49c3840120a8c..63ae9ec6f9c1b 100644 --- a/test/common/network/cidr_range_test.cc +++ b/test/common/network/cidr_range_test.cc @@ -1,4 +1,9 @@ + +#if defined(WIN32) +#include +#else #include +#endif #include #include @@ -102,7 +107,9 @@ TEST(IsInRange, Various) { EXPECT_TRUE(rng.isInRange(Ipv4Instance("9.255.255.255"))); EXPECT_TRUE(rng.isInRange(Ipv4Instance("0.0.0.0"))); EXPECT_FALSE(rng.isInRange(Ipv6Instance("::"))); +#if !defined(WIN32) EXPECT_FALSE(rng.isInRange(PipeInstance("foo"))); +#endif } { @@ -127,7 +134,9 @@ TEST(IsInRange, Various) { EXPECT_TRUE(rng.isInRange(Ipv6Instance("::1"))); EXPECT_TRUE(rng.isInRange(Ipv6Instance("2001::"))); EXPECT_FALSE(rng.isInRange(Ipv4Instance("0.0.0.0"))); +#if !defined(WIN32) EXPECT_FALSE(rng.isInRange(PipeInstance("foo"))); +#endif } { @@ -483,7 +492,9 @@ TEST(IpListTest, Normal) { EXPECT_FALSE(wl.contains(Address::Ipv4Instance("10.16.0.0"))); EXPECT_FALSE(wl.contains(Address::Ipv6Instance("::1"))); +#if !defined(WIN32) EXPECT_FALSE(wl.contains(Address::PipeInstance("foo"))); +#endif } TEST(IpListTest, AddressVersionMix) { @@ -516,8 +527,9 @@ TEST(IpListTest, AddressVersionMix) { EXPECT_TRUE(wl.contains(Address::Ipv6Instance("::1"))); EXPECT_FALSE(wl.contains(Address::Ipv6Instance("::"))); - +#if !defined(WIN32) EXPECT_FALSE(wl.contains(Address::PipeInstance("foo"))); +#endif } TEST(IpListTest, MatchAny) { @@ -540,7 +552,9 @@ TEST(IpListTest, MatchAny) { EXPECT_TRUE(wl.contains(Address::Ipv4Instance("1.1.1.1"))); EXPECT_FALSE(wl.contains(Address::Ipv6Instance("::1"))); +#if !defined(WIN32) EXPECT_FALSE(wl.contains(Address::PipeInstance("foo"))); +#endif } TEST(IpListTest, MatchAnyAll) { @@ -568,7 +582,9 @@ TEST(IpListTest, MatchAnyAll) { EXPECT_TRUE(wl.contains(Address::Ipv6Instance("2001:db8:85a3::"))); EXPECT_TRUE(wl.contains(Address::Ipv6Instance("ffee::"))); +#if !defined(WIN32) EXPECT_FALSE(wl.contains(Address::PipeInstance("foo"))); +#endif } } // namespace Address diff --git a/test/common/network/connection_impl_test.cc b/test/common/network/connection_impl_test.cc index ae869ca079ace..00aa8ea77b244 100644 --- a/test/common/network/connection_impl_test.cc +++ b/test/common/network/connection_impl_test.cc @@ -160,7 +160,12 @@ class ConnectionImplTest : public testing::TestWithParam { protected: Event::DispatcherPtr dispatcher_; Stats::IsolatedStoreImpl stats_store_; +#if defined(WIN32) + // On windows, 0.0.0.0 does not work for outbound connections. Hence default to loopback. + Network::TcpListenSocket socket_{Network::Test::getCanonicalLoopbackAddress(GetParam()), true}; +#else Network::TcpListenSocket socket_{Network::Test::getAnyAddress(GetParam()), true}; +#endif Network::MockListenerCallbacks listener_callbacks_; Network::MockConnectionHandler connection_handler_; Network::ListenerPtr listener_; @@ -176,9 +181,8 @@ class ConnectionImplTest : public testing::TestWithParam { INSTANTIATE_TEST_CASE_P(IpVersions, ConnectionImplTest, testing::ValuesIn(TestEnvironment::getIpVersionsForTest())); -TEST_P(ConnectionImplTest, CloseDuringConnectCallback) { +TEST_P(ConnectionImplTest, CloseDuringConnectCallback) { setUpBasicConnection(); - Buffer::OwnedImpl buffer("hello world"); client_connection_->write(buffer); client_connection_->connect(); @@ -307,7 +311,7 @@ TEST_P(ConnectionImplTest, ReadDisable) { } TEST_P(ConnectionImplTest, EarlyCloseOnReadDisabledConnection) { -#ifdef __APPLE__ +#if defined(__APPLE__) || defined(WIN32) // On our current OSX build, the client connection does not get the early // close notification and instead gets the close after reading the FIN. return; diff --git a/test/common/network/dns_impl_test.cc b/test/common/network/dns_impl_test.cc index 28accb4de76bc..b5a2408cf8ca2 100644 --- a/test/common/network/dns_impl_test.cc +++ b/test/common/network/dns_impl_test.cc @@ -1,6 +1,12 @@ +#if !defined(WIN32) #include #include #include +#else +#include +// arpa/nameser.h not present on windows, copy the header. +#include "nameser.h" +#endif #include #include @@ -123,15 +129,16 @@ class TestDnsServerQuery { // The response begins with the intial part of the request // (including the question section). - const size_t response_base_len = HFIXEDSZ + name_len + QFIXEDSZ; - unsigned char response_base[response_base_len]; - memcpy(response_base, request, response_base_len); - DNS_HEADER_SET_QR(response_base, 1); - DNS_HEADER_SET_AA(response_base, 0); - DNS_HEADER_SET_RCODE(response_base, ips != nullptr ? NOERROR : NXDOMAIN); - DNS_HEADER_SET_ANCOUNT(response_base, ips != nullptr ? ips->size() : 0); - DNS_HEADER_SET_NSCOUNT(response_base, 0); - DNS_HEADER_SET_ARCOUNT(response_base, 0); + size_t response_base_len = HFIXEDSZ + name_len + QFIXEDSZ; + ASSERT_GE(response_base_len, 1); + std::vector response_base(response_base_len); + memcpy(&response_base[0], request, response_base_len); + DNS_HEADER_SET_QR(&response_base[0], 1); + DNS_HEADER_SET_AA(&response_base[0], 0); + DNS_HEADER_SET_RCODE(&response_base[0], ips != nullptr ? NOERROR : NXDOMAIN); + DNS_HEADER_SET_ANCOUNT(&response_base[0], ips != nullptr ? ips->size() : 0); + DNS_HEADER_SET_NSCOUNT(&response_base[0], 0); + DNS_HEADER_SET_ARCOUNT(&response_base[0], 0); // Create a resource record for each IP found in the host map. unsigned char response_rr_fixed[RRFIXEDSZ]; @@ -157,7 +164,7 @@ class TestDnsServerQuery { const uint16_t response_size_n = htons(response_base_len + response_rest_len); Buffer::OwnedImpl write_buffer_; write_buffer_.add(&response_size_n, sizeof(response_size_n)); - write_buffer_.add(response_base, response_base_len); + write_buffer_.add(&response_base[0], response_base_len); if (ips != nullptr) { for (const auto& it : *ips) { write_buffer_.add(question, name_len); diff --git a/test/common/network/listener_impl_test.cc b/test/common/network/listener_impl_test.cc index 7048954f216a2..9d92b3e41a5a0 100644 --- a/test/common/network/listener_impl_test.cc +++ b/test/common/network/listener_impl_test.cc @@ -122,7 +122,12 @@ TEST_P(ListenerImplTest, UseActualDst) { TEST_P(ListenerImplTest, WildcardListenerUseActualDst) { Stats::IsolatedStoreImpl stats_store; Event::DispatcherImpl dispatcher; +#if defined(WIN32) + // On windows, 0.0.0.0 does not work for outbound connections. Hence default to loopback. + Network::TcpListenSocket socket(Network::Test::getCanonicalLoopbackAddress(version_), true); +#else Network::TcpListenSocket socket(Network::Test::getAnyAddress(version_), true); +#endif Network::MockListenerCallbacks listener_callbacks; Network::MockConnectionHandler connection_handler; // Do not redirect since use_original_dst is false. diff --git a/test/common/network/nameser.h b/test/common/network/nameser.h new file mode 100644 index 0000000000000..a0302fd39894e --- /dev/null +++ b/test/common/network/nameser.h @@ -0,0 +1,211 @@ + +#ifndef ARES_NAMESER_H +#define ARES_NAMESER_H + +/* header file provided by liren@vivisimo.com */ + +#ifndef HAVE_ARPA_NAMESER_H + +#define NS_PACKETSZ 512 /* maximum packet size */ +#define NS_MAXDNAME 256 /* maximum domain name */ +#define NS_MAXCDNAME 255 /* maximum compressed domain name */ +#define NS_MAXLABEL 63 +#define NS_HFIXEDSZ 12 /* #/bytes of fixed data in header */ +#define NS_QFIXEDSZ 4 /* #/bytes of fixed data in query */ +#define NS_RRFIXEDSZ 10 /* #/bytes of fixed data in r record */ +#define NS_INT16SZ 2 +#define NS_INADDRSZ 4 +#define NS_IN6ADDRSZ 16 +#define NS_CMPRSFLGS 0xc0 /* Flag bits indicating name compression. */ +#define NS_DEFAULTPORT 53 /* For both TCP and UDP. */ + +typedef enum __ns_class { + ns_c_invalid = 0, /* Cookie. */ + ns_c_in = 1, /* Internet. */ + ns_c_2 = 2, /* unallocated/unsupported. */ + ns_c_chaos = 3, /* MIT Chaos-net. */ + ns_c_hs = 4, /* MIT Hesiod. */ + /* Query class values which do not appear in resource records */ + ns_c_none = 254, /* for prereq. sections in update requests */ + ns_c_any = 255, /* Wildcard match. */ + ns_c_max = 65536 +} ns_class; + +typedef enum __ns_type { + ns_t_invalid = 0, /* Cookie. */ + ns_t_a = 1, /* Host address. */ + ns_t_ns = 2, /* Authoritative server. */ + ns_t_md = 3, /* Mail destination. */ + ns_t_mf = 4, /* Mail forwarder. */ + ns_t_cname = 5, /* Canonical name. */ + ns_t_soa = 6, /* Start of authority zone. */ + ns_t_mb = 7, /* Mailbox domain name. */ + ns_t_mg = 8, /* Mail group member. */ + ns_t_mr = 9, /* Mail rename name. */ + ns_t_null = 10, /* Null resource record. */ + ns_t_wks = 11, /* Well known service. */ + ns_t_ptr = 12, /* Domain name pointer. */ + ns_t_hinfo = 13, /* Host information. */ + ns_t_minfo = 14, /* Mailbox information. */ + ns_t_mx = 15, /* Mail routing information. */ + ns_t_txt = 16, /* Text strings. */ + ns_t_rp = 17, /* Responsible person. */ + ns_t_afsdb = 18, /* AFS cell database. */ + ns_t_x25 = 19, /* X_25 calling address. */ + ns_t_isdn = 20, /* ISDN calling address. */ + ns_t_rt = 21, /* Router. */ + ns_t_nsap = 22, /* NSAP address. */ + ns_t_nsap_ptr = 23, /* Reverse NSAP lookup (deprecated). */ + ns_t_sig = 24, /* Security signature. */ + ns_t_key = 25, /* Security key. */ + ns_t_px = 26, /* X.400 mail mapping. */ + ns_t_gpos = 27, /* Geographical position (withdrawn). */ + ns_t_aaaa = 28, /* Ip6 Address. */ + ns_t_loc = 29, /* Location Information. */ + ns_t_nxt = 30, /* Next domain (security). */ + ns_t_eid = 31, /* Endpoint identifier. */ + ns_t_nimloc = 32, /* Nimrod Locator. */ + ns_t_srv = 33, /* Server Selection. */ + ns_t_atma = 34, /* ATM Address */ + ns_t_naptr = 35, /* Naming Authority PoinTeR */ + ns_t_kx = 36, /* Key Exchange */ + ns_t_cert = 37, /* Certification record */ + ns_t_a6 = 38, /* IPv6 address (deprecates AAAA) */ + ns_t_dname = 39, /* Non-terminal DNAME (for IPv6) */ + ns_t_sink = 40, /* Kitchen sink (experimentatl) */ + ns_t_opt = 41, /* EDNS0 option (meta-RR) */ + ns_t_apl = 42, /* Address prefix list (RFC3123) */ + ns_t_ds = 43, /* Delegation Signer (RFC4034) */ + ns_t_sshfp = 44, /* SSH Key Fingerprint (RFC4255) */ + ns_t_rrsig = 46, /* Resource Record Signature (RFC4034) */ + ns_t_nsec = 47, /* Next Secure (RFC4034) */ + ns_t_dnskey = 48, /* DNS Public Key (RFC4034) */ + ns_t_tkey = 249, /* Transaction key */ + ns_t_tsig = 250, /* Transaction signature. */ + ns_t_ixfr = 251, /* Incremental zone transfer. */ + ns_t_axfr = 252, /* Transfer zone of authority. */ + ns_t_mailb = 253, /* Transfer mailbox records. */ + ns_t_maila = 254, /* Transfer mail agent records. */ + ns_t_any = 255, /* Wildcard match. */ + ns_t_zxfr = 256, /* BIND-specific, nonstandard. */ + ns_t_max = 65536 +} ns_type; + +typedef enum __ns_opcode { + ns_o_query = 0, /* Standard query. */ + ns_o_iquery = 1, /* Inverse query (deprecated/unsupported). */ + ns_o_status = 2, /* Name server status query (unsupported). */ + /* Opcode 3 is undefined/reserved. */ + ns_o_notify = 4, /* Zone change notification. */ + ns_o_update = 5, /* Zone update message. */ + ns_o_max = 6 +} ns_opcode; + +typedef enum __ns_rcode { + ns_r_noerror = 0, /* No error occurred. */ + ns_r_formerr = 1, /* Format error. */ + ns_r_servfail = 2, /* Server failure. */ + ns_r_nxdomain = 3, /* Name error. */ + ns_r_notimpl = 4, /* Unimplemented. */ + ns_r_refused = 5, /* Operation refused. */ + /* these are for BIND_UPDATE */ + ns_r_yxdomain = 6, /* Name exists */ + ns_r_yxrrset = 7, /* RRset exists */ + ns_r_nxrrset = 8, /* RRset does not exist */ + ns_r_notauth = 9, /* Not authoritative for zone */ + ns_r_notzone = 10, /* Zone of record different from zone section */ + ns_r_max = 11, + /* The following are TSIG extended errors */ + ns_r_badsig = 16, + ns_r_badkey = 17, + ns_r_badtime = 18 +} ns_rcode; + +#endif /* HAVE_ARPA_NAMESER_H */ + +#ifndef HAVE_ARPA_NAMESER_COMPAT_H + +#define PACKETSZ NS_PACKETSZ +#define MAXDNAME NS_MAXDNAME +#define MAXCDNAME NS_MAXCDNAME +#define MAXLABEL NS_MAXLABEL +#define HFIXEDSZ NS_HFIXEDSZ +#define QFIXEDSZ NS_QFIXEDSZ +#define RRFIXEDSZ NS_RRFIXEDSZ +#define INDIR_MASK NS_CMPRSFLGS +#define NAMESERVER_PORT NS_DEFAULTPORT + +#define QUERY ns_o_query + +#define SERVFAIL ns_r_servfail +#define NOTIMP ns_r_notimpl +#define REFUSED ns_r_refused +#undef NOERROR /* it seems this is already defined in winerror.h */ +#define NOERROR ns_r_noerror +#define FORMERR ns_r_formerr +#define NXDOMAIN ns_r_nxdomain + +#define C_IN ns_c_in +#define C_CHAOS ns_c_chaos +#define C_HS ns_c_hs +#define C_NONE ns_c_none +#define C_ANY ns_c_any + +#define T_A ns_t_a +#define T_NS ns_t_ns +#define T_MD ns_t_md +#define T_MF ns_t_mf +#define T_CNAME ns_t_cname +#define T_SOA ns_t_soa +#define T_MB ns_t_mb +#define T_MG ns_t_mg +#define T_MR ns_t_mr +#define T_NULL ns_t_null +#define T_WKS ns_t_wks +#define T_PTR ns_t_ptr +#define T_HINFO ns_t_hinfo +#define T_MINFO ns_t_minfo +#define T_MX ns_t_mx +#define T_TXT ns_t_txt +#define T_RP ns_t_rp +#define T_AFSDB ns_t_afsdb +#define T_X25 ns_t_x25 +#define T_ISDN ns_t_isdn +#define T_RT ns_t_rt +#define T_NSAP ns_t_nsap +#define T_NSAP_PTR ns_t_nsap_ptr +#define T_SIG ns_t_sig +#define T_KEY ns_t_key +#define T_PX ns_t_px +#define T_GPOS ns_t_gpos +#define T_AAAA ns_t_aaaa +#define T_LOC ns_t_loc +#define T_NXT ns_t_nxt +#define T_EID ns_t_eid +#define T_NIMLOC ns_t_nimloc +#define T_SRV ns_t_srv +#define T_ATMA ns_t_atma +#define T_NAPTR ns_t_naptr +#define T_KX ns_t_kx +#define T_CERT ns_t_cert +#define T_A6 ns_t_a6 +#define T_DNAME ns_t_dname +#define T_SINK ns_t_sink +#define T_OPT ns_t_opt +#define T_APL ns_t_apl +#define T_DS ns_t_ds +#define T_SSHFP ns_t_sshfp +#define T_RRSIG ns_t_rrsig +#define T_NSEC ns_t_nsec +#define T_DNSKEY ns_t_dnskey +#define T_TKEY ns_t_tkey +#define T_TSIG ns_t_tsig +#define T_IXFR ns_t_ixfr +#define T_AXFR ns_t_axfr +#define T_MAILB ns_t_mailb +#define T_MAILA ns_t_maila +#define T_ANY ns_t_any + +#endif /* HAVE_ARPA_NAMESER_COMPAT_H */ + +#endif /* ARES_NAMESER_H */ diff --git a/test/common/network/utility_test.cc b/test/common/network/utility_test.cc index 64ba4d05f40d9..67f27b7ce73fe 100644 --- a/test/common/network/utility_test.cc +++ b/test/common/network/utility_test.cc @@ -151,7 +151,9 @@ TEST(NetworkUtility, InternalAddress) { EXPECT_FALSE(Utility::isInternalAddress(Address::Ipv6Instance("fc00::"))); EXPECT_FALSE(Utility::isInternalAddress(Address::Ipv6Instance("fe00::"))); +#if !defined(WIN32) EXPECT_FALSE(Utility::isInternalAddress(Address::PipeInstance("/hello"))); +#endif } TEST(NetworkUtility, LoopbackAddress) { @@ -163,10 +165,14 @@ TEST(NetworkUtility, LoopbackAddress) { Address::Ipv4Instance address("10.0.0.1"); EXPECT_FALSE(Utility::isLoopbackAddress(address)); } + +#if !defined(WIN32) { Address::PipeInstance address("/foo"); EXPECT_FALSE(Utility::isLoopbackAddress(address)); } +#endif + { Address::Ipv6Instance address("::1"); EXPECT_TRUE(Utility::isLoopbackAddress(address)); @@ -242,7 +248,10 @@ TEST(PortRangeListTest, Normal) { Utility::parsePortRangeList(port_range_str, port_range_list); EXPECT_TRUE(Utility::portInRangeList(makeFromPort(1), port_range_list)); EXPECT_FALSE(Utility::portInRangeList(makeFromPort(2), port_range_list)); +// TODO-WIN: Address::PipeInstance source not ported to windows. hence disabling the tests. +#if !defined(WIN32) EXPECT_FALSE(Utility::portInRangeList(Address::PipeInstance("/foo"), port_range_list)); +#endif } { diff --git a/test/common/protobuf/CMakeLists.txt b/test/common/protobuf/CMakeLists.txt new file mode 100644 index 0000000000000..a254509930d63 --- /dev/null +++ b/test/common/protobuf/CMakeLists.txt @@ -0,0 +1,10 @@ +add_executable(protobuf_utility_test utility_test.cc) +target_link_libraries(protobuf_utility_test + utility_lib_protobuf + environment_lib + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) \ No newline at end of file diff --git a/test/common/ratelimit/CMakeLists.txt b/test/common/ratelimit/CMakeLists.txt new file mode 100644 index 0000000000000..c2761bce09339 --- /dev/null +++ b/test/common/ratelimit/CMakeLists.txt @@ -0,0 +1,11 @@ +add_executable(ratelimit_impl_test ratelimit_impl_test.cc) +target_link_libraries(ratelimit_impl_test + header_map_lib + ratelimit_lib + grpc_mocks + upstream_mocks + test_main + +#dependencies + envoy_all_lib +) \ No newline at end of file diff --git a/test/common/request_info/CMakeLists.txt b/test/common/request_info/CMakeLists.txt new file mode 100644 index 0000000000000..30e90f166cbe0 --- /dev/null +++ b/test/common/request_info/CMakeLists.txt @@ -0,0 +1,21 @@ +#include(GoogleTest) + +add_executable(request_info_impl_test request_info_impl_test.cc) +target_link_libraries(request_info_impl_test + router_mocks + upstream_mocks + test_main + +#dependencies + envoy_all_lib +) + +add_executable(request_info_utility_test utility_test.cc) +target_link_libraries(request_info_utility_test + common_request_info_utility + request_info_mocks + test_main + +#dependencies + envoy_all_lib +) \ No newline at end of file diff --git a/test/common/request_info/utility_test.cc b/test/common/request_info/utility_test.cc index 583d26fe2a336..945597f85da5e 100644 --- a/test/common/request_info/utility_test.cc +++ b/test/common/request_info/utility_test.cc @@ -58,8 +58,10 @@ TEST(ResponseFlagUtilsTest, toShortStringConversion) { TEST(UtilityTest, formatDownstreamAddressNoPort) { EXPECT_EQ("1.2.3.4", Utility::formatDownstreamAddressNoPort(Network::Address::Ipv4Instance("1.2.3.4"))); +#if !defined(WIN32) EXPECT_EQ("/hello", Utility::formatDownstreamAddressNoPort(Network::Address::PipeInstance("/hello"))); +#endif } } // namespace RequestInfo diff --git a/test/common/router/CMakeLists.txt b/test/common/router/CMakeLists.txt new file mode 100644 index 0000000000000..c48838a275bbb --- /dev/null +++ b/test/common/router/CMakeLists.txt @@ -0,0 +1,143 @@ +#include(GoogleTest) + +add_executable(config_impl_test config_impl_test.cc) +target_link_libraries(config_impl_test + metadata_lib + rds_json_lib + header_map_lib + json_loader_lib + config_utility_lib_router + runtime_mocks + upstream_mocks + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) + +add_executable(rds_impl_test rds_impl_test.cc) +target_link_libraries(rds_impl_test + filter_json_lib + config_utility_lib + message_lib + json_loader_lib + rds_lib + admin_lib + init_mocks + local_info_mocks + server_mocks + thread_local_mocks + upstream_mocks + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) + +add_executable(retry_state_impl_test retry_state_impl_test.cc) +target_link_libraries(retry_state_impl_test + header_map_lib + retry_state_lib + router_mocks + runtime_mocks + upstream_mocks + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) + +add_executable(router_ratelimit_test router_ratelimit_test.cc) +target_link_libraries(router_ratelimit_test + header_map_lib + json_loader_lib + config_utility_lib_router + router_ratelimit_lib + http_mocks + ratelimit_mocks + router_mocks + upstream_mocks + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) + +add_executable(router_test router_test.cc) +target_link_libraries(router_test + buffer_lib + network_utility_lib + router_lib + upstream_lib + common_lib + http_mocks + local_info_mocks + network_mocks + router_mocks + runtime_mocks + ssl_mocks + upstream_mocks + http_common_lib + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) + +add_executable(router_upstream_log_test router_upstream_log_test.cc) +target_link_libraries(router_upstream_log_test + buffer_lib + filter_json_lib + network_utility_lib + router_lib + upstream_lib + file_access_log_lib + common_lib + access_log_mocks + filesystem_mocks + http_mocks + local_info_mocks + network_mocks + router_mocks + runtime_mocks + server_mocks + ssl_mocks + upstream_mocks + http_common_lib + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) + +add_executable(shadow_writer_impl_test shadow_writer_impl_test.cc) +target_link_libraries(shadow_writer_impl_test + message_lib + shadow_writer_lib + upstream_mocks + test_main + +#dependencies + envoy_all_lib +) + +add_executable(header_formatter_test header_formatter_test.cc) +target_link_libraries(header_formatter_test + metadata_lib + rds_json_lib + common_router_header_formatter_lib + common_router_header_parser_lib + http_mocks + upstream_mocks + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) diff --git a/test/common/router/router_ratelimit_test.cc b/test/common/router/router_ratelimit_test.cc index 9b9583092d0d3..20416e2851033 100644 --- a/test/common/router/router_ratelimit_test.cc +++ b/test/common/router/router_ratelimit_test.cc @@ -394,6 +394,7 @@ TEST_F(RateLimitPolicyEntryTest, RemoteAddress) { testing::ContainerEq(descriptors_)); } +#if !defined(WIN32) // Verify no descriptor is emitted if remote is a pipe. TEST_F(RateLimitPolicyEntryTest, PipeAddress) { std::string json = R"EOF( @@ -412,6 +413,7 @@ TEST_F(RateLimitPolicyEntryTest, PipeAddress) { rate_limit_entry_->populateDescriptors(route_, descriptors_, "", header_, pipe_address); EXPECT_TRUE(descriptors_.empty()); } +#endif TEST_F(RateLimitPolicyEntryTest, SourceService) { std::string json = R"EOF( diff --git a/test/common/singleton/CMakeLists.txt b/test/common/singleton/CMakeLists.txt new file mode 100644 index 0000000000000..6173cd6421bdf --- /dev/null +++ b/test/common/singleton/CMakeLists.txt @@ -0,0 +1,8 @@ +add_executable(manager_impl_test manager_impl_test.cc) +target_link_libraries(manager_impl_test + singleton_manager_lib + test_main + +#dependencies + envoy_all_lib +) \ No newline at end of file diff --git a/test/common/ssl/CMakeLists.txt b/test/common/ssl/CMakeLists.txt new file mode 100644 index 0000000000000..2251344aa1202 --- /dev/null +++ b/test/common/ssl/CMakeLists.txt @@ -0,0 +1,140 @@ +add_executable(ssl_socket_test ssl_socket_test.cc) +target_link_libraries(ssl_socket_test + buffer_lib + dispatcher_lib + json_loader_lib + listen_socket_lib + utility_lib + context_config_lib + context_lib + common_ssl_ssl_socket_lib + stats_lib + buffer_mocks + network_mocks + runtime_mocks + server_mocks + stats_mocks + environment_lib + network_utility_lib + test_main + +#dependencies + logger_lib + config_utility_lib + utility_lib_protobuf + json_loader_lib + config_schemas_lib + filesystem_lib + os_sys_calls_impl + thread_lib + buffer_lib + logger_lib + libevent_lib + watcher_lib + connection_lib + dns_lib + listener_lib + connection_lib_ssl + address_lib + listen_socket_lib + context_lib + hex_lib + common_ssl_ssl_socket_lib + filter_manager_lib + watermark_buffer_lib + stats_lib + version_lib + stats_mocks + + cares.lib + fmt.lib + event.lib + event_core.lib + event_extra.lib + ws2_32.lib + xxhash.lib + + crypto.lib + decrepit.lib + ssl.lib +) + +target_link_libraries(ssl_socket_test + debug gtestd.lib +) + +target_link_libraries(ssl_socket_test + optimized gtest.lib +) + +file(COPY test_data DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +file(COPY gen_unittest_certs.bat DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + +add_executable(context_impl_test context_impl_test.cc) +target_link_libraries(context_impl_test + json_loader_lib + context_config_lib + context_lib + stats_lib + runtime_mocks + environment_lib + test_main + +#dependencies + network_utility_lib + server_mocks + stats_mocks + buffer_mocks + network_mocks + common_ssl_ssl_socket_lib + listen_socket_lib + utility_lib + dispatcher_lib + buffer_lib + logger_lib + config_utility_lib + utility_lib_protobuf + json_loader_lib + config_schemas_lib + filesystem_lib + os_sys_calls_impl + thread_lib + buffer_lib + logger_lib + libevent_lib + watcher_lib + connection_lib + dns_lib + listener_lib + connection_lib_ssl + address_lib + listen_socket_lib + context_lib + hex_lib + common_ssl_ssl_socket_lib + filter_manager_lib + watermark_buffer_lib + stats_lib + version_lib + stats_mocks + + cares.lib + fmt.lib + event.lib + event_core.lib + event_extra.lib + ws2_32.lib + xxhash.lib + + crypto.lib + decrepit.lib + ssl.lib +) + +target_link_libraries(context_impl_test + debug gtestd.lib +) + +target_link_libraries(context_impl_test + optimized gtest.lib +) diff --git a/test/common/ssl/gen_unittest_certs.bat b/test/common/ssl/gen_unittest_certs.bat new file mode 100644 index 0000000000000..f2cf9db26ae85 --- /dev/null +++ b/test/common/ssl/gen_unittest_certs.bat @@ -0,0 +1,51 @@ +REM Create a test certificate with a 15-day expiration for SSL tests. +SETLOCAL +set PATH=C:/OpenSSL-Win32/bin;%PATH% +set TEST_CERT_DIR=%TEST_TMPDIR% + +mkdir "%TEST_CERT_DIR%" + +set OPENSSL_CONF=%TEST_CERT_DIR%/openssl.cnf +( +echo [ req ] +echo default_bits = 2048 +echo distinguished_name = req_distinguished_name + +echo [ req_distinguished_name ] +echo countryName = Country Name ^(2 letter code^) +echo countryName_default = AU +echo countryName_min = 2 +echo countryName_max = 2 + +echo stateOrProvinceName = State or Province Name ^(full name^) +echo stateOrProvinceName_default = Some-State + +echo localityName = Locality Name ^(eg, city^) + +echo 0.organizationName = Organization Name ^(eg, company^) +echo 0.organizationName_default = Internet Widgits Pty Ltd + +echo organizationalUnitName = Organizational Unit Name ^(eg, section^) + +echo commonName = Common Name ^(e.g. server FQDN or YOUR name^) +echo commonName_max = 64 + +echo emailAddress = Email Address +echo emailAddress_max = 64 +)>"%OPENSSL_CONF%" + +openssl genrsa -out "%TEST_CERT_DIR%/unittestkey.pem" 1024 + +set country=US +set state=California +set locality=San Francisco +set organization=Lyft +set organizationalunit=Test +set commonname=Unit Test CA +set email=unittest@lyft.com + +openssl req -new -key "%TEST_CERT_DIR%/unittestkey.pem" -out "%TEST_CERT_DIR%/unittestcert.csr" ^ + -sha256 -subj "/C=%country%/ST=%state%/L=%locality%/O=%organization%/OU=%organizationalunit%/CN=%commonname%/emailAddress=%email%" + +openssl x509 -req -days 15 -in "%TEST_CERT_DIR%/unittestcert.csr" -sha256 ^ + -signkey "%TEST_CERT_DIR%/unittestkey.pem" -out "%TEST_CERT_DIR%/unittestcert.pem" diff --git a/test/common/ssl/ssl_certs_test.h b/test/common/ssl/ssl_certs_test.h index 4aee4a34986c1..f109bddff4d2f 100644 --- a/test/common/ssl/ssl_certs_test.h +++ b/test/common/ssl/ssl_certs_test.h @@ -8,7 +8,11 @@ namespace Envoy { class SslCertsTest : public testing::Test { public: static void SetUpTestCase() { +#if defined(WIN32) + TestEnvironment::exec({TestEnvironment::runfilesPath("test/common/ssl/gen_unittest_certs.bat")}); +#else TestEnvironment::exec({TestEnvironment::runfilesPath("test/common/ssl/gen_unittest_certs.sh")}); +#endif } }; } // namespace Envoy diff --git a/test/common/thread_local/CMakeLists.txt b/test/common/thread_local/CMakeLists.txt new file mode 100644 index 0000000000000..a6edb139c1b49 --- /dev/null +++ b/test/common/thread_local/CMakeLists.txt @@ -0,0 +1,10 @@ +add_executable(thread_local_impl_test thread_local_impl_test.cc) +target_link_libraries(thread_local_impl_test + dispatcher_lib + thread_local_lib + event_mocks + test_main + +#dependencies + envoy_all_lib +) \ No newline at end of file diff --git a/test/common/tracing/CMakeLists.txt b/test/common/tracing/CMakeLists.txt new file mode 100644 index 0000000000000..c752737a7316b --- /dev/null +++ b/test/common/tracing/CMakeLists.txt @@ -0,0 +1,24 @@ +add_executable(http_tracer_impl_test http_tracer_impl_test.cc) +target_link_libraries(http_tracer_impl_test + base64_lib + header_map_lib + message_lib + runtime_lib + uuid_util_lib + http_tracer_lib + http_mocks + local_info_mocks + runtime_mocks + stats_mocks + thread_local_mocks + tracing_mocks + upstream_mocks + test_common_utility_lib + + test_main + +#dependencies + envoy_all_lib +) + +add_subdirectory(zipkin) \ No newline at end of file diff --git a/test/common/tracing/zipkin/CMakeLists.txt b/test/common/tracing/zipkin/CMakeLists.txt new file mode 100644 index 0000000000000..588398aa521c6 --- /dev/null +++ b/test/common/tracing/zipkin/CMakeLists.txt @@ -0,0 +1,32 @@ +add_executable(zipkin_test +span_buffer_test.cc +span_context_test.cc +tracer_test.cc +util_test.cc +zipkin_core_types_test.cc +zipkin_tracer_impl_test.cc +) + +target_link_libraries(zipkin_test + hex_lib + utility_lib + conn_manager_lib + address_lib + network_utility_lib + runtime_lib + zipkin_lib + test_mocks_common_lib + http_mocks + local_info_mocks + runtime_mocks + stats_mocks + thread_local_mocks + tracing_mocks + upstream_mocks + test_common_utility_lib + + test_main + +#dependencies + envoy_all_lib +) diff --git a/test/common/upstream/CMakeLists.txt b/test/common/upstream/CMakeLists.txt new file mode 100644 index 0000000000000..13108d8d1b527 --- /dev/null +++ b/test/common/upstream/CMakeLists.txt @@ -0,0 +1,228 @@ +#include(GoogleTest) + +add_library(upstream_utility_lib INTERFACE) +target_link_libraries(upstream_utility_lib INTERFACE + json_loader_lib + cds_json_lib + network_utility_lib + upstream_lib +) + +target_link_libraries(upstream_utility_lib INTERFACE + debug gtestd.lib +) + +target_link_libraries(upstream_utility_lib INTERFACE + optimized gtest.lib +) + +add_executable(cds_api_impl_test cds_api_impl_test.cc) +target_link_libraries(cds_api_impl_test + config_utility_lib + message_lib + json_loader_lib + cds_api_lib + local_info_mocks + upstream_mocks + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) + +add_executable(cluster_manager_impl_test cluster_manager_impl_test.cc) +target_link_libraries(cluster_manager_impl_test + access_log_mocks + http_mocks + local_info_mocks + network_mocks + runtime_mocks + thread_local_mocks + upstream_mocks + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) + +add_executable(eds_test eds_test.cc) +target_link_libraries(eds_test + upstream_utility_lib + local_info_mocks + runtime_mocks + ssl_mocks + thread_local_mocks + upstream_mocks + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) + +add_executable(health_checker_impl_test health_checker_impl_test.cc) +target_link_libraries(health_checker_impl_test + upstream_utility_lib + network_mocks + redis_mocks + runtime_mocks + upstream_mocks + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) + +add_executable(host_utility_test host_utility_test.cc) +target_link_libraries(host_utility_test + upstream_utility_lib + upstream_mocks + test_main + +#dependencies + envoy_all_lib +) + +add_executable(load_balancer_impl_test load_balancer_impl_test.cc) +target_link_libraries(load_balancer_impl_test + upstream_utility_lib + runtime_mocks + upstream_mocks + test_main + +#dependencies + envoy_all_lib +) + +add_executable(load_balancer_simulation_test load_balancer_simulation_test.cc) +target_link_libraries(load_balancer_simulation_test + upstream_utility_lib + runtime_mocks + upstream_mocks + test_main + +#dependencies + envoy_all_lib +) + +add_executable(load_stats_reporter_test load_stats_reporter_test.cc) +target_link_libraries(load_stats_reporter_test + upstream_utility_lib + event_mocks + grpc_mocks + upstream_mocks + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) + +add_executable(logical_dns_cluster_test logical_dns_cluster_test.cc) +target_link_libraries(logical_dns_cluster_test + upstream_utility_lib + test_mocks_common_lib + network_mocks + runtime_mocks + ssl_mocks + thread_local_mocks + upstream_mocks + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) + +add_executable(original_dst_cluster_test original_dst_cluster_test.cc) +target_link_libraries(original_dst_cluster_test + upstream_utility_lib + test_mocks_common_lib + network_mocks + runtime_mocks + ssl_mocks + upstream_mocks + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) + +add_executable(outlier_detection_impl_test outlier_detection_impl_test.cc) +target_link_libraries(outlier_detection_impl_test + upstream_utility_lib + access_log_mocks + event_mocks + runtime_mocks + upstream_mocks + test_main + +#dependencies + envoy_all_lib +) + +add_executable(resource_manager_impl_test resource_manager_impl_test.cc) +target_link_libraries(resource_manager_impl_test + runtime_mocks + test_main + +#dependencies + envoy_all_lib +) + +add_executable(ring_hash_lb_test ring_hash_lb_test.cc) +target_link_libraries(ring_hash_lb_test + upstream_utility_lib + runtime_mocks + upstream_mocks + test_main + +#dependencies + envoy_all_lib +) + +file(COPY test_data DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +add_executable(sds_test sds_test.cc) +target_link_libraries(sds_test + upstream_utility_lib + local_info_mocks + runtime_mocks + ssl_mocks + upstream_mocks + environment_lib + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) + +add_executable(subset_lb_test subset_lb_test.cc) +target_link_libraries(subset_lb_test + upstream_utility_lib + runtime_mocks + upstream_mocks + test_main + +#dependencies + envoy_all_lib +) + +add_executable(upstream_impl_test upstream_impl_test.cc) +target_link_libraries(upstream_impl_test + upstream_utility_lib + test_mocks_common_lib + network_mocks + runtime_mocks + ssl_mocks + upstream_mocks + test_common_utility_lib + test_main + +#dependencies + envoy_all_lib +) \ No newline at end of file diff --git a/test/common/upstream/health_checker_impl_test.cc b/test/common/upstream/health_checker_impl_test.cc index 255511804ea49..75889761dea5c 100644 --- a/test/common/upstream/health_checker_impl_test.cc +++ b/test/common/upstream/health_checker_impl_test.cc @@ -59,6 +59,7 @@ envoy::api::v2::HealthCheck createGrpcHealthCheckConfig() { return health_check; } +#if !defined(WIN32) TEST(HealthCheckerFactoryTest, createRedis) { std::string json = R"EOF( { @@ -79,6 +80,7 @@ TEST(HealthCheckerFactoryTest, createRedis) { runtime, random, dispatcher) .get())); } +#endif // TODO(htuch): This provides coverage on MissingFieldException and missing health check type // handling for HealthCheck construction, but should eventually be subsumed by whatever we do for @@ -1291,6 +1293,7 @@ TEST_F(TcpHealthCheckerImplTest, PassiveFailureCrossThreadRemoveClusterRace) { EXPECT_EQ(0UL, cluster_->info_->stats_store_.counter("health_check.passive_failure").value()); } +#if !defined(WIN32) class RedisHealthCheckerImplTest : public testing::Test, public Redis::ConnPool::ClientFactory { public: RedisHealthCheckerImplTest() : cluster_(new NiceMock()) {} @@ -1493,6 +1496,7 @@ TEST_F(RedisHealthCheckerImplTest, AllDontReuseConnection) { EXPECT_EQ(3UL, cluster_->info_->stats_store_.counter("health_check.failure").value()); EXPECT_EQ(2UL, cluster_->info_->stats_store_.counter("health_check.network_failure").value()); } +#endif class TestGrpcHealthCheckerImpl : public GrpcHealthCheckerImpl { public: diff --git a/test/common/upstream/original_dst_cluster_test.cc b/test/common/upstream/original_dst_cluster_test.cc index f676de9b640ea..709ccbe8a72bb 100644 --- a/test/common/upstream/original_dst_cluster_test.cc +++ b/test/common/upstream/original_dst_cluster_test.cc @@ -164,6 +164,7 @@ TEST_F(OriginalDstClusterTest, NoContext) { EXPECT_EQ(host, nullptr); } +#if !defined(WIN32) // No host for non-IP address { NiceMock connection; @@ -176,6 +177,8 @@ TEST_F(OriginalDstClusterTest, NoContext) { HostConstSharedPtr host = lb.chooseHost(&lb_context); EXPECT_EQ(host, nullptr); } +#endif + } TEST_F(OriginalDstClusterTest, Membership) { diff --git a/test/integration/CMakeLists.txt b/test/integration/CMakeLists.txt new file mode 100644 index 0000000000000..2c056ebe788e5 --- /dev/null +++ b/test/integration/CMakeLists.txt @@ -0,0 +1,20 @@ +add_library(integration_lib autonomous_upstream.cc + fake_upstream.cc + integration.cc + server.cc + ssl_utility.cc + utility.cc +) + +target_link_libraries(integration_lib +#dependencies + envoy_all_lib +) + +target_link_libraries(integration_lib + debug gtestd.lib +) + +target_link_libraries(integration_lib + optimized gtest.lib +) \ No newline at end of file diff --git a/test/integration/fake_upstream.cc b/test/integration/fake_upstream.cc index 5b76d1d4d0cdf..cb6b4b55d5d6b 100644 --- a/test/integration/fake_upstream.cc +++ b/test/integration/fake_upstream.cc @@ -229,11 +229,14 @@ FakeStreamPtr FakeHttpConnection::waitForNewStream(Event::Dispatcher& client_dis return stream; } +// UdsListenSocket not present on windows. +#if !defined(WIN32) FakeUpstream::FakeUpstream(const std::string& uds_path, FakeHttpConnection::Type type) : FakeUpstream(nullptr, Network::ListenSocketPtr{new Network::UdsListenSocket(uds_path)}, type) { ENVOY_LOG(info, "starting fake server on unix domain socket {}", uds_path); } +#endif static Network::ListenSocketPtr makeTcpListenSocket(uint32_t port, Network::Address::IpVersion version) { diff --git a/test/integration/integration.cc b/test/integration/integration.cc index 950091cf29038..b55252a84e6a7 100644 --- a/test/integration/integration.cc +++ b/test/integration/integration.cc @@ -76,8 +76,8 @@ void IntegrationStreamDecoder::decodeHeaders(Http::HeaderMapPtr&& headers, bool void IntegrationStreamDecoder::decodeData(Buffer::Instance& data, bool end_stream) { saw_end_stream_ = end_stream; uint64_t num_slices = data.getRawSlices(nullptr, 0); - Buffer::RawSlice slices[num_slices]; - data.getRawSlices(slices, num_slices); + std::vector slices(num_slices); + data.getRawSlices(&slices[0], num_slices); for (Buffer::RawSlice& slice : slices) { body_.append(static_cast(slice.mem_), slice.len_); } diff --git a/test/main.cc b/test/main.cc index cc00c32f7332b..05942120ad410 100644 --- a/test/main.cc +++ b/test/main.cc @@ -14,11 +14,28 @@ const char* __asan_default_options() { // The main entry point (and the rest of this file) should have no logic in it, // this allows overriding by site specific versions of main.cc. int main(int argc, char** argv) { +#if defined(WIN32) + WORD wVersionRequested; + WSADATA wsaData; + int err; + + /* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */ + wVersionRequested = MAKEWORD(2, 2); + + err = WSAStartup(wVersionRequested, &wsaData); + if (err != 0) { + /* Tell the user that we could not find a usable */ + /* Winsock DLL. */ + printf("WSAStartup failed with error: %d\n", err); + return 1; + } +#endif #ifdef ENVOY_HANDLE_SIGNALS // Enabled by default. Control with "bazel --define=signal_trace=disabled" Envoy::SignalAction handle_sigs; #endif +#if !defined(WIN32) ::setenv("TEST_RUNDIR", (Envoy::TestEnvironment::getCheckedEnvVar("TEST_SRCDIR") + "/" + Envoy::TestEnvironment::getCheckedEnvVar("TEST_WORKSPACE")) @@ -32,5 +49,16 @@ int main(int argc, char** argv) { // v4 and v6 addresses is desired. This feature is in progress and will be rolled out to all tests // in upcoming PRs. ::setenv("ENVOY_IP_TEST_VERSIONS", "all", 0); +#else + _putenv(("TEST_RUNDIR=" + Envoy::TestEnvironment::getCheckedEnvVar("TEST_SRCDIR") + + "/" + + Envoy::TestEnvironment::getCheckedEnvVar("TEST_WORKSPACE")) + .c_str()); + if (!getenv("ENVOY_IP_TEST_VERSIONS")) + { + _putenv("ENVOY_IP_TEST_VERSIONS=all"); + } +#endif + return Envoy::TestRunner::RunTests(argc, argv); } diff --git a/test/mocks/CMakeLists.txt b/test/mocks/CMakeLists.txt new file mode 100644 index 0000000000000..1d1b12b0a79b0 --- /dev/null +++ b/test/mocks/CMakeLists.txt @@ -0,0 +1,25 @@ +add_library(test_mocks_common_lib common.cc) + +add_subdirectory(access_log) +add_subdirectory(api) +add_subdirectory(buffer) +add_subdirectory(config) +add_subdirectory(event) +add_subdirectory(filesystem) +add_subdirectory(grpc) +add_subdirectory(http) +add_subdirectory(init) +add_subdirectory(local_info) +add_subdirectory(network) +add_subdirectory(ratelimit) +add_subdirectory(redis) +add_subdirectory(request_info) +add_subdirectory(router) +add_subdirectory(runtime) +add_subdirectory(server) +add_subdirectory(ssl) +add_subdirectory(stats) +add_subdirectory(thread_local) +add_subdirectory(tracing) +add_subdirectory(upstream) + diff --git a/test/mocks/access_log/CMakeLists.txt b/test/mocks/access_log/CMakeLists.txt new file mode 100644 index 0000000000000..dbd0d94f3d20c --- /dev/null +++ b/test/mocks/access_log/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(access_log_mocks mocks.cc) + +target_link_libraries(access_log_mocks + filesystem_mocks +) \ No newline at end of file diff --git a/test/mocks/api/CMakeLists.txt b/test/mocks/api/CMakeLists.txt new file mode 100644 index 0000000000000..47965fd0524f5 --- /dev/null +++ b/test/mocks/api/CMakeLists.txt @@ -0,0 +1,6 @@ +add_library(api_mocks mocks.cc) + +target_link_libraries(api_mocks + os_sys_calls_impl + filesystem_mocks +) \ No newline at end of file diff --git a/test/mocks/api/mocks.h b/test/mocks/api/mocks.h index 46dcacb9c4303..5d12f3abc6ffe 100644 --- a/test/mocks/api/mocks.h +++ b/test/mocks/api/mocks.h @@ -48,10 +48,14 @@ class MockOsSysCalls : public OsSysCallsImpl { MOCK_METHOD1(close, int(int)); MOCK_METHOD3(open_, int(const std::string& full_path, int flags, int mode)); MOCK_METHOD3(write_, ssize_t(int, const void*, size_t)); +#if !defined(WIN32) MOCK_METHOD3(shmOpen, int(const char*, int, mode_t)); MOCK_METHOD1(shmUnlink, int(const char*)); +#endif MOCK_METHOD2(ftruncate, int(int fd, off_t length)); +#if !defined(WIN32) MOCK_METHOD6(mmap, void*(void* addr, size_t length, int prot, int flags, int fd, off_t offset)); +#endif MOCK_METHOD2(stat, int(const char* name, struct stat* stat)); size_t num_writes_; diff --git a/test/mocks/buffer/CMakeLists.txt b/test/mocks/buffer/CMakeLists.txt new file mode 100644 index 0000000000000..ecae6682d8660 --- /dev/null +++ b/test/mocks/buffer/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(buffer_mocks mocks.cc) + +target_link_libraries(buffer_mocks + test_common_utility_lib +) \ No newline at end of file diff --git a/test/mocks/config/CMakeLists.txt b/test/mocks/config/CMakeLists.txt new file mode 100644 index 0000000000000..bc1f4ceccdcfc --- /dev/null +++ b/test/mocks/config/CMakeLists.txt @@ -0,0 +1 @@ +add_library(config_mocks mocks.cc) \ No newline at end of file diff --git a/test/mocks/event/CMakeLists.txt b/test/mocks/event/CMakeLists.txt new file mode 100644 index 0000000000000..01402f9f424f1 --- /dev/null +++ b/test/mocks/event/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(event_mocks mocks.cc) + +target_link_libraries(event_mocks + buffer_mocks +) \ No newline at end of file diff --git a/test/mocks/filesystem/CMakeLists.txt b/test/mocks/filesystem/CMakeLists.txt new file mode 100644 index 0000000000000..edac967261082 --- /dev/null +++ b/test/mocks/filesystem/CMakeLists.txt @@ -0,0 +1,13 @@ +add_library(filesystem_mocks mocks.cc) + +target_link_libraries(filesystem_mocks + thread_lib +) + +target_link_libraries(filesystem_mocks + debug gmockd.lib +) + +target_link_libraries(filesystem_mocks + optimized gmock.lib +) diff --git a/test/mocks/grpc/CMakeLists.txt b/test/mocks/grpc/CMakeLists.txt new file mode 100644 index 0000000000000..04edb4a67439c --- /dev/null +++ b/test/mocks/grpc/CMakeLists.txt @@ -0,0 +1 @@ +add_library(grpc_mocks mocks.cc) diff --git a/test/mocks/http/CMakeLists.txt b/test/mocks/http/CMakeLists.txt new file mode 100644 index 0000000000000..dc552b6f81a9f --- /dev/null +++ b/test/mocks/http/CMakeLists.txt @@ -0,0 +1,10 @@ +add_library(http_mocks mocks.cc) + +target_link_libraries(http_mocks + event_mocks + request_info_mocks + router_mocks + tracing_mocks + host_mocks + printers_lib +) \ No newline at end of file diff --git a/test/mocks/init/CMakeLists.txt b/test/mocks/init/CMakeLists.txt new file mode 100644 index 0000000000000..cef6bb2d01e89 --- /dev/null +++ b/test/mocks/init/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(init_mocks mocks.cc) + +target_link_libraries(init_mocks + test_mocks_common_lib +) \ No newline at end of file diff --git a/test/mocks/local_info/CMakeLists.txt b/test/mocks/local_info/CMakeLists.txt new file mode 100644 index 0000000000000..97fd469991e4a --- /dev/null +++ b/test/mocks/local_info/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(local_info_mocks mocks.cc) + +target_link_libraries(local_info_mocks + address_lib +) \ No newline at end of file diff --git a/test/mocks/network/CMakeLists.txt b/test/mocks/network/CMakeLists.txt new file mode 100644 index 0000000000000..7c6ddacb33c68 --- /dev/null +++ b/test/mocks/network/CMakeLists.txt @@ -0,0 +1,8 @@ +add_library(network_mocks mocks.cc) + +target_link_libraries(network_mocks + address_lib + network_utility_lib + event_mocks + ws2_32.lib +) \ No newline at end of file diff --git a/test/mocks/network/mocks.h b/test/mocks/network/mocks.h index e6e178f8919b2..e1b96b93d2fa0 100644 --- a/test/mocks/network/mocks.h +++ b/test/mocks/network/mocks.h @@ -9,6 +9,8 @@ #include "envoy/network/filter.h" #include "envoy/network/transport_socket.h" +#include "envoy/common/socket_fd.h" + #include "common/stats/stats_impl.h" #include "test/mocks/event/mocks.h" @@ -255,7 +257,11 @@ class MockListenSocket : public ListenSocket { ~MockListenSocket(); MOCK_CONST_METHOD0(localAddress, Address::InstanceConstSharedPtr()); +#if defined(WIN32) + MOCK_METHOD0(fd, SOCKET_FD_TYPE()); +#else MOCK_METHOD0(fd, int()); +#endif MOCK_METHOD0(close, void()); Address::InstanceConstSharedPtr local_address_; @@ -329,10 +335,11 @@ class MockResolvedAddress : public Address::Instance { return asString() == other.asString(); } - MOCK_CONST_METHOD1(bind, int(int)); - MOCK_CONST_METHOD1(connect, int(int)); + MOCK_CONST_METHOD1(bind, int(SOCKET_FD_TYPE)); + MOCK_CONST_METHOD1(connect, int(SOCKET_FD_TYPE)); MOCK_CONST_METHOD0(ip, Address::Ip*()); - MOCK_CONST_METHOD1(socket, int(Address::SocketType)); + MOCK_CONST_METHOD1(socket, SOCKET_FD_TYPE(Address::SocketType)); + MOCK_CONST_METHOD0(type, Address::Type()); const std::string& asString() const override { return physical_; } diff --git a/test/mocks/ratelimit/CMakeLists.txt b/test/mocks/ratelimit/CMakeLists.txt new file mode 100644 index 0000000000000..dc037009768f4 --- /dev/null +++ b/test/mocks/ratelimit/CMakeLists.txt @@ -0,0 +1 @@ +add_library(ratelimit_mocks mocks.cc) \ No newline at end of file diff --git a/test/mocks/redis/CMakeLists.txt b/test/mocks/redis/CMakeLists.txt new file mode 100644 index 0000000000000..a10825e1a6674 --- /dev/null +++ b/test/mocks/redis/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(redis_mocks mocks.cc) + +target_link_libraries(redis_mocks + codec_lib +) \ No newline at end of file diff --git a/test/mocks/request_info/CMakeLists.txt b/test/mocks/request_info/CMakeLists.txt new file mode 100644 index 0000000000000..92c0e8728441f --- /dev/null +++ b/test/mocks/request_info/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(request_info_mocks mocks.cc) + +target_link_libraries(request_info_mocks + host_mocks +) \ No newline at end of file diff --git a/test/mocks/router/CMakeLists.txt b/test/mocks/router/CMakeLists.txt new file mode 100644 index 0000000000000..e89e8961c82b7 --- /dev/null +++ b/test/mocks/router/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(router_mocks mocks.cc) + +target_link_libraries(router_mocks + test_mocks_common_lib +) \ No newline at end of file diff --git a/test/mocks/runtime/CMakeLists.txt b/test/mocks/runtime/CMakeLists.txt new file mode 100644 index 0000000000000..32cae3b45685a --- /dev/null +++ b/test/mocks/runtime/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(runtime_mocks mocks.cc) + +target_link_libraries(runtime_mocks + test_mocks_common_lib +) \ No newline at end of file diff --git a/test/mocks/server/CMakeLists.txt b/test/mocks/server/CMakeLists.txt new file mode 100644 index 0000000000000..e0c806ed136ad --- /dev/null +++ b/test/mocks/server/CMakeLists.txt @@ -0,0 +1,18 @@ +add_library(server_mocks mocks.cc) + +target_link_libraries(server_mocks + singleton_manager_lib + context_lib + stats_lib + access_log_mocks + api_mocks + http_mocks + init_mocks + local_info_mocks + network_mocks + router_mocks + runtime_mocks + thread_local_mocks + tracing_mocks + upstream_mocks +) \ No newline at end of file diff --git a/test/mocks/ssl/CMakeLists.txt b/test/mocks/ssl/CMakeLists.txt new file mode 100644 index 0000000000000..845100d918ab6 --- /dev/null +++ b/test/mocks/ssl/CMakeLists.txt @@ -0,0 +1 @@ +add_library(ssl_mocks mocks.cc) \ No newline at end of file diff --git a/test/mocks/stats/CMakeLists.txt b/test/mocks/stats/CMakeLists.txt new file mode 100644 index 0000000000000..7a46942371fe3 --- /dev/null +++ b/test/mocks/stats/CMakeLists.txt @@ -0,0 +1,12 @@ +add_library(stats_mocks mocks.cc) + +target_link_libraries(stats_mocks + test_mocks_common_lib +) +target_link_libraries(stats_mocks + debug gmockd.lib +) + +target_link_libraries(stats_mocks + optimized gmock.lib +) diff --git a/test/mocks/thread_local/CMakeLists.txt b/test/mocks/thread_local/CMakeLists.txt new file mode 100644 index 0000000000000..18afd0601afbe --- /dev/null +++ b/test/mocks/thread_local/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(thread_local_mocks mocks.cc) + +target_link_libraries(thread_local_mocks + event_mocks +) \ No newline at end of file diff --git a/test/mocks/tracing/CMakeLists.txt b/test/mocks/tracing/CMakeLists.txt new file mode 100644 index 0000000000000..244f5beb3a30a --- /dev/null +++ b/test/mocks/tracing/CMakeLists.txt @@ -0,0 +1 @@ +add_library(tracing_mocks mocks.cc) \ No newline at end of file diff --git a/test/mocks/upstream/CMakeLists.txt b/test/mocks/upstream/CMakeLists.txt new file mode 100644 index 0000000000000..d653bf4c3da96 --- /dev/null +++ b/test/mocks/upstream/CMakeLists.txt @@ -0,0 +1,59 @@ +add_library(cluster_info_mocks cluster_info.cc + $ +) + + +target_link_libraries(cluster_info_mocks + upstream_lib + runtime_mocks + stats_mocks + original_dst_cluster_lib + logical_dns_cluster_lib + health_checker_lib + http_utility_lib + common_lib + metadata_lib + outlier_detection_lib + hex_lib + message_lib + thread_lib + common_network_raw_buffer_socket_lib + zero_copy_input_stream_lib + codec_client_lib + host_utility_lib + eds_lib + rest_api_fetcher_lib + grpc_mux_impl_lib + config_utility_lib + sds_subscription_lib + http2_codec_lib + http1_codec_lib + buffer_lib + watermark_buffer_lib + utility_lib + to_lower_table_lib + codes_lib + header_map_lib + nghttp2.lib + http_parser.lib + config_schemas_lib + resolver_impl_lib +) + +add_library(host_mocks host.cc) + +target_link_libraries(host_mocks + cluster_info_mocks + network_utility_lib + stats_lib +) + +add_library(upstream_mocks mocks.cc) + +target_link_libraries(upstream_mocks + config_mocks + grpc_mocks + http_mocks + runtime_mocks + stats_mocks +) diff --git a/test/proto/CMakeLists.txt b/test/proto/CMakeLists.txt new file mode 100644 index 0000000000000..763d386399d5c --- /dev/null +++ b/test/proto/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(bookstore_lib bookstore.pb.cc) +add_library(helloworld_lib helloworld.pb.cc) diff --git a/test/proto/buildprotos.bat b/test/proto/buildprotos.bat new file mode 100644 index 0000000000000..b0a4574dd5636 --- /dev/null +++ b/test/proto/buildprotos.bat @@ -0,0 +1,18 @@ +for /R %%i in (*.proto) do ( + %PROTOC% %PROTOC_FLAGS% --proto_path=%cd% --proto_path=%ENVOY_DEPENDENCY_ROOT%\googleapis --cpp_out=%cd% "%%i" +) + +mkdir debug +cl /nologo /c /EHsc /I %PROTOC_OUTPUT%\googleapis /D_DEBUG %cd%\bookstore.pb.cc /Fo:%cd%\debug\bookstore.pb.obj +lib /nologo /out:%cd%\debug\bookstore.lib %cd%\debug\bookstore.pb.obj + +cl /nologo /c /EHsc /I %PROTOC_OUTPUT%\googleapis /D_DEBUG %cd%\helloworld.pb.cc /Fo:%cd%\debug\helloworld.pb.obj +lib /nologo /out:%cd%\debug\helloworld.lib %cd%\debug\helloworld.pb.obj + +mkdir release + +cl /nologo /c /EHsc /I %PROTOC_OUTPUT%\googleapis /DNDEBUG /Osx %cd%\bookstore.pb.cc /Fo:%cd%\release\bookstore.pb.obj +lib /nologo /out:%cd%\release\bookstore.lib %cd%\release\bookstore.pb.obj + +cl /nologo /c /EHsc /I %PROTOC_OUTPUT%\googleapis /DNDEBUG /Osx %cd%\helloworld.pb.cc /Fo:%cd%\release\helloworld.pb.obj +lib /nologo /out:%cd%\release\helloworld.lib %cd%\release\helloworld.pb.obj \ No newline at end of file diff --git a/test/test_common/CMakeLists.txt b/test/test_common/CMakeLists.txt new file mode 100644 index 0000000000000..90322546c9c9a --- /dev/null +++ b/test/test_common/CMakeLists.txt @@ -0,0 +1,260 @@ +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +add_library(environment_lib environment.cc) + +target_link_libraries(environment_lib PUBLIC + network_utility_lib + utility_lib + options_lib + test_network_utility_lib + ws2_32.lib +) + +target_link_libraries(environment_lib PUBLIC + debug absl_based.lib + debug absl_stringsd.lib +) + +target_link_libraries(environment_lib PUBLIC + optimized absl_base.lib + optimized absl_strings.lib +) + +add_library(test_network_utility_lib network_utility.cc) +target_link_libraries(test_network_utility_lib PUBLIC + address_lib + common_network_raw_buffer_socket_lib + utility_lib + runtime_lib +) + +add_library(printers_lib printers.cc) +target_link_libraries(printers_lib PUBLIC + buffer_lib + header_map_lib + codec_lib +) + +add_library(test_common_utility_lib utility.cc) +target_link_libraries(test_common_utility_lib PUBLIC + utility_lib + bootstrap_json_lib + header_map_lib + json_loader_lib + network_utility_lib + address_lib + utility_lib_protobuf + well_known_names_lib + tls_context_json_lib + filesystem_lib + os_sys_calls_impl + buffer_lib + libevent_lib + thread_lib + cidr_range_lib + protocol_json_lib + + ws2_32.lib + event.lib + event_core.lib + event_extra.lib + xxhash.lib + fmt.lib + gogoproto.lib + googleapis.lib + protoc-gen-validate.lib + health.lib +) +target_link_libraries(test_common_utility_lib PUBLIC + debug libprotobufd.lib + debug libprotocd.lib +) +target_link_libraries(test_common_utility_lib PUBLIC + debug absl_based.lib + debug absl_stringsd.lib + debug libyaml-cppmdd.lib +) +target_link_libraries(test_common_utility_lib PUBLIC + optimized absl_base.lib + optimized absl_strings.lib + optimized libyaml-cppmd.lib +) + +target_link_libraries(test_common_utility_lib PRIVATE + data-plane-api.lib +) + +add_library(envoy_all_lib INTERFACE) +target_link_libraries(envoy_all_lib INTERFACE + envoy_main_common_lib + config_http_zipkin_lib + xxhash.lib + base64_lib + hex_lib + logger_lib + thread_lib + utility_lib + version_lib + to_lower_table_lib + api_lib + buffer_lib + zero_copy_input_stream_lib + dispatcher_lib + dispatched_thread_lib + memory_stats_lib + statsd_lib + guarddog_lib + profiler_lib + codec_lib + logger_lib + thread_local_lib + server_lib_config_validation + utility_lib + configuration_lib + connection_handler_lib + init_manager_lib + lds_api_lib + listener_manager_lib + watchdog_lib + worker_lib + + buffer_filter_lib + config_lib_router + config_utility_lib_router + rds_lib + retry_state_lib + router_lib + router_ratelimit_lib + shadow_writer_lib + async_client_lib + codec_client_lib + codes_lib + conn_manager_lib + date_provider_lib + header_map_lib + message_lib + rest_api_fetcher_lib + user_agent_lib + http_utility_lib + filter_utility_lib + admin_lib + common_lib + http_tracer_lib + zipkin_lib + access_log_formatter_lib + http2_codec_lib + http2_conn_pool_lib + codec_client_lib + http1_codec_lib + http1_conn_pool_lib + ratelimit_lib + cds_api_lib + cluster_manager_lib + health_checker_lib + host_utility_lib + load_balancer_lib + logical_dns_cluster_lib + outlier_detection_lib + ring_hash_lb_lib + eds_lib + sds_subscription_lib + upstream_lib + protocol_json_lib + tls_context_json_lib + api_lib_config_validation + async_client_lib_config_validation + cluster_manager_lib_config_validation + dispatcher_lib_config_validation + dns_lib_config_validation + server_lib_config_validation + watcher_lib + filesystem_lib + config_schemas_lib + json_loader_lib + metadata_lib + config_utility_lib + shadow_writer_lib + router_ratelimit_lib + router_lib + retry_state_lib + rds_lib + address_lib + runtime_lib + uuid_util_lib + connection_lib_ssl + context_config_lib + context_lib + watermark_buffer_lib + buffer_lib + zero_copy_input_stream_lib + cidr_range_lib + connection_lib + dns_lib + filter_manager_lib + listen_socket_lib + filter_json_lib + well_known_names_lib + utility_lib_protobuf + singleton_manager_lib + listener_lib + access_log_lib + common_html_utility + common_request_info_utility + common_grpc_async_client_manager_lib + common_ssl_ssl_socket_lib + common_network_raw_buffer_socket_lib + fault_filter_lib + grpc_web_filter_lib + http1_bridge_filter_lib + http_ratelimit_lib + ip_tagging_filter_lib + ratelimit_lib_filter + proxy_protocol_lib + health.lib + cares.lib + event.lib + event_core.lib + event_extra.lib + nghttp2.lib + Ws2_32.lib + http_parser.lib + googleapis.lib + Rpcrt4.lib + protoc-gen-validate.lib + gogoproto.lib +) + +target_link_libraries(envoy_all_lib INTERFACE + debug libprotobufd.lib + debug libprotocd.lib + + optimized libprotobuf.lib + optimized libprotoc.lib +) + +target_link_libraries(envoy_all_lib INTERFACE + debug absl_based.lib + debug absl_stringsd.lib +) + +target_link_libraries(envoy_all_lib INTERFACE + optimized absl_base.lib + optimized absl_strings.lib +) + +target_link_libraries(envoy_all_lib INTERFACE + crypto.lib + decrepit.lib + ssl.lib +) + +target_link_libraries(envoy_all_lib INTERFACE + debug libyaml-cppmdd.lib + optimized libyaml-cppmd.lib +) + + +target_link_libraries(envoy_all_lib INTERFACE + data-plane-api.lib +) diff --git a/test/test_common/environment.cc b/test/test_common/environment.cc index f562d127df56a..a49378efb656d 100644 --- a/test/test_common/environment.cc +++ b/test/test_common/environment.cc @@ -1,7 +1,14 @@ #include "test/test_common/environment.h" +#if !defined(WIN32) #include #include +#endif + +#if defined(WIN32) +#include +namespace fs = std::filesystem; +#endif #include #include @@ -31,12 +38,29 @@ std::string getOrCreateUnixDomainSocketDirectory() { if (path != nullptr) { return std::string(path); } +#if defined(WIN32) + char test_udsdir[] = "envoy_test_uds.XXXXXX"; + int size = strlen(test_udsdir) + 1; // terminating NULL + RELEASE_ASSERT(_mktemp_s(test_udsdir, size) == 0); + + std::error_code ec; + auto tmp_dir = fs::temp_directory_path(ec); + RELEASE_ASSERT(!ec); + + fs::path ret_path = tmp_dir; + ret_path /= test_udsdir; + fs::create_directories(ret_path, ec); + RELEASE_ASSERT(!ec); + + return ret_path.string(); +#else // Generate temporary path for Unix Domain Sockets only. This is a workaround // for the sun_path limit on sockaddr_un, since TEST_TMPDIR as generated by // Bazel may be too long. char test_udsdir[] = "/tmp/envoy_test_uds.XXXXXX"; RELEASE_ASSERT(::mkdtemp(test_udsdir) != nullptr); return std::string(test_udsdir); +#endif } // Allow initializeOptions() to remember CLI args for getOptions(). @@ -184,7 +208,14 @@ std::string TestEnvironment::temporaryFileSubstitute(const std::string& path, const std::string extension = StringUtil::endsWith(path, ".yaml") ? ".yaml" : ".json"; const std::string out_json_path = TestEnvironment::temporaryPath(path + ".with.ports" + extension); +#if defined(WIN32) + fs::path out_dir = out_json_path; + std::error_code ec; + fs::create_directories(out_dir.parent_path(), ec); + RELEASE_ASSERT(!ec); +#else RELEASE_ASSERT(::system(("mkdir -p $(dirname " + out_json_path + ")").c_str()) == 0); +#endif { std::ofstream out_json_file(out_json_path); out_json_file << out_json_string; @@ -199,9 +230,15 @@ Json::ObjectSharedPtr TestEnvironment::jsonLoadFromString(const std::string& jso void TestEnvironment::exec(const std::vector& args) { std::stringstream cmd; +#if defined(WIN32) + //TODO: Is setting PYTHONPATH here required on windows? + //fs::path out_dir = args[0]; + //cmd << "set PYTHONPATH=" << out_dir.parent_path() << " && "; +#else // Symlinked args[0] can confuse Python when importing module relative, so we let Python know // where it can find its module relative files. cmd << "PYTHONPATH=$(dirname " << args[0] << ") "; +#endif for (auto& arg : args) { cmd << arg << " "; } @@ -214,8 +251,16 @@ void TestEnvironment::exec(const std::vector& args) { std::string TestEnvironment::writeStringToFileForTest(const std::string& filename, const std::string& contents) { const std::string out_path = TestEnvironment::temporaryPath(filename); +#if !defined(WIN32) RELEASE_ASSERT(::system(("mkdir -p $(dirname " + out_path + ")").c_str()) == 0); unlink(out_path.c_str()); +#else + fs::path out_dir = out_path; + std::error_code ec; + fs::create_directories(out_dir.parent_path(), ec); + RELEASE_ASSERT(!ec); +#endif + { std::ofstream out_file(out_path); RELEASE_ASSERT(!out_file.fail()); diff --git a/test/test_common/network_utility.cc b/test/test_common/network_utility.cc index 32ec06926d9b0..e79d67e394ef8 100644 --- a/test/test_common/network_utility.cc +++ b/test/test_common/network_utility.cc @@ -1,7 +1,11 @@ #include "test/test_common/network_utility.h" +#if defined(WIN32) +typedef unsigned int sa_family_t; +#else #include #include +#endif #include #include @@ -133,10 +137,18 @@ bool supportsIpVersion(const Address::IpVersion version) { } if (0 != addr->bind(fd)) { // Socket bind failed. +#if defined(WIN32) + RELEASE_ASSERT(::closesocket(fd) == 0); +#else RELEASE_ASSERT(::close(fd) == 0); +#endif return false; } +#if defined(WIN32) + RELEASE_ASSERT(::closesocket(fd) == 0); +#else RELEASE_ASSERT(::close(fd) == 0); +#endif return true; } @@ -154,7 +166,11 @@ std::pair bindFreeLoopbackPort(Address::Ip } const int err = errno; if (fd >= 0) { - close(fd); +#if defined(WIN32) + RELEASE_ASSERT(::closesocket(fd) == 0); +#else + RELEASE_ASSERT(::close(fd) == 0); +#endif } std::string msg = fmt::format("{} failed for address {} with error: {} ({})", failing_fn, addr->asString(), strerror(err), err); diff --git a/test/test_common/printers.cc b/test/test_common/printers.cc index 1f361478de6a4..bcb9fc6df446e 100644 --- a/test/test_common/printers.cc +++ b/test/test_common/printers.cc @@ -39,9 +39,11 @@ void PrintTo(const Buffer::OwnedImpl& buffer, std::ostream* os) { } } // namespace Buffer +#if !defined(WIN32) namespace Redis { void PrintTo(const RespValue& value, std::ostream* os) { *os << value.toString(); } void PrintTo(const RespValuePtr& value, std::ostream* os) { *os << value->toString(); } } // namespace Redis +#endif } // namespace Envoy diff --git a/test/test_common/printers.h b/test/test_common/printers.h index 536cc8140333b..14e19a690d9cb 100644 --- a/test/test_common/printers.h +++ b/test/test_common/printers.h @@ -36,6 +36,7 @@ class OwnedImpl; void PrintTo(const OwnedImpl& buffer, std::ostream* os); } // namespace Buffer +#if !defined(WIN32) namespace Redis { /** * Pretty print const RespValue& value @@ -45,4 +46,5 @@ typedef std::unique_ptr RespValuePtr; void PrintTo(const RespValue& value, std::ostream* os); void PrintTo(const RespValuePtr& value, std::ostream* os); } // namespace Redis +#endif } // namespace Envoy diff --git a/test/test_common/utility.cc b/test/test_common/utility.cc index ed6d9c0556b46..9af09fa94ee2b 100644 --- a/test/test_common/utility.cc +++ b/test/test_common/utility.cc @@ -1,7 +1,14 @@ #include "utility.h" +#if !defined(WIN32) #include #include +#else +#include +#include +#include +namespace fs = std::filesystem; +#endif #include #include @@ -53,10 +60,18 @@ bool TestUtility::buffersEqual(const Buffer::Instance& lhs, const Buffer::Instan return false; } +#if !defined(WIN32) Buffer::RawSlice lhs_slices[lhs_num_slices]; lhs.getRawSlices(lhs_slices, lhs_num_slices); Buffer::RawSlice rhs_slices[rhs_num_slices]; rhs.getRawSlices(rhs_slices, rhs_num_slices); +#else + std::vector lhs_slices(lhs_num_slices); + lhs.getRawSlices(lhs_slices.data(), lhs_num_slices); + std::vector rhs_slices(rhs_num_slices); + rhs.getRawSlices(rhs_slices.data(), rhs_num_slices); +#endif + for (size_t i = 0; i < lhs_num_slices; i++) { if (lhs_slices[i].len_ != rhs_slices[i].len_) { return false; @@ -73,8 +88,13 @@ bool TestUtility::buffersEqual(const Buffer::Instance& lhs, const Buffer::Instan std::string TestUtility::bufferToString(const Buffer::Instance& buffer) { std::string output; uint64_t num_slices = buffer.getRawSlices(nullptr, 0); +#if !defined(WIN32) Buffer::RawSlice slices[num_slices]; buffer.getRawSlices(slices, num_slices); +#else + std::vector slices(num_slices); + buffer.getRawSlices(slices.data(), num_slices); +#endif for (Buffer::RawSlice& slice : slices) { output.append(static_cast(slice.mem_), slice.len_); } @@ -122,6 +142,7 @@ TestUtility::makeDnsResponse(const std::list& addresses) { } std::vector TestUtility::listFiles(const std::string& path, bool recursive) { +#if !defined(WIN32) DIR* dir = opendir(path.c_str()); if (!dir) { throw std::runtime_error(fmt::format("Directory not found '{}'", path)); @@ -149,6 +170,14 @@ std::vector TestUtility::listFiles(const std::string& path, bool re closedir(dir); return file_names; +#else + std::vector file_names; + for (auto& p : std::filesystem::recursive_directory_iterator(path)) { + if (p.is_regular_file()) + file_names.push_back(p.path().string()); + } + return file_names; +#endif } envoy::api::v2::Bootstrap TestUtility::parseBootstrapFromJson(const std::string& json_string) { @@ -191,7 +220,11 @@ void ConditionalInitializer::waitReady() { } ScopedFdCloser::ScopedFdCloser(int fd) : fd_(fd) {} +#if defined(WIN32) +ScopedFdCloser::~ScopedFdCloser() { ::closesocket(fd_); } +#else ScopedFdCloser::~ScopedFdCloser() { ::close(fd_); } +#endif namespace Http { diff --git a/test/test_runner.h b/test/test_runner.h index 3a92b0b6c5a4a..17d2d1a267ad6 100644 --- a/test/test_runner.h +++ b/test/test_runner.h @@ -21,7 +21,11 @@ class TestRunner { ::testing::Test::RecordProperty("TemporaryDirectory", TestEnvironment::temporaryDirectory()); ::testing::Test::RecordProperty("RunfilesDirectory", TestEnvironment::runfilesDirectory()); - if (::setenv("TEST_UDSDIR", TestEnvironment::unixDomainSocketDirectory().c_str(), 1) != 0) { +#if defined(WIN32) + if (_putenv(("TEST_UDSDIR=" + TestEnvironment::unixDomainSocketDirectory()).c_str()) != 0) { +#else + if (::setenv("TEST_UDSDIR", TestEnvironment::unixDomainSocketDirectory().c_str(), 1) != 0) {} +#endif ::perror("Failed to set temporary UDS directory."); ::exit(1); }