From 6e5fca3cbe6914090ebe8ca95bde26279363e04b Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Tue, 7 Sep 2021 10:24:10 +0000 Subject: [PATCH 01/54] Fix url 404 not found error Signed-off-by: Chidera Olibie --- .bazelrc | 2 +- library/java/org/chromium/net/impl/CronetUrlRequest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.bazelrc b/.bazelrc index 68d8e61ead..c843db5ce9 100644 --- a/.bazelrc +++ b/.bazelrc @@ -26,7 +26,7 @@ build --incompatible_objc_compile_info_migration build --features=-per_object_debug_info # Suppress deprecated declaration warnings due to extensive transitive noise from protobuf. build --copt -Wno-deprecated-declarations -build --@envoy//bazel:http3=False +# build --@envoy//bazel:http3=False # Default flags for builds targeting iOS # Manual stamping is necessary in order to get versioning information in the iOS diff --git a/library/java/org/chromium/net/impl/CronetUrlRequest.java b/library/java/org/chromium/net/impl/CronetUrlRequest.java index 5ec9ca99e6..d9497ec663 100644 --- a/library/java/org/chromium/net/impl/CronetUrlRequest.java +++ b/library/java/org/chromium/net/impl/CronetUrlRequest.java @@ -549,7 +549,7 @@ private static RequestHeaders buildEnvoyRequestHeaders(String initialMethod, } RequestMethod requestMethod = RequestMethod.valueOf(initialMethod); RequestHeadersBuilder requestHeadersBuilder = new RequestHeadersBuilder( - requestMethod, url.getProtocol(), url.getAuthority(), url.getFile()); + requestMethod, url.getProtocol(), url.getAuthority(), url.getFile().isEmpty() ? "/" : url.getFile() ); boolean hasUserAgent = false; boolean hasContentType = false; for (Map.Entry header : headersList) { From 51bab1c81fa9bece844c4df2351f7370b37bbdf3 Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Tue, 7 Sep 2021 10:35:54 +0000 Subject: [PATCH 02/54] Working version of quicTestServer Signed-off-by: Chidera Olibie --- test/common/integration/BUILD | 66 ++++ test/common/integration/quic_test_server.cc | 126 ++++++++ test/common/integration/quic_test_server.h | 49 +++ .../integration/quic_test_server_interface.cc | 34 ++ .../integration/quic_test_server_interface.h | 18 ++ test/common/jni/BUILD | 36 +++ .../jni/quic_test_server_jni_interface.cc | 36 +++ test/java/org/chromium/net/BUILD | 22 ++ test/java/org/chromium/net/QuicTest.java | 305 ++++++++++++++++++ test/java/org/chromium/net/testing/BUILD | 4 + .../chromium/net/testing/CronetTestUtil.java | 85 +++++ .../net/testing/MockCertVerifier.java | 21 ++ .../chromium/net/testing/QuicTestServer.java | 87 +++++ 13 files changed, 889 insertions(+) create mode 100644 test/common/integration/quic_test_server.cc create mode 100644 test/common/integration/quic_test_server.h create mode 100644 test/common/integration/quic_test_server_interface.cc create mode 100644 test/common/integration/quic_test_server_interface.h create mode 100644 test/common/jni/BUILD create mode 100644 test/common/jni/quic_test_server_jni_interface.cc create mode 100644 test/java/org/chromium/net/QuicTest.java create mode 100644 test/java/org/chromium/net/testing/CronetTestUtil.java create mode 100644 test/java/org/chromium/net/testing/MockCertVerifier.java create mode 100644 test/java/org/chromium/net/testing/QuicTestServer.java diff --git a/test/common/integration/BUILD b/test/common/integration/BUILD index 277e316c0c..ad73258a86 100644 --- a/test/common/integration/BUILD +++ b/test/common/integration/BUILD @@ -1,4 +1,5 @@ load("@envoy//bazel:envoy_build_system.bzl", "envoy_cc_test", "envoy_package") +load("@envoy//bazel:envoy_build_system.bzl", "envoy_cc_test_library", "envoy_package") licenses(["notice"]) # Apache 2 @@ -19,3 +20,68 @@ envoy_cc_test( "@envoy//test/server:utility_lib", ], ) + +# ignore, used this test that the server java file works standalone +envoy_cc_test( + name = "quic_s", + srcs = ["quic_s.cc"], + data = [ + "@envoy//test/config/integration/certs", + ], + repository = "@envoy", + deps = [ + "@envoy//source/common/quic:quic_stat_names_lib", + "@envoy//source/common/quic:active_quic_listener_lib", + "@envoy//source/common/quic:quic_factory_lib", + "@envoy//source/common/stats:isolated_store_lib", + "@envoy//test/config:utility_lib", + "@envoy//test/integration:autonomous_upstream_lib", + "@envoy//test/integration:fake_upstream_lib", + "@envoy//test/test_common:network_utility_lib", + # "@envoy_api//envoy/extensions/transport_sockets/quic/v3:pkg_cc_proto", + ], +) + +# interface libs for jni implementation +envoy_cc_test_library( + name = "quic_test_server_interface_lib", + repository = "@envoy", + deps = [ + ":quic_test_server_interface_lib_no_stamp", + ], +) + +envoy_cc_test_library( + name = "quic_test_server_interface_lib_no_stamp", + srcs = [ + "quic_test_server.cc", + "quic_test_server.h", + "quic_test_server_interface.cc", + ], + hdrs = ["quic_test_server_interface.h"], + data = [ + "@envoy//test/config/integration/certs", + ], + repository = "@envoy", + deps = [ + "@envoy//source/common/quic:active_quic_listener_lib", + "@envoy//source/common/quic:quic_factory_lib", + "@envoy//source/common/quic:quic_stat_names_lib", + "@envoy//source/common/stats:isolated_store_lib", + "@envoy//test:test_pch", + "@envoy//source/exe:process_wide_lib", + "@envoy//test/mocks/access_log:access_log_mocks", + "@envoy//test/config:utility_lib", + "@envoy//source/common/common:logger_lib", + "@envoy//test/integration:autonomous_upstream_lib", + "@envoy//test/integration:fake_upstream_lib", + "@envoy//test/test_common:network_utility_lib", + "@envoy_api//envoy/extensions/filters/common/matcher/action/v3:pkg_cc_proto", + "@envoy_api//envoy/extensions/transport_sockets/quic/v3:pkg_cc_proto", + ] + select({ + "@envoy//bazel:disable_signal_trace": [], + "//conditions:default": [ + "@envoy//source/common/signal:sigaction_lib", + ], + }), +) diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc new file mode 100644 index 0000000000..1fa93d9e04 --- /dev/null +++ b/test/common/integration/quic_test_server.cc @@ -0,0 +1,126 @@ +#include "quic_test_server.h" + +using bazel::tools::cpp::runfiles::Runfiles; +namespace Envoy { + + // see https://github.com/envoyproxy/envoy/blob/main/test/test_runner.cc + void QuicTestServer::setup(int argc, char** argv) { + Envoy::TestEnvironment::initializeTestMain(argv[0]); + + std::string error; + const std::basic_string argv0; + std::unique_ptr runfiles(Runfiles::CreateForTest()); + RELEASE_ASSERT(Envoy::TestEnvironment::getOptionalEnvVar("NORUNFILES").has_value() || + runfiles != nullptr, + error); + + Envoy::TestEnvironment::setRunfiles(runfiles.get()); + + Envoy::TestEnvironment::setEnvVar("ENVOY_IP_TEST_VERSIONS", "v4only", 0); + + ::testing::InitGoogleMock(&argc, argv); + + ProcessWide process_wide; + + ::testing::FLAGS_gtest_death_test_style = "threadsafe"; + + testing::Test::RecordProperty("TemporaryDirectory", TestEnvironment::temporaryDirectory()); + + TestEnvironment::setEnvVar("TEST_UDSDIR", TestEnvironment::unixDomainSocketDirectory(), 1); + + TestEnvironment::initializeOptions(argc, argv); + Thread::MutexBasicLockable lock; + + Server::Options& options = TestEnvironment::getOptions(); + + Logger::Registry::getSink()->setLock(lock); + Logger::Registry::getSink()->setShouldEscape(false); + Logger::Registry::setLogLevel(options.logLevel()); + Logger::Registry::setLogFormat(options.logFormat()); + + // TODO(colibie) this doesnt work. Why? + // Logger::Context logging_state(options.logLevel(), options.logFormat(), lock, false, + // options.enableFineGrainLogging()); + + if (Logger::Registry::getSink()->hasLock()) {std::cerr << "true \n";}; + // Allocate fake log access manager. + testing::NiceMock access_log_manager; + std::unique_ptr file_logger; + + // Redirect all logs to fake file when --log-path arg is specified in command line. + if (!TestEnvironment::getOptions().logPath().empty()) { + file_logger = std::make_unique( + TestEnvironment::getOptions().logPath(), access_log_manager, Logger::Registry::getSink()); + } + + } + + Network::TransportSocketFactoryPtr QuicTestServer::createUpstreamTlsContext(testing::NiceMock& factory_context) { + envoy::extensions::transport_sockets::tls::v3::DownstreamTlsContext tls_context; + Extensions::TransportSockets::Tls::ContextManagerImpl context_manager_{time_system_}; + std::cerr << "quic_test_serverL50\n"; + //TODO (colibie) fix runfilesPath error; std::cerr << TestEnvironment::runfilesPath("") << " testpath\n"; + const std::string yaml = absl::StrFormat( + R"EOF( +common_tls_context: + tls_certificates: + - certificate_chain: { filename: "/usr/local/google/home/colibie/.cache/bazel/_bazel_colibie/bdfb488ae034f37da2dcebdbd6e4d897/execroot/envoy_mobile/bazel-out/k8-fastbuild/bin/test/java/org/chromium/net/quic_test.runfiles/envoy/test/config/integration/certs/upstreamcert.pem" } + private_key: { filename: "/usr/local/google/home/colibie/.cache/bazel/_bazel_colibie/bdfb488ae034f37da2dcebdbd6e4d897/execroot/envoy_mobile/bazel-out/k8-fastbuild/bin/test/java/org/chromium/net/quic_test.runfiles/envoy/test/config/integration/certs/upstreamkey.pem" } + validation_context: + trusted_ca: { filename: "/usr/local/google/home/colibie/.cache/bazel/_bazel_colibie/bdfb488ae034f37da2dcebdbd6e4d897/execroot/envoy_mobile/bazel-out/k8-fastbuild/bin/test/java/org/chromium/net/quic_test.runfiles/envoy/test/config/integration/certs/cacert.pem" } +)EOF"); + TestUtility::loadFromYaml(yaml, tls_context); + envoy::extensions::transport_sockets::quic::v3::QuicDownstreamTransport quic_config; + quic_config.mutable_downstream_tls_context()->MergeFrom(tls_context); + + std::vector server_names; + auto& config_factory = Config::Utility::getAndCheckFactoryByName< + Server::Configuration::DownstreamTransportSocketConfigFactory>( + "envoy.transport_sockets.quic"); + std::cerr << "quic_test_serverL73\n"; + return config_factory.createTransportSocketFactory(quic_config, factory_context, server_names); + } + + QuicTestServer::QuicTestServer() : api_(Api::createApiForTest(stats_store_, time_system_)), + version_(Network::Address::IpVersion::v4), + config_helper_(version_, *api_, ConfigHelper::baseConfig() + R"EOF( + filter_chains: + filters: + )EOF"){ + ON_CALL(factory_context_, api()).WillByDefault(testing::ReturnRef(*api_)); + ON_CALL(factory_context_, scope()).WillByDefault(testing::ReturnRef(stats_store_)); + + // TODO(colibie) remove test param value + char param[] = "/usr/local/google/home/colibie/.cache/bazel/_bazel_colibie/bdfb488ae034f37da2dcebdbd6e4d897/execroot/envoy_mobile/external/envoy/"; + + char *argv[]{param, NULL}; + setup(1, argv); + } + + void QuicTestServer::startQuicTestServer() { + FakeUpstreamConfig upstream_config_{time_system_}; + upstream_config_.upstream_protocol_ = Http::CodecType::HTTP3; + upstream_config_.udp_fake_upstream_ = FakeUpstreamConfig::UdpConfig(); + + Network::TransportSocketFactoryPtr factory = createUpstreamTlsContext(factory_context_); // Network::Test::createRawBufferSocketFactory(); + + int port = 0; // let the kernel pick a port that is not in use (avoids test races) + aupstream = std::make_unique(std::move(factory), port, version_, upstream_config_, false); + + // see what port was selected. + std::cerr << "Upstream now listening on " << aupstream->localAddress()->asString(); + + Logger::Registry::getSink()->clearLock(); + } + + void QuicTestServer::shutdownQuicTestServer() { + aupstream.reset(); +// FAIL() << "this way blaze will give you a test log"; + } + + int QuicTestServer::getServerPort() { + std::cerr << "quic_test_serverL147\n"; + return aupstream->localAddress()->ip()->port(); + } +} // namespace Envoy + diff --git a/test/common/integration/quic_test_server.h b/test/common/integration/quic_test_server.h new file mode 100644 index 0000000000..184ce8d5c6 --- /dev/null +++ b/test/common/integration/quic_test_server.h @@ -0,0 +1,49 @@ +#pragma once + +#include "source/common/stats/isolated_store_impl.h" +#include "source/extensions/transport_sockets/tls/ssl_socket.h" + +// test_runner setups +#include "source/common/common/logger.h" +#include "source/common/common/logger_delegates.h" +#include "source/exe/process_wide.h" +#include "test/mocks/access_log/mocks.h" + +#include "gtest/gtest.h" + +#include "absl/strings/str_format.h" +#include "envoy/extensions/transport_sockets/quic/v3/quic_transport.pb.h" +#include "test/mocks/server/transport_socket_factory_context.h" +#include "test/test_common/environment.h" +#include "test/integration/fake_upstream.h" +#include "test/integration/autonomous_upstream.h" +#include "test/config/utility.h" +#include "test/test_common/network_utility.h" +#include "tools/cpp/runfiles/runfiles.h" + +namespace Envoy { + class QuicTestServer { + private: + testing::NiceMock factory_context_; + Stats::IsolatedStoreImpl stats_store_; + Event::GlobalTimeSystem time_system_; + Api::ApiPtr api_; + Network::Address::IpVersion version_; + ConfigHelper config_helper_; + std::unique_ptr upstream; + std::unique_ptr aupstream; + + void setup(int, char**); + Network::TransportSocketFactoryPtr createUpstreamTlsContext(testing::NiceMock&); + + public: + QuicTestServer(); + + void startQuicTestServer(); + + void shutdownQuicTestServer(); + + int getServerPort(); + }; + +} // namespace Envoy \ No newline at end of file diff --git a/test/common/integration/quic_test_server_interface.cc b/test/common/integration/quic_test_server_interface.cc new file mode 100644 index 0000000000..3c3008c34a --- /dev/null +++ b/test/common/integration/quic_test_server_interface.cc @@ -0,0 +1,34 @@ +#include "test/common/integration/quic_test_server_interface.h" + +// NOLINT(namespace-envoy) + +static std::shared_ptr strong_quic_test_server_; +static std::weak_ptr quic_test_server_; + +static std::shared_ptr quic_test_server() { + return quic_test_server_.lock(); +} + +void start_server() { + // start server + strong_quic_test_server_ = std::make_shared(); + quic_test_server_ = strong_quic_test_server_; + + if (auto e = quic_test_server()) { + e->startQuicTestServer(); + } +} + +void shutdown_server() { + auto e = strong_quic_test_server_; + strong_quic_test_server_.reset(); + e->shutdownQuicTestServer(); +} + +int get_server_port() { + if (auto e = quic_test_server()) { + return e->getServerPort(); + } + // TODO (colibie) write a more suitable error code + return 1; // failure +} \ No newline at end of file diff --git a/test/common/integration/quic_test_server_interface.h b/test/common/integration/quic_test_server_interface.h new file mode 100644 index 0000000000..06ac960f64 --- /dev/null +++ b/test/common/integration/quic_test_server_interface.h @@ -0,0 +1,18 @@ +#pragma once + +#include "test/common/integration/quic_test_server.h" +// NOLINT(namespace-envoy) + +#ifdef __cplusplus +extern "C" { // functions +#endif + +void start_server(); + +void shutdown_server(); + +int get_server_port(); + +#ifdef __cplusplus +} // functions +#endif diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD new file mode 100644 index 0000000000..280de77aa9 --- /dev/null +++ b/test/common/jni/BUILD @@ -0,0 +1,36 @@ +load("//bazel:kotlin_lib.bzl", "envoy_mobile_so_to_jni_lib") +load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") +load("@envoy//bazel:envoy_build_system.bzl", "envoy_cc_library", "envoy_package") + +licenses(["notice"]) # Apache 2 + +envoy_package() + +### Targets for local execution +## OS X binary (.jnilib) for NDK testing +#envoy_mobile_so_to_jni_lib_test( +# name = "libquic_test_server_jni.jnilib", +# native_dep = "libquic_test_server_jni.so", +#) + +# dynamic library for the Envoy Mobile aar +cc_binary( + name = "libquic_test_server_jni.so", + testonly = True, + srcs = [ + "quic_test_server_jni_interface.cc", + "@local_jdk//:jni_header", + ], + copts = ["-std=c++17"], + linkopts = [ + ], + linkshared = True, + deps = [ + "//bazel:jni", + "//library/common:envoy_main_interface_lib", + "//library/common/api:c_types", + "//library/common/jni:base_java_jni_lib", + "//library/common/jni:java_jni_support", + "//test/common/integration:quic_test_server_interface_lib", + ], +) diff --git a/test/common/jni/quic_test_server_jni_interface.cc b/test/common/jni/quic_test_server_jni_interface.cc new file mode 100644 index 0000000000..600d018b7b --- /dev/null +++ b/test/common/jni/quic_test_server_jni_interface.cc @@ -0,0 +1,36 @@ +#include + +#include "library/common/jni/jni_support.h" +#include "library/common/jni/jni_utility.h" +#include "library/common/jni/jni_version.h" +#include "test/common/integration/quic_test_server_interface.h" + + +// Quic Test ServerJniLibrary + +extern "C" JNIEXPORT void JNICALL Java_org_chromium_net_testing_QuicTestServer_nativeStartQuicTestServer(JNIEnv * env, + jclass clazz, + jstring file_path, + jstring test_data_dir) { + // TODO: implement nativeStartQuicTestServer() + jni_log("[QTS]", "starting server"); + start_server(); +} + +extern "C" JNIEXPORT jint +JNICALL +Java_org_chromium_net_testing_QuicTestServer_nativeGetServerPort(JNIEnv* env, + jclass clazz) { + // TODO: implement nativeGetServerPort() + jni_log("[QTS]", "getting server port"); + return get_server_port(); +} + + +extern "C" JNIEXPORT void JNICALL +Java_org_chromium_net_testing_QuicTestServer_nativeShutdownQuicTestServer(JNIEnv * env, + jclass clazz) { +// TODO: implement nativeShutdownQuicTestServer() +jni_log("[QTS]", "shutting down server"); + shutdown_server(); +} \ No newline at end of file diff --git a/test/java/org/chromium/net/BUILD b/test/java/org/chromium/net/BUILD index a871a3a1b1..20c594d2de 100644 --- a/test/java/org/chromium/net/BUILD +++ b/test/java/org/chromium/net/BUILD @@ -32,6 +32,28 @@ envoy_mobile_android_test( ], ) +envoy_mobile_android_test( + name = "quic_test", + srcs = [ + "QuicTest.java", + ], + library_path = "library/common/jni:test/common/jni", + native_deps = [ + "//library/common/jni:libndk_envoy_jni.so", + "//library/common/jni:libndk_envoy_jni.jnilib", + "//test/common/jni:libquic_test_server_jni.so", + ], + deps = [ + "//library/java/io/envoyproxy/envoymobile/engine:envoy_base_engine_lib", + "//library/java/io/envoyproxy/envoymobile/engine:envoy_engine_lib", + "//library/java/org/chromium/net", + "//library/java/org/chromium/net/impl:cronvoy", + "//library/kotlin/io/envoyproxy/envoymobile:envoy_interfaces_lib", + "//library/kotlin/io/envoyproxy/envoymobile:envoy_lib", + "//test/java/org/chromium/net/testing", + ], +) + envoy_mobile_android_test( name = "cronet_url_request_context_test", srcs = [ diff --git a/test/java/org/chromium/net/QuicTest.java b/test/java/org/chromium/net/QuicTest.java new file mode 100644 index 0000000000..c20e6bb329 --- /dev/null +++ b/test/java/org/chromium/net/QuicTest.java @@ -0,0 +1,305 @@ +package org.chromium.net; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import static org.chromium.net.testing.CronetTestRule.getContext; +import static org.chromium.net.testing.CronetTestRule.getTestStorage; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.LargeTest; +import androidx.test.filters.SmallTest; + +import org.chromium.net.testing.CronetTestRule; +import org.chromium.net.testing.CronetTestUtil; +import org.chromium.net.testing.QuicTestServer; +import org.chromium.net.testing.QuicTestServerA; +import org.chromium.net.testing.TestUrlRequestCallback; +import org.json.JSONObject; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import android.util.Log; +import org.chromium.net.testing.Feature; +import org.chromium.net.testing.CronetTestRule.OnlyRunNativeCronet; +import org.chromium.net.testing.MetricsTestUtil.TestRequestFinishedListener; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Date; +import java.util.concurrent.Executors; + +/** + * Tests making requests using QUIC. + */ +@RunWith(AndroidJUnit4.class) +public class QuicTest { + @Rule + public final CronetTestRule mTestRule = new CronetTestRule(); + + private static final String TAG = QuicTest.class.getSimpleName(); + private ExperimentalCronetEngine.Builder mBuilder; + + @Before + public void setUp() throws Exception { + // Load library first, since we need the Quic test server's URL. + System.loadLibrary("quic_test_server_jni"); + QuicTestServer.startQuicTestServer(getContext()); + mBuilder = new ExperimentalCronetEngine.Builder(getContext()); + // mBuilder.enableNetworkQualityEstimator(true).enableQuic(true); + // mBuilder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getServerPort(), + // QuicTestServer.getServerPort()); + // + // // The pref may not be written if the computed Effective Connection Type (ECT) matches the + // // default ECT for the current connection type. Force the ECT to "Slow-2G". Since "Slow-2G" + // // is not the default ECT for any connection type, this ensures that the pref is written to. + // JSONObject nqeParams = new JSONObject().put("force_effective_connection_type", "Slow-2G"); + // // TODO(mgersh): Enable connection migration once it works, see http://crbug.com/634910 + // JSONObject quicParams = new JSONObject() + // .put("connection_options", "PACE,IW10,FOO,DEADBEEF") + // .put("max_server_configs_stored_in_properties", 2) + // .put("idle_connection_timeout_seconds", 300) + // .put("migrate_sessions_on_network_change_v2", false) + // .put("migrate_sessions_early_v2", false) + // .put("race_cert_verification", true); + // JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules(); + // JSONObject experimentalOptions = new JSONObject() + // .put("QUIC", quicParams) + // .put("HostResolverRules", hostResolverParams) + // .put("NetworkQualityEstimator", nqeParams); + // mBuilder.setExperimentalOptions(experimentalOptions.toString()); + // mBuilder.setStoragePath(getTestStorage()); + // mBuilder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK_NO_HTTP, 1000 * 1024); + // CronetTestUtil.setMockCertVerifierForTesting( + // mBuilder, QuicTestServer.createMockCertVerifier()); + } + + @After + public void tearDown() throws Exception { + System.out.println("QTS: quicTestJavaL88\n"); + + QuicTestServer.shutdownQuicTestServer(); + } + + @Test + @LargeTest + @Feature({"Cronet"}) + @OnlyRunNativeCronet + public void testQuicLoadUrl() throws Exception { + ExperimentalCronetEngine cronetEngine = mBuilder.build(); + String quicURL = QuicTestServer.getServerURL(); + TestUrlRequestCallback callback = new TestUrlRequestCallback(); + // Although the native stack races QUIC and SPDY for the first request, + // since there is no http server running on the corresponding TCP port, + // QUIC will always succeed with a 200 (see + // net::HttpStreamFactoryImpl::Request::OnStreamFailed). + UrlRequest.Builder requestBuilder = + cronetEngine.newUrlRequestBuilder(quicURL, callback, callback.getExecutor()); + requestBuilder.build().start(); + callback.blockForDone(); + System.out.println("QTS:" + callback.mResponseInfo); + assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); + String expectedContent = "This is a simple text file served by QUIC.\n"; + assertEquals(expectedContent, callback.mResponseAsString); + assertIsQuic(callback.mResponseInfo); + // The total received bytes should be larger than the content length, to account for + // headers. + assertTrue(callback.mResponseInfo.getReceivedByteCount() > expectedContent.length()); + // This test takes a long time, since the update will only be scheduled + // after kUpdatePrefsDelayMs in http_server_properties_manager.cc. + while (true) { + Log.i(TAG, "Still waiting for pref file update....."); + Thread.sleep(10000); + boolean contains = false; + try { + if (fileContainsString("local_prefs.json", "quic")) break; + } catch (FileNotFoundException e) { + // Ignored this exception since the file will only be created when updates are + // flushed to the disk. + } + } + assertTrue(fileContainsString("local_prefs.json", + QuicTestServer.getServerHost() + ":" + QuicTestServer.getServerPort())); + cronetEngine.shutdown(); + + // Make another request using a new context but with no QUIC hints. + ExperimentalCronetEngine.Builder builder = + new ExperimentalCronetEngine.Builder(getContext()); + builder.setStoragePath(getTestStorage()); + builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK, 1000 * 1024); + builder.enableQuic(true); + JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules(); + JSONObject experimentalOptions = new JSONObject() + .put("HostResolverRules", hostResolverParams); + builder.setExperimentalOptions(experimentalOptions.toString()); + CronetTestUtil.setMockCertVerifierForTesting( + builder, QuicTestServer.createMockCertVerifier()); + cronetEngine = builder.build(); + TestUrlRequestCallback callback2 = new TestUrlRequestCallback(); + requestBuilder = + cronetEngine.newUrlRequestBuilder(quicURL, callback2, callback2.getExecutor()); + requestBuilder.build().start(); + callback2.blockForDone(); + assertEquals(200, callback2.mResponseInfo.getHttpStatusCode()); + assertEquals(expectedContent, callback2.mResponseAsString); + assertIsQuic(callback.mResponseInfo); + // The total received bytes should be larger than the content length, to account for + // headers. + assertTrue(callback2.mResponseInfo.getReceivedByteCount() > expectedContent.length()); + cronetEngine.shutdown(); + } + + // Returns whether a file contains a particular string. + private boolean fileContainsString(String filename, String content) throws IOException { + File file = new File(getTestStorage() + "/prefs/" + filename); + FileInputStream fileInputStream = new FileInputStream(file); + byte[] data = new byte[(int) file.length()]; + fileInputStream.read(data); + fileInputStream.close(); + return new String(data, "UTF-8").contains(content); + } + + /** + * Tests that the network quality listeners are propoerly notified when QUIC is enabled. + */ + // @Test + // @LargeTest + // @Feature({"Cronet"}) + // @OnlyRunNativeCronet + // @SuppressWarnings("deprecation") + // public void testNQEWithQuic() throws Exception { + // ExperimentalCronetEngine cronetEngine = mBuilder.build(); + // String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; + // + // TestNetworkQualityRttListener rttListener = + // new TestNetworkQualityRttListener(Executors.newSingleThreadExecutor()); + // TestNetworkQualityThroughputListener throughputListener = + // new TestNetworkQualityThroughputListener(Executors.newSingleThreadExecutor()); + // + // cronetEngine.addRttListener(rttListener); + // cronetEngine.addThroughputListener(throughputListener); + // + // cronetEngine.configureNetworkQualityEstimatorForTesting(true, true, true); + // TestUrlRequestCallback callback = new TestUrlRequestCallback(); + // + // // Although the native stack races QUIC and SPDY for the first request, + // // since there is no http server running on the corresponding TCP port, + // // QUIC will always succeed with a 200 (see + // // net::HttpStreamFactoryImpl::Request::OnStreamFailed). + // UrlRequest.Builder requestBuilder = + // cronetEngine.newUrlRequestBuilder(quicURL, callback, callback.getExecutor()); + // requestBuilder.build().start(); + // callback.blockForDone(); + // + // assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); + // String expectedContent = "This is a simple text file served by QUIC.\n"; + // assertEquals(expectedContent, callback.mResponseAsString); + // assertIsQuic(callback.mResponseInfo); + // + // // Throughput observation is posted to the network quality estimator on the network thread + // // after the UrlRequest is completed. The observations are then eventually posted to + // // throughput listeners on the executor provided to network quality. + // throughputListener.waitUntilFirstThroughputObservationReceived(); + // + // // Wait for RTT observation (at the URL request layer) to be posted. + // rttListener.waitUntilFirstUrlRequestRTTReceived(); + // + // assertTrue(throughputListener.throughputObservationCount() > 0); + // + // // Check RTT observation count after throughput observation has been received. This ensures + // // that executor has finished posting the RTT observation to the RTT listeners. + // // NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST + // assertTrue(rttListener.rttObservationCount(0) > 0); + // + // // NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC + // assertTrue(rttListener.rttObservationCount(2) > 0); + // + // // Verify that effective connection type callback is received and + // // effective connection type is correctly set. + // assertTrue( + // cronetEngine.getEffectiveConnectionType() != EffectiveConnectionType.TYPE_UNKNOWN); + // + // // Verify that the HTTP RTT, transport RTT and downstream throughput + // // estimates are available. + // assertTrue(cronetEngine.getHttpRttMs() >= 0); + // assertTrue(cronetEngine.getTransportRttMs() >= 0); + // assertTrue(cronetEngine.getDownstreamThroughputKbps() >= 0); + // + // // Verify that the cached estimates were written to the prefs. + // while (true) { + // Log.i(TAG, "Still waiting for pref file update....."); + // Thread.sleep(10000); + // try { + // if (fileContainsString("local_prefs.json", "network_qualities")) { + // break; + // } + // } catch (FileNotFoundException e) { + // // Ignored this exception since the file will only be created when updates are + // // flushed to the disk. + // } + // } + // assertTrue(fileContainsString("local_prefs.json", "network_qualities")); + // cronetEngine.shutdown(); + // } + // + // @Test + // @SmallTest + // @OnlyRunNativeCronet + // @Feature({"Cronet"}) + // public void testMetricsWithQuic() throws Exception { + // ExperimentalCronetEngine cronetEngine = mBuilder.build(); + // TestRequestFinishedListener requestFinishedListener = new TestRequestFinishedListener(); + // cronetEngine.addRequestFinishedListener(requestFinishedListener); + // + // String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; + // TestUrlRequestCallback callback = new TestUrlRequestCallback(); + // + // UrlRequest.Builder requestBuilder = + // cronetEngine.newUrlRequestBuilder(quicURL, callback, callback.getExecutor()); + // Date startTime = new Date(); + // requestBuilder.build().start(); + // callback.blockForDone(); + // requestFinishedListener.blockUntilDone(); + // Date endTime = new Date(); + // + // assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); + // assertIsQuic(callback.mResponseInfo); + // + // RequestFinishedInfo requestInfo = requestFinishedListener.getRequestInfo(); + // MetricsTestUtil.checkRequestFinishedInfo(requestInfo, quicURL, startTime, endTime); + // assertEquals(RequestFinishedInfo.SUCCEEDED, requestInfo.getFinishedReason()); + // MetricsTestUtil.checkHasConnectTiming(requestInfo.getMetrics(), startTime, endTime, true); + // + // // Second request should use the same connection and not have ConnectTiming numbers + // callback = new TestUrlRequestCallback(); + // requestFinishedListener.reset(); + // requestBuilder = + // cronetEngine.newUrlRequestBuilder(quicURL, callback, callback.getExecutor()); + // startTime = new Date(); + // requestBuilder.build().start(); + // callback.blockForDone(); + // requestFinishedListener.blockUntilDone(); + // endTime = new Date(); + // + // assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); + // assertIsQuic(callback.mResponseInfo); + // + // requestInfo = requestFinishedListener.getRequestInfo(); + // MetricsTestUtil.checkRequestFinishedInfo(requestInfo, quicURL, startTime, endTime); + // assertEquals(RequestFinishedInfo.SUCCEEDED, requestInfo.getFinishedReason()); + // MetricsTestUtil.checkNoConnectTiming(requestInfo.getMetrics()); + // + // cronetEngine.shutdown(); + // } + + // Helper method to assert that the request is negotiated over QUIC. + private void assertIsQuic(UrlResponseInfo responseInfo) { + assertTrue(responseInfo.getNegotiatedProtocol().startsWith("http/2+quic") + || responseInfo.getNegotiatedProtocol().startsWith("h3")); + } +} diff --git a/test/java/org/chromium/net/testing/BUILD b/test/java/org/chromium/net/testing/BUILD index 6209f0e41d..ca09988b55 100644 --- a/test/java/org/chromium/net/testing/BUILD +++ b/test/java/org/chromium/net/testing/BUILD @@ -13,14 +13,18 @@ android_library( "ConditionVariable.java", "ContextUtils.java", "CronetTestRule.java", + "CronetTestUtil.java", "FailurePhase.java", "Feature.java", "FileUtils.java", "MetricsTestUtil.java", + "MockCertVerifier.java", "MockUrlRequestJobFactory.java", "NativeTestServer.java", "PathUtils.java", + "QuicTestServer.java", "StrictModeContext.java", + "TestFilesInstaller.java", "TestUploadDataProvider.java", "TestUrlRequestCallback.java", "UrlUtils.java", diff --git a/test/java/org/chromium/net/testing/CronetTestUtil.java b/test/java/org/chromium/net/testing/CronetTestUtil.java new file mode 100644 index 0000000000..4de7434627 --- /dev/null +++ b/test/java/org/chromium/net/testing/CronetTestUtil.java @@ -0,0 +1,85 @@ +package org.chromium.net.testing; + +import org.chromium.net.CronetEngine; +import org.chromium.net.ExperimentalCronetEngine; +import org.chromium.net.UrlRequest; +import org.chromium.net.impl.CronetEngineBuilderImpl; +import org.chromium.net.impl.CronetUrlRequestContext; +import org.json.JSONException; +import org.json.JSONObject; + +/** + * Utilities for Cronet testing + */ +public class CronetTestUtil { + // QUIC test domain must match the certificate used + // (quic-chain.pem and quic-leaf-cert.key), and the file served ( + // components/cronet/android/test/assets/test/quic_data/simple.txt). + static final String QUIC_FAKE_HOST = "test.example.com"; + private static final String[] TEST_DOMAINS = {QUIC_FAKE_HOST}; + private static final String LOOPBACK_ADDRESS = "127.0.0.1"; + + /** + * Generates rules for customized DNS mapping for testing hostnames used by test servers, + * namely: + *
    + *
  • {@link QuicTestServer#getServerHost}
  • + *
+ * Maps the test hostnames to 127.0.0.1. + */ + public static JSONObject generateHostResolverRules() throws JSONException { + return generateHostResolverRules(LOOPBACK_ADDRESS); + } + + /** + * Generates rules for customized DNS mapping for testing hostnames used by test servers, + * namely: + *
    + *
  • {@link QuicTestServer#getServerHost}
  • + *
+ * @param destination host to map to + */ + public static JSONObject generateHostResolverRules(String destination) throws JSONException { + StringBuilder rules = new StringBuilder(); + for (String domain : TEST_DOMAINS) { + rules.append("MAP " + domain + " " + destination + ","); + } + return new JSONObject().put("host_resolver_rules", rules); + } + + /** + * Prepare {@code cronetEngine}'s network thread so libcronet_test code can run on it. + */ + public static class NetworkThreadTestConnector { + private final CronetUrlRequestContext mRequestContext; + + public NetworkThreadTestConnector(CronetEngine cronetEngine) { + mRequestContext = (CronetUrlRequestContext) cronetEngine; + // nativePrepareNetworkThread(mRequestContext.getUrlRequestContextAdapter()); + } + + public void shutdown() { + // TODO(colibie): to be implemented + } + } + + /** + * Returns the value of load flags in |urlRequest|. + * @param urlRequest is the UrlRequest object of interest. + */ + public static int getLoadFlags(UrlRequest urlRequest) { + // To be implemented + return 0; + } + + public static void setMockCertVerifierForTesting( + ExperimentalCronetEngine.Builder builder, long mockCertVerifier) { + getCronetEngineBuilderImpl(builder).setMockCertVerifierForTesting(mockCertVerifier); + } + + public static CronetEngineBuilderImpl getCronetEngineBuilderImpl( + ExperimentalCronetEngine.Builder builder) { + return (CronetEngineBuilderImpl) builder.getBuilderDelegate(); + } +} + diff --git a/test/java/org/chromium/net/testing/MockCertVerifier.java b/test/java/org/chromium/net/testing/MockCertVerifier.java new file mode 100644 index 0000000000..3534fdd614 --- /dev/null +++ b/test/java/org/chromium/net/testing/MockCertVerifier.java @@ -0,0 +1,21 @@ +package org.chromium.net.testing; + +/** + * A Java wrapper to supply a net::MockCertVerifier which can be then passed + * into {@link CronetEngine.Builder#setMockCertVerifierForTesting}. + * The native pointer will be freed when the CronetEngine is torn down. + */ +public class MockCertVerifier { + private MockCertVerifier() {} + + /** + * Creates a new net::MockCertVerifier, and returns a pointer to it. + * @param certs a String array of certificate filenames in + * net::GetTestCertsDirectory() to accept in testing. + * @return a pointer to the newly created net::MockCertVerifier. + */ + public static long createMockCertVerifier(String[] certs, boolean knownRoot) { + // TODO: to be implemented + return 0L; + } +} diff --git a/test/java/org/chromium/net/testing/QuicTestServer.java b/test/java/org/chromium/net/testing/QuicTestServer.java new file mode 100644 index 0000000000..0637f92273 --- /dev/null +++ b/test/java/org/chromium/net/testing/QuicTestServer.java @@ -0,0 +1,87 @@ +package org.chromium.net.testing; + +import android.content.Context; +import android.os.ConditionVariable; +import android.util.Log; + +/** + * Wrapper class to start a Quic test server. + */ + +public final class QuicTestServer { + private static final ConditionVariable sBlock = new ConditionVariable(); + private static final String TAG = QuicTestServer.class.getSimpleName(); + + private static final String CERT_USED = "upstreamcert.pem"; + private static final String KEY_USED = "upstreamkey.pem"; + private static final String[] CERTS_USED = {CERT_USED}; + + private static boolean sServerRunning; + + /* + * Starts the server. + */ + public static void startQuicTestServer(Context context) { + if (sServerRunning) { + throw new IllegalStateException("Quic server is already running"); + } + System.out.println("QTS: quicTestServerJavaL28"); + TestFilesInstaller.installIfNeeded(context); + nativeStartQuicTestServer( + TestFilesInstaller.getInstalledPath(context), UrlUtils.getIsolatedTestRoot()); + System.out.println("port at: " + nativeGetServerPort()); + System.out.println("QTS: quicTestServerJavaL32"); + // sBlock.block(); + // sBlock.close(); + sServerRunning = true; + } + + /** + * Shuts down the server. No-op if the server is already shut down. + */ + public static void shutdownQuicTestServer() { + if (!sServerRunning) { + return; + } + nativeShutdownQuicTestServer(); + sServerRunning = false; + } + + public static String getServerURL() { + System.out.println("QTS: quicTestServerJavaL51"); + return "https://" + getServerHost() + ":" + getServerPort() + "/"; + } + + public static String getServerHost() { + System.out.println("QTS: quicTestServerJavaL56"); + // return CronetTestUtil.QUIC_FAKE_HOST; + return "127.0.0.1"; + } + + public static int getServerPort() { + return nativeGetServerPort(); + } + + public static final String getServerCert() { + return CERT_USED; + } + + public static final String getServerCertKey() { + return KEY_USED; + } + + public static long createMockCertVerifier() { + TestFilesInstaller.installIfNeeded(ContextUtils.getApplicationContext()); + return MockCertVerifier.createMockCertVerifier(CERTS_USED, true); + } + + // @CalledByNative + private static void onServerStarted() { + Log.i(TAG, "Quic server started."); + sBlock.open(); + } + + private static native void nativeStartQuicTestServer(String filePath, String testDataDir); + private static native void nativeShutdownQuicTestServer(); + private static native int nativeGetServerPort(); +} \ No newline at end of file From 15cfb054508a17c4d9cd130fa8dc37423972c686 Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Tue, 7 Sep 2021 12:39:51 +0000 Subject: [PATCH 03/54] remove traces of argc and argv Signed-off-by: Chidera Olibie --- test/common/integration/quic_test_server.cc | 143 +++++++++++------- test/common/integration/quic_test_server.h | 3 +- .../chromium/net/testing/QuicTestServer.java | 6 +- 3 files changed, 91 insertions(+), 61 deletions(-) diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc index 1fa93d9e04..913ae16e11 100644 --- a/test/common/integration/quic_test_server.cc +++ b/test/common/integration/quic_test_server.cc @@ -1,73 +1,113 @@ #include "quic_test_server.h" -using bazel::tools::cpp::runfiles::Runfiles; namespace Envoy { - // see https://github.com/envoyproxy/envoy/blob/main/test/test_runner.cc - void QuicTestServer::setup(int argc, char** argv) { - Envoy::TestEnvironment::initializeTestMain(argv[0]); - - std::string error; - const std::basic_string argv0; - std::unique_ptr runfiles(Runfiles::CreateForTest()); - RELEASE_ASSERT(Envoy::TestEnvironment::getOptionalEnvVar("NORUNFILES").has_value() || - runfiles != nullptr, - error); - - Envoy::TestEnvironment::setRunfiles(runfiles.get()); - - Envoy::TestEnvironment::setEnvVar("ENVOY_IP_TEST_VERSIONS", "v4only", 0); - - ::testing::InitGoogleMock(&argc, argv); + void QuicTestServer::setup() { ProcessWide process_wide; - - ::testing::FLAGS_gtest_death_test_style = "threadsafe"; - - testing::Test::RecordProperty("TemporaryDirectory", TestEnvironment::temporaryDirectory()); - - TestEnvironment::setEnvVar("TEST_UDSDIR", TestEnvironment::unixDomainSocketDirectory(), 1); - - TestEnvironment::initializeOptions(argc, argv); Thread::MutexBasicLockable lock; - Server::Options& options = TestEnvironment::getOptions(); - Logger::Registry::getSink()->setLock(lock); Logger::Registry::getSink()->setShouldEscape(false); - Logger::Registry::setLogLevel(options.logLevel()); - Logger::Registry::setLogFormat(options.logFormat()); + Logger::Registry::setLogLevel(spdlog::level::level_enum::err); // options.logLevel() + Logger::Registry::setLogFormat("[%Y-%m-%d %T.%e][%t][%l][%n] [%g:%#] %v"); // options.logFormat() // TODO(colibie) this doesnt work. Why? // Logger::Context logging_state(options.logLevel(), options.logFormat(), lock, false, // options.enableFineGrainLogging()); - - if (Logger::Registry::getSink()->hasLock()) {std::cerr << "true \n";}; - // Allocate fake log access manager. - testing::NiceMock access_log_manager; - std::unique_ptr file_logger; - - // Redirect all logs to fake file when --log-path arg is specified in command line. - if (!TestEnvironment::getOptions().logPath().empty()) { - file_logger = std::make_unique( - TestEnvironment::getOptions().logPath(), access_log_manager, Logger::Registry::getSink()); - } - } Network::TransportSocketFactoryPtr QuicTestServer::createUpstreamTlsContext(testing::NiceMock& factory_context) { envoy::extensions::transport_sockets::tls::v3::DownstreamTlsContext tls_context; Extensions::TransportSockets::Tls::ContextManagerImpl context_manager_{time_system_}; - std::cerr << "quic_test_serverL50\n"; - //TODO (colibie) fix runfilesPath error; std::cerr << TestEnvironment::runfilesPath("") << " testpath\n"; + const std::string yaml = absl::StrFormat( R"EOF( common_tls_context: + alpn_protocols: h3 tls_certificates: - - certificate_chain: { filename: "/usr/local/google/home/colibie/.cache/bazel/_bazel_colibie/bdfb488ae034f37da2dcebdbd6e4d897/execroot/envoy_mobile/bazel-out/k8-fastbuild/bin/test/java/org/chromium/net/quic_test.runfiles/envoy/test/config/integration/certs/upstreamcert.pem" } - private_key: { filename: "/usr/local/google/home/colibie/.cache/bazel/_bazel_colibie/bdfb488ae034f37da2dcebdbd6e4d897/execroot/envoy_mobile/bazel-out/k8-fastbuild/bin/test/java/org/chromium/net/quic_test.runfiles/envoy/test/config/integration/certs/upstreamkey.pem" } + - certificate_chain: + inline_string: | + -----BEGIN CERTIFICATE----- + MIIEPjCCAyagAwIBAgIUEuy1WgSCzX6mojPirk7Th6uhNHowDQYJKoZIhvcNAQEL + BQAwfzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcM + DVNhbiBGcmFuY2lzY28xDTALBgNVBAoMBEx5ZnQxGTAXBgNVBAsMEEx5ZnQgRW5n + aW5lZXJpbmcxGTAXBgNVBAMMEFRlc3QgVXBzdHJlYW0gQ0EwHhcNMjAwODA1MTkx + NjAyWhcNMjIwODA1MTkxNjAyWjCBgzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNh + bGlmb3JuaWExFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xDTALBgNVBAoMBEx5ZnQx + GTAXBgNVBAsMEEx5ZnQgRW5naW5lZXJpbmcxHTAbBgNVBAMMFFRlc3QgVXBzdHJl + YW0gU2VydmVyMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtpiYA4/I + NuflkPe4L/GTslmngNQUCo8TzPXG0gt7uoxr4FeuVy7AaD28S2/hwhbl+bDtHTQY + mvBUwNMsYzpND2eQ3sSIumdeLzBEKP2mnnZ9gE/Zd2TIuZl686RpDq0B6ZdZSpCu + bqQmmPFLiRNH8JViJZMN5yqMt7T5oq+DnCYQZllqmpAwd6NnhKALrYmZ87oqc0zh + kf+5amP7zMYKkwQuRwcx4QPZkEp3+qhszolpAJ52dFGJ+pLuUVDg0Gf0cnxLjFKc + 6vcTlj4tsymR4ci58MHRt4EdGdhShw0oaj67gRRfU4Vj61I2ZAVH07kL0mjO2TZT + EKrOEJJ7/dtxdwIDAQABo4GsMIGpMAwGA1UdEwEB/wQCMAAwCwYDVR0PBAQDAgXg + MB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDATAtBgNVHREEJjAkggoqLmx5 + ZnQuY29thwR/AAABhxAAAAAAAAAAAAAAAAAAAAABMB0GA1UdDgQWBBQeoC5wxwX5 + k3ggIN/844/6jKx9czAfBgNVHSMEGDAWgBQ7Zh1TopMm7SY1RCOEO8L1G8IAZDAN + BgkqhkiG9w0BAQsFAAOCAQEA18wEg8LnPm99cIouFUFMAO+BpiY2KVa9Bu6x07m9 + quNFv7/4mLt87sk/umD3LH/tDjqW0D84vhG9a+0yDq7ZrD/P5eK3R+yBINwhe4/x + obJlThEsbcZF1FkMnq1rt53izukyQLLQwoVxidQl3HCg3hosWmpH1VBPgwoize6V + aAhKLW0n+JSfIE1d80nvZdYlHuCnS6UhLmAbTBCnwT0aGTfzT0Dd4KlYiY8vGZRu + tXOw4MzKtJcOL3t7Zpz2mhqN25dyiuyvKEhLXdx48aemwa2t6ISfFKsd0/glnNe/ + PFZMakzKv1G0xLGURjsInCZ0kePAmerfZN6CBZDo4laYEg== + -----END CERTIFICATE----- + private_key: + inline_string: | + -----BEGIN RSA PRIVATE KEY----- + MIIEpAIBAAKCAQEAtpiYA4/INuflkPe4L/GTslmngNQUCo8TzPXG0gt7uoxr4Feu + Vy7AaD28S2/hwhbl+bDtHTQYmvBUwNMsYzpND2eQ3sSIumdeLzBEKP2mnnZ9gE/Z + d2TIuZl686RpDq0B6ZdZSpCubqQmmPFLiRNH8JViJZMN5yqMt7T5oq+DnCYQZllq + mpAwd6NnhKALrYmZ87oqc0zhkf+5amP7zMYKkwQuRwcx4QPZkEp3+qhszolpAJ52 + dFGJ+pLuUVDg0Gf0cnxLjFKc6vcTlj4tsymR4ci58MHRt4EdGdhShw0oaj67gRRf + U4Vj61I2ZAVH07kL0mjO2TZTEKrOEJJ7/dtxdwIDAQABAoIBACz6E1+1N/0GTA7U + ZgMxP09MNC1QkAs1yQvQcoPknjqKQjxFfMUu1+gVZN80FOjpGQbTJOTvoyvvDQFe + Qu3CO58SxKWKxZ8cvR9khTWPnU4lI67KfGejZKoK+zUuh049IV53kGAEmWLZfkRo + E1IVdL/3G/DjcyZA3d6WbnM7RnDcqORPnig4lq5HxN76eBdssbxtrAi3Sjy3ChMy + BLInnryF4UtaT5xqR26YjgtFmYkunrgXTe1i/ewQgBBkSPXcNr7or69hCCv0SG9e + vRsv1r+Uug3/iRZDjEhKBmXWNAZJ/IsDF37ywiyeBdUY+klDX+mWz+0BB0us8b4u + LxoZQTECgYEA2Gu9EVC0RMrQ9FF5AgKKJWmZKkOn346RkPrtbl5lbuUgnVdBXJjr + wfMZVTD/8E/tMN4EMSGmC9bxCpRRzhrphrm7SHGD6b9O30DH9q0TV0r0A8IG/bMO + xJLYjrYVxtEE+KckzvyvfIefbDG7wYkI3u+ObmjBg9t6jcErKlI/PdkCgYEA1/1E + T+cpR16iOPz1mz+f/GU4YmPkdSDj/PrjMv0c1OTDvdPiZPpLkhLUKiICnKSKbYjX + Ko8fdZc3cmakgD1dXtAfR7Tf/hXQIR5+iHD48I5e9DVlkqMNDObfj82ohTFKVe/P + ZSwgDiAPTMFxWr26u/GzY5D3adCQYJyKE2wTh88CgYEAu7vpzGVnmu0ciXNLNvUh + BQcvODxsGT9BArTI1Z7I+oOD4TjZmAuHJz1L0lypB7stk+BjXoND2K1hdr3moJUz + 0gy3a0YdGd07++nkDBVi26xHNCNRkS2MN/TyKgnFpiuW1mOXSH5lc+7p2h7iMiY/ + LbQ8p4Xzp//xtZnFafbiqTECgYEAwDN5KZ1r5z24H/xCVv+cT46HSU7ZCr3VA9cC + fOouUOitouu9J9xviTJGKKQRLPFi2awOxKmN9ic1SRE7y35P60JKw5WaSdGBXydy + s9nMPMyEhM5Lb9y2jUeZo68ACl5dZvG63a4RbGBtHQF67KOvWvXvi2eCM2BMShyi + 5jujeZMCgYAjewq1hVqL1FOD8sIFpmndsH3+Dfc7BJ/erqGOX9bQYGvJO4nCe+7K + 4o8qFQf4jwdxu0iNxYJIMdn+l4/pz2e7GUFHjgMduUclf27Qj1p+8EyYqp6cmkzM + 8mcwRkYo3aM70EmUu0Xxi3d5O5F1bIJ5MkgXaX/zSF2N02B3jXroxQ== + -----END RSA PRIVATE KEY----- validation_context: - trusted_ca: { filename: "/usr/local/google/home/colibie/.cache/bazel/_bazel_colibie/bdfb488ae034f37da2dcebdbd6e4d897/execroot/envoy_mobile/bazel-out/k8-fastbuild/bin/test/java/org/chromium/net/quic_test.runfiles/envoy/test/config/integration/certs/cacert.pem" } + trusted_ca: + inline_string: | + -----BEGIN CERTIFICATE----- + MIID3TCCAsWgAwIBAgIUdCu/mLip3X/We37vh3BA9u/nxakwDQYJKoZIhvcNAQEL + BQAwdjELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcM + DVNhbiBGcmFuY2lzY28xDTALBgNVBAoMBEx5ZnQxGTAXBgNVBAsMEEx5ZnQgRW5n + aW5lZXJpbmcxEDAOBgNVBAMMB1Rlc3QgQ0EwHhcNMjAwODA1MTkxNjAwWhcNMjIw + ODA1MTkxNjAwWjB2MQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEW + MBQGA1UEBwwNU2FuIEZyYW5jaXNjbzENMAsGA1UECgwETHlmdDEZMBcGA1UECwwQ + THlmdCBFbmdpbmVlcmluZzEQMA4GA1UEAwwHVGVzdCBDQTCCASIwDQYJKoZIhvcN + AQEBBQADggEPADCCAQoCggEBALu2Ihi4DmaQG7zySZlWyM9SjxOXCI5840V7Hn0C + XoiI8sQQmKSC2YCzsaphQoJ0lXCi6Y47o5FkooYyLeNDQTGS0nh+IWm5RCyochtO + fnaKPv/hYxhpyFQEwkJkbF1Zt1s6j2rq5MzmbWZx090uXZEE82DNZ9QJaMPu6VWt + iwGoGoS5HF5HNlUVxLNUsklNH0ZfDafR7/LC2ty1vO1c6EJ6yCGiyJZZ7Ilbz27Q + HPAUd8CcDNKCHZDoMWkLSLN3Nj1MvPVZ5HDsHiNHXthP+zV8FQtloAuZ8Srsmlyg + rJREkc7gF3f6HrH5ShNhsRFFc53NUjDbYZuha1u4hiOE8lcCAwEAAaNjMGEwDwYD + VR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFJZL2ixTtL6V + xpNz4qekny4NchiHMB8GA1UdIwQYMBaAFJZL2ixTtL6VxpNz4qekny4NchiHMA0G + CSqGSIb3DQEBCwUAA4IBAQAcgG+AaCdrUFEVJDn9UsO7zqzQ3c1VOp+WAtAU8OQK + Oc4vJYVVKpDs8OZFxmukCeqm1gz2zDeH7TfgCs5UnLtkplx1YO1bd9qvserJVHiD + LAK+Yl24ZEbrHPaq0zI1RLchqYUOGWmi51pcXi1gsfc8DQ3GqIXoai6kYJeV3jFJ + jxpQSR32nx6oNN/6kVKlgmBjlWrOy7JyDXGim6Z97TzmS6Clctewmw/5gZ9g+M8e + g0ZdFbFkNUjzSNm44hiDX8nR6yJRn+gLaARaJvp1dnT+MlvofZuER17WYKH4OyMs + ie3qKR3an4KC20CtFbpZfv540BVuTTOCtQ5xqZ/LTE78 + -----END CERTIFICATE----- )EOF"); TestUtility::loadFromYaml(yaml, tls_context); envoy::extensions::transport_sockets::quic::v3::QuicDownstreamTransport quic_config; @@ -77,7 +117,7 @@ namespace Envoy { auto& config_factory = Config::Utility::getAndCheckFactoryByName< Server::Configuration::DownstreamTransportSocketConfigFactory>( "envoy.transport_sockets.quic"); - std::cerr << "quic_test_serverL73\n"; + return config_factory.createTransportSocketFactory(quic_config, factory_context, server_names); } @@ -90,11 +130,7 @@ namespace Envoy { ON_CALL(factory_context_, api()).WillByDefault(testing::ReturnRef(*api_)); ON_CALL(factory_context_, scope()).WillByDefault(testing::ReturnRef(stats_store_)); - // TODO(colibie) remove test param value - char param[] = "/usr/local/google/home/colibie/.cache/bazel/_bazel_colibie/bdfb488ae034f37da2dcebdbd6e4d897/execroot/envoy_mobile/external/envoy/"; - - char *argv[]{param, NULL}; - setup(1, argv); + setup(); } void QuicTestServer::startQuicTestServer() { @@ -108,7 +144,7 @@ namespace Envoy { aupstream = std::make_unique(std::move(factory), port, version_, upstream_config_, false); // see what port was selected. - std::cerr << "Upstream now listening on " << aupstream->localAddress()->asString(); + std::cerr << "Upstream now listening on " << aupstream->localAddress()->asString() << "\n"; Logger::Registry::getSink()->clearLock(); } @@ -119,7 +155,6 @@ namespace Envoy { } int QuicTestServer::getServerPort() { - std::cerr << "quic_test_serverL147\n"; return aupstream->localAddress()->ip()->port(); } } // namespace Envoy diff --git a/test/common/integration/quic_test_server.h b/test/common/integration/quic_test_server.h index 184ce8d5c6..5b1807bd7a 100644 --- a/test/common/integration/quic_test_server.h +++ b/test/common/integration/quic_test_server.h @@ -19,7 +19,6 @@ #include "test/integration/autonomous_upstream.h" #include "test/config/utility.h" #include "test/test_common/network_utility.h" -#include "tools/cpp/runfiles/runfiles.h" namespace Envoy { class QuicTestServer { @@ -33,7 +32,7 @@ namespace Envoy { std::unique_ptr upstream; std::unique_ptr aupstream; - void setup(int, char**); + void setup(); Network::TransportSocketFactoryPtr createUpstreamTlsContext(testing::NiceMock&); public: diff --git a/test/java/org/chromium/net/testing/QuicTestServer.java b/test/java/org/chromium/net/testing/QuicTestServer.java index 0637f92273..267ffec7a3 100644 --- a/test/java/org/chromium/net/testing/QuicTestServer.java +++ b/test/java/org/chromium/net/testing/QuicTestServer.java @@ -25,12 +25,10 @@ public static void startQuicTestServer(Context context) { if (sServerRunning) { throw new IllegalStateException("Quic server is already running"); } - System.out.println("QTS: quicTestServerJavaL28"); TestFilesInstaller.installIfNeeded(context); nativeStartQuicTestServer( TestFilesInstaller.getInstalledPath(context), UrlUtils.getIsolatedTestRoot()); - System.out.println("port at: " + nativeGetServerPort()); - System.out.println("QTS: quicTestServerJavaL32"); + // sBlock.block(); // sBlock.close(); sServerRunning = true; @@ -48,12 +46,10 @@ public static void shutdownQuicTestServer() { } public static String getServerURL() { - System.out.println("QTS: quicTestServerJavaL51"); return "https://" + getServerHost() + ":" + getServerPort() + "/"; } public static String getServerHost() { - System.out.println("QTS: quicTestServerJavaL56"); // return CronetTestUtil.QUIC_FAKE_HOST; return "127.0.0.1"; } From 91e1af832cf1097a7b3266099b954c0ba1241509 Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Tue, 7 Sep 2021 16:27:45 +0000 Subject: [PATCH 04/54] [WIP] create quicTestServerTest Signed-off-by: Chidera Olibie --- test/common/integration/BUILD | 4 +- test/common/integration/quic_test_server.cc | 147 ++++--- test/common/integration/quic_test_server.h | 47 +- .../integration/quic_test_server_interface.cc | 2 +- .../integration/quic_test_server_interface.h | 1 + test/common/jni/BUILD | 4 +- .../jni/quic_test_server_jni_interface.cc | 26 +- test/java/org/chromium/net/QuicTest.java | 2 +- test/java/org/chromium/net/testing/BUILD | 21 + .../net/testing/QuicTestServerTest.java | 409 ++++++++++++++++++ 10 files changed, 555 insertions(+), 108 deletions(-) create mode 100644 test/java/org/chromium/net/testing/QuicTestServerTest.java diff --git a/test/common/integration/BUILD b/test/common/integration/BUILD index ad73258a86..20c5e937fa 100644 --- a/test/common/integration/BUILD +++ b/test/common/integration/BUILD @@ -1,5 +1,4 @@ -load("@envoy//bazel:envoy_build_system.bzl", "envoy_cc_test", "envoy_package") -load("@envoy//bazel:envoy_build_system.bzl", "envoy_cc_test_library", "envoy_package") +load("@envoy//bazel:envoy_build_system.bzl", "envoy_cc_test", "envoy_cc_test_library", "envoy_package") licenses(["notice"]) # Apache 2 @@ -38,6 +37,7 @@ envoy_cc_test( "@envoy//test/integration:autonomous_upstream_lib", "@envoy//test/integration:fake_upstream_lib", "@envoy//test/test_common:network_utility_lib", + "@envoy_api//envoy/extensions/transport_sockets/quic/v3:pkg_cc_proto", # "@envoy_api//envoy/extensions/transport_sockets/quic/v3:pkg_cc_proto", ], ) diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc index 913ae16e11..3d23f9b13b 100644 --- a/test/common/integration/quic_test_server.cc +++ b/test/common/integration/quic_test_server.cc @@ -1,28 +1,29 @@ #include "quic_test_server.h" namespace Envoy { - // see https://github.com/envoyproxy/envoy/blob/main/test/test_runner.cc - void QuicTestServer::setup() { +// see https://github.com/envoyproxy/envoy/blob/main/test/test_runner.cc +void QuicTestServer::setup() { - ProcessWide process_wide; - Thread::MutexBasicLockable lock; + ProcessWide process_wide; + Thread::MutexBasicLockable lock; - Logger::Registry::getSink()->setLock(lock); - Logger::Registry::getSink()->setShouldEscape(false); - Logger::Registry::setLogLevel(spdlog::level::level_enum::err); // options.logLevel() - Logger::Registry::setLogFormat("[%Y-%m-%d %T.%e][%t][%l][%n] [%g:%#] %v"); // options.logFormat() + Logger::Registry::getSink()->setLock(lock); + Logger::Registry::getSink()->setShouldEscape(false); + Logger::Registry::setLogLevel(spdlog::level::level_enum::err); // options.logLevel() + Logger::Registry::setLogFormat("[%Y-%m-%d %T.%e][%t][%l][%n] [%g:%#] %v"); // options.logFormat() - // TODO(colibie) this doesnt work. Why? - // Logger::Context logging_state(options.logLevel(), options.logFormat(), lock, false, - // options.enableFineGrainLogging()); - } + // TODO(colibie) this doesnt work. Why? + // Logger::Context logging_state(options.logLevel(), options.logFormat(), lock, false, + // options.enableFineGrainLogging()); +} - Network::TransportSocketFactoryPtr QuicTestServer::createUpstreamTlsContext(testing::NiceMock& factory_context) { - envoy::extensions::transport_sockets::tls::v3::DownstreamTlsContext tls_context; - Extensions::TransportSockets::Tls::ContextManagerImpl context_manager_{time_system_}; +Network::TransportSocketFactoryPtr QuicTestServer::createUpstreamTlsContext( + testing::NiceMock& factory_context) { + envoy::extensions::transport_sockets::tls::v3::DownstreamTlsContext tls_context; + Extensions::TransportSockets::Tls::ContextManagerImpl context_manager_{time_system_}; - const std::string yaml = absl::StrFormat( - R"EOF( + const std::string yaml = absl::StrFormat( + R"EOF( common_tls_context: alpn_protocols: h3 tls_certificates: @@ -109,53 +110,71 @@ namespace Envoy { ie3qKR3an4KC20CtFbpZfv540BVuTTOCtQ5xqZ/LTE78 -----END CERTIFICATE----- )EOF"); - TestUtility::loadFromYaml(yaml, tls_context); - envoy::extensions::transport_sockets::quic::v3::QuicDownstreamTransport quic_config; - quic_config.mutable_downstream_tls_context()->MergeFrom(tls_context); - - std::vector server_names; - auto& config_factory = Config::Utility::getAndCheckFactoryByName< - Server::Configuration::DownstreamTransportSocketConfigFactory>( - "envoy.transport_sockets.quic"); - - return config_factory.createTransportSocketFactory(quic_config, factory_context, server_names); - } - - QuicTestServer::QuicTestServer() : api_(Api::createApiForTest(stats_store_, time_system_)), - version_(Network::Address::IpVersion::v4), - config_helper_(version_, *api_, ConfigHelper::baseConfig() + R"EOF( + TestUtility::loadFromYaml(yaml, tls_context); + envoy::extensions::transport_sockets::quic::v3::QuicDownstreamTransport quic_config; + quic_config.mutable_downstream_tls_context()->MergeFrom(tls_context); + + std::vector server_names; + auto& config_factory = Config::Utility::getAndCheckFactoryByName< + Server::Configuration::DownstreamTransportSocketConfigFactory>( + "envoy.transport_sockets.quic"); + + return config_factory.createTransportSocketFactory(quic_config, factory_context, server_names); +} + +QuicTestServer::QuicTestServer() + : api_(Api::createApiForTest(stats_store_, time_system_)), + version_(Network::Address::IpVersion::v4), + config_helper_(version_, *api_, ConfigHelper::baseConfig() + R"EOF( filter_chains: filters: - )EOF"){ - ON_CALL(factory_context_, api()).WillByDefault(testing::ReturnRef(*api_)); - ON_CALL(factory_context_, scope()).WillByDefault(testing::ReturnRef(stats_store_)); - - setup(); - } - - void QuicTestServer::startQuicTestServer() { - FakeUpstreamConfig upstream_config_{time_system_}; - upstream_config_.upstream_protocol_ = Http::CodecType::HTTP3; - upstream_config_.udp_fake_upstream_ = FakeUpstreamConfig::UdpConfig(); - - Network::TransportSocketFactoryPtr factory = createUpstreamTlsContext(factory_context_); // Network::Test::createRawBufferSocketFactory(); - - int port = 0; // let the kernel pick a port that is not in use (avoids test races) - aupstream = std::make_unique(std::move(factory), port, version_, upstream_config_, false); - - // see what port was selected. - std::cerr << "Upstream now listening on " << aupstream->localAddress()->asString() << "\n"; - - Logger::Registry::getSink()->clearLock(); - } - - void QuicTestServer::shutdownQuicTestServer() { - aupstream.reset(); -// FAIL() << "this way blaze will give you a test log"; - } - - int QuicTestServer::getServerPort() { - return aupstream->localAddress()->ip()->port(); - } + - name: envoy.filters.network.http_connection_manager + typed_config: + "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager + codec_type: HTTP3 + stat_prefix: remote_hcm + route_config: + name: remote_route + virtual_hosts: + - name: remote_service + domains: ["*"] + routes: + - match: { prefix: "/simple" } + direct_response: { status: 200 } + http3_protocol_options: + http_filters: + - name: envoy.router + typed_config: + "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router + )EOF") { + ON_CALL(factory_context_, api()).WillByDefault(testing::ReturnRef(*api_)); + ON_CALL(factory_context_, scope()).WillByDefault(testing::ReturnRef(stats_store_)); + + setup(); +} + +void QuicTestServer::startQuicTestServer() { + FakeUpstreamConfig upstream_config_{time_system_}; + upstream_config_.upstream_protocol_ = Http::CodecType::HTTP3; + upstream_config_.udp_fake_upstream_ = FakeUpstreamConfig::UdpConfig(); + + Network::TransportSocketFactoryPtr factory = + createUpstreamTlsContext(factory_context_); // Network::Test::createRawBufferSocketFactory(); + + int port = 0; // let the kernel pick a port that is not in use (avoids test races) + aupstream = std::make_unique(std::move(factory), port, version_, + upstream_config_, false); + + // see what port was selected. + std::cerr << "Upstream now listening on " << aupstream->localAddress()->asString() << "\n"; + + Logger::Registry::getSink()->clearLock(); +} + +void QuicTestServer::shutdownQuicTestServer() { + aupstream.reset(); + // FAIL() << "this way blaze will give you a test log"; +} + +int QuicTestServer::getServerPort() { return aupstream->localAddress()->ip()->port(); } } // namespace Envoy - diff --git a/test/common/integration/quic_test_server.h b/test/common/integration/quic_test_server.h index 5b1807bd7a..4e0db398aa 100644 --- a/test/common/integration/quic_test_server.h +++ b/test/common/integration/quic_test_server.h @@ -21,28 +21,29 @@ #include "test/test_common/network_utility.h" namespace Envoy { - class QuicTestServer { - private: - testing::NiceMock factory_context_; - Stats::IsolatedStoreImpl stats_store_; - Event::GlobalTimeSystem time_system_; - Api::ApiPtr api_; - Network::Address::IpVersion version_; - ConfigHelper config_helper_; - std::unique_ptr upstream; - std::unique_ptr aupstream; - - void setup(); - Network::TransportSocketFactoryPtr createUpstreamTlsContext(testing::NiceMock&); - - public: - QuicTestServer(); - - void startQuicTestServer(); - - void shutdownQuicTestServer(); - - int getServerPort(); - }; +class QuicTestServer { +private: + testing::NiceMock factory_context_; + Stats::IsolatedStoreImpl stats_store_; + Event::GlobalTimeSystem time_system_; + Api::ApiPtr api_; + Network::Address::IpVersion version_; + ConfigHelper config_helper_; + std::unique_ptr upstream; + std::unique_ptr aupstream; + + void setup(); + Network::TransportSocketFactoryPtr createUpstreamTlsContext( + testing::NiceMock&); + +public: + QuicTestServer(); + + void startQuicTestServer(); + + void shutdownQuicTestServer(); + + int getServerPort(); +}; } // namespace Envoy \ No newline at end of file diff --git a/test/common/integration/quic_test_server_interface.cc b/test/common/integration/quic_test_server_interface.cc index 3c3008c34a..09e33e9138 100644 --- a/test/common/integration/quic_test_server_interface.cc +++ b/test/common/integration/quic_test_server_interface.cc @@ -15,7 +15,7 @@ void start_server() { quic_test_server_ = strong_quic_test_server_; if (auto e = quic_test_server()) { - e->startQuicTestServer(); + e->startQuicTestServer(); } } diff --git a/test/common/integration/quic_test_server_interface.h b/test/common/integration/quic_test_server_interface.h index 06ac960f64..decb3e3d4d 100644 --- a/test/common/integration/quic_test_server_interface.h +++ b/test/common/integration/quic_test_server_interface.h @@ -1,6 +1,7 @@ #pragma once #include "test/common/integration/quic_test_server.h" + // NOLINT(namespace-envoy) #ifdef __cplusplus diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index 280de77aa9..87c051b591 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -1,6 +1,4 @@ -load("//bazel:kotlin_lib.bzl", "envoy_mobile_so_to_jni_lib") -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") -load("@envoy//bazel:envoy_build_system.bzl", "envoy_cc_library", "envoy_package") +load("@envoy//bazel:envoy_build_system.bzl", "envoy_package") licenses(["notice"]) # Apache 2 diff --git a/test/common/jni/quic_test_server_jni_interface.cc b/test/common/jni/quic_test_server_jni_interface.cc index 600d018b7b..25820bccc3 100644 --- a/test/common/jni/quic_test_server_jni_interface.cc +++ b/test/common/jni/quic_test_server_jni_interface.cc @@ -1,36 +1,34 @@ #include +#include "test/common/integration/quic_test_server_interface.h" + #include "library/common/jni/jni_support.h" #include "library/common/jni/jni_utility.h" #include "library/common/jni/jni_version.h" -#include "test/common/integration/quic_test_server_interface.h" - // Quic Test ServerJniLibrary +// NOLINT(namespace-envoy) -extern "C" JNIEXPORT void JNICALL Java_org_chromium_net_testing_QuicTestServer_nativeStartQuicTestServer(JNIEnv * env, - jclass clazz, - jstring file_path, - jstring test_data_dir) { +extern "C" JNIEXPORT void JNICALL +Java_org_chromium_net_testing_QuicTestServer_nativeStartQuicTestServer(JNIEnv* env, jclass clazz, + jstring file_path, + jstring test_data_dir) { // TODO: implement nativeStartQuicTestServer() jni_log("[QTS]", "starting server"); start_server(); } -extern "C" JNIEXPORT jint -JNICALL -Java_org_chromium_net_testing_QuicTestServer_nativeGetServerPort(JNIEnv* env, - jclass clazz) { +extern "C" JNIEXPORT jint JNICALL +Java_org_chromium_net_testing_QuicTestServer_nativeGetServerPort(JNIEnv* env, jclass clazz) { // TODO: implement nativeGetServerPort() jni_log("[QTS]", "getting server port"); return get_server_port(); } - extern "C" JNIEXPORT void JNICALL -Java_org_chromium_net_testing_QuicTestServer_nativeShutdownQuicTestServer(JNIEnv * env, +Java_org_chromium_net_testing_QuicTestServer_nativeShutdownQuicTestServer(JNIEnv* env, jclass clazz) { -// TODO: implement nativeShutdownQuicTestServer() -jni_log("[QTS]", "shutting down server"); + // TODO: implement nativeShutdownQuicTestServer() + jni_log("[QTS]", "shutting down server"); shutdown_server(); } \ No newline at end of file diff --git a/test/java/org/chromium/net/QuicTest.java b/test/java/org/chromium/net/QuicTest.java index c20e6bb329..d3963adb3c 100644 --- a/test/java/org/chromium/net/QuicTest.java +++ b/test/java/org/chromium/net/QuicTest.java @@ -13,7 +13,6 @@ import org.chromium.net.testing.CronetTestRule; import org.chromium.net.testing.CronetTestUtil; import org.chromium.net.testing.QuicTestServer; -import org.chromium.net.testing.QuicTestServerA; import org.chromium.net.testing.TestUrlRequestCallback; import org.json.JSONObject; import org.junit.After; @@ -93,6 +92,7 @@ public void tearDown() throws Exception { public void testQuicLoadUrl() throws Exception { ExperimentalCronetEngine cronetEngine = mBuilder.build(); String quicURL = QuicTestServer.getServerURL(); + Thread.sleep(100000); TestUrlRequestCallback callback = new TestUrlRequestCallback(); // Although the native stack races QUIC and SPDY for the first request, // since there is no http server running on the corresponding TCP port, diff --git a/test/java/org/chromium/net/testing/BUILD b/test/java/org/chromium/net/testing/BUILD index ca09988b55..4c93d3bd0f 100644 --- a/test/java/org/chromium/net/testing/BUILD +++ b/test/java/org/chromium/net/testing/BUILD @@ -64,3 +64,24 @@ envoy_mobile_android_test( "//library/kotlin/io/envoyproxy/envoymobile:envoy_lib", ], ) + +envoy_mobile_android_test( + name = "quic_test_server_test", + srcs = [ + "QuicTestServerTest.java", + ], + library_path = "library/common/jni:test/common/jni", + native_deps = [ + "//library/common/jni:libndk_envoy_jni.so", + "//library/common/jni:libndk_envoy_jni.jnilib", + "//test/common/jni:libquic_test_server_jni.so", + ], + deps = [ + ":testing", + "//library/java/io/envoyproxy/envoymobile/engine:envoy_base_engine_lib", + "//library/java/io/envoyproxy/envoymobile/engine:envoy_engine_lib", + "//library/java/org/chromium/net/impl:cronvoy", + "//library/kotlin/io/envoyproxy/envoymobile:envoy_interfaces_lib", + "//library/kotlin/io/envoyproxy/envoymobile:envoy_lib", + ], +) diff --git a/test/java/org/chromium/net/testing/QuicTestServerTest.java b/test/java/org/chromium/net/testing/QuicTestServerTest.java new file mode 100644 index 0000000000..d17bea3860 --- /dev/null +++ b/test/java/org/chromium/net/testing/QuicTestServerTest.java @@ -0,0 +1,409 @@ +package org.chromium.net.testing; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.chromium.net.testing.CronetTestRule.getContext; + +import io.envoyproxy.envoymobile.AndroidEngineBuilder; +import io.envoyproxy.envoymobile.Custom; +import io.envoyproxy.envoymobile.Engine; +import io.envoyproxy.envoymobile.EnvoyError; +import io.envoyproxy.envoymobile.RequestHeaders; +import io.envoyproxy.envoymobile.RequestHeadersBuilder; +import io.envoyproxy.envoymobile.RequestMethod; +import io.envoyproxy.envoymobile.ResponseHeaders; +import io.envoyproxy.envoymobile.ResponseTrailers; +import io.envoyproxy.envoymobile.Stream; +import io.envoyproxy.envoymobile.engine.AndroidJniLibrary; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.ByteBuffer; +import java.util.AbstractMap.SimpleImmutableEntry; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; + +@RunWith(RobolectricTestRunner.class) +public class QuicTestServerTest { + private static String hcmType = "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager"; + + private static String quicDownstreamType = "type.googleapis.com/envoy.extensions.transport_sockets.quic.v3.QuicDownstreamTransport"; + + private static String quicUpstreamType = "type.googleapis.com/envoy.extensions.transport_sockets.quic.v3.QuicUpstreamTransport"; + private static String config = + "static_resources:\n" + + " listeners:\n" + + " - name: h3_remote_listener\n" + + " address:\n" + + " socket_address: { protocol: UDP, address: 127.0.0.1, port_value: 10101 }\n" + + " reuse_port: true\n" + + " udp_listener_config:\n" + + " quic_options: {}\n" + + " downstream_socket_config:\n" + + " prefer_gro: true\n" + + " filter_chains:\n" + + " transport_socket:\n" + + " name: envoy.transport_sockets.quic\n" + + " typed_config:\n" + + " \"@type\": " + quicDownstreamType + "\n" + + " downstream_tls_context:\n" + + " common_tls_context:\n" + + " alpn_protocols: h3\n" + + " tls_certificates:\n" + + " certificate_chain:\n" + + " inline_string: |\n" + + " -----BEGIN CERTIFICATE-----\n" + + " MIIEbDCCA1SgAwIBAgIUJuVBh0FKfFgIcO++ljWm7D47eYUwDQYJKoZIhvcNAQEL\n" + + " BQAwdjELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcM\n" + + " DVNhbiBGcmFuY2lzY28xDTALBgNVBAoMBEx5ZnQxGTAXBgNVBAsMEEx5ZnQgRW5n\n" + + " aW5lZXJpbmcxEDAOBgNVBAMMB1Rlc3QgQ0EwHhcNMjAwODA1MTkxNjAxWhcNMjIw\n" + + " ODA1MTkxNjAxWjCBpjELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWEx\n" + + " FjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xDTALBgNVBAoMBEx5ZnQxGTAXBgNVBAsM\n" + + " EEx5ZnQgRW5naW5lZXJpbmcxGjAYBgNVBAMMEVRlc3QgQmFja2VuZCBUZWFtMSQw\n" + + " IgYJKoZIhvcNAQkBFhViYWNrZW5kLXRlYW1AbHlmdC5jb20wggEiMA0GCSqGSIb3\n" + + " DQEBAQUAA4IBDwAwggEKAoIBAQC9JgaI7hxjPM0tsUna/QmivBdKbCrLnLW9Teak\n" + + " RH/Ebg68ovyvrRIlybDT6XhKi+iVpzVY9kqxhGHgrFDgGLBakVMiYJ5EjIgHfoo4\n" + + " UUAHwIYbunJluYCgANzpprBsvTC/yFYDVMqUrjvwHsoYYVm36io994k9+t813b70\n" + + " o0l7/PraBsKkz8NcY2V2mrd/yHn/0HAhv3hl6iiJme9yURuDYQrae2ACSrQtsbel\n" + + " KwdZ/Re71Z1awz0OQmAjMa2HuCop+Q/1QLnqBekT5+DH1qKUzJ3Jkq6NRkERXOpi\n" + + " 87j04rtCBteCogrO67qnuBZ2lH3jYEMb+lQdLkyNMLltBSdLAgMBAAGjgcAwgb0w\n" + + " DAYDVR0TAQH/BAIwADALBgNVHQ8EBAMCBeAwHQYDVR0lBBYwFAYIKwYBBQUHAwIG\n" + + " CCsGAQUFBwMBMEEGA1UdEQQ6MDiGHnNwaWZmZTovL2x5ZnQuY29tL2JhY2tlbmQt\n" + + " dGVhbYIIbHlmdC5jb22CDHd3dy5seWZ0LmNvbTAdBgNVHQ4EFgQU2XcTZbc0xKZf\n" + + " gNVKSvAbMZJCBoYwHwYDVR0jBBgwFoAUlkvaLFO0vpXGk3Pip6SfLg1yGIcwDQYJ\n" + + " KoZIhvcNAQELBQADggEBAFW05aca3hSiEz/g593GAV3XP4lI5kYUjGjbPSy/HmLr\n" + + " rdv/u3bGfacywAPo7yld+arMzd35tIYEqnhoq0+/OxPeyhwZXVVUatg5Oknut5Zv\n" + + " 2+8l+mVW+8oFCXRqr2gwc8Xt4ByYN+HaNUYfoucnjDplOPukkfSuRhbxqnkhA14v\n" + + " Lri2EbISX14sXf2VQ9I0dkm1hXUxiO0LlA1Z7tvJac9zPSoa6Oljke4D1iH2jzwF\n" + + " Yn7S/gGvVQgkTmWrs3S3TGyBDi4GTDhCF1R+ESvXz8z4UW1MrCSdYUXbRtsT7sbE\n" + + " CjlFYuUyxCi1oe3IHCeXVDo/bmzwGQPDuF3WaDNSYWU=\n" + + " -----END CERTIFICATE-----\n" + + " private_key:\n" + + " inline_string: |\n" + + " -----BEGIN RSA PRIVATE KEY-----\n" + + " MIIEpAIBAAKCAQEAvSYGiO4cYzzNLbFJ2v0JorwXSmwqy5y1vU3mpER/xG4OvKL8\n" + + " r60SJcmw0+l4Sovolac1WPZKsYRh4KxQ4BiwWpFTImCeRIyIB36KOFFAB8CGG7py\n" + + " ZbmAoADc6aawbL0wv8hWA1TKlK478B7KGGFZt+oqPfeJPfrfNd2+9KNJe/z62gbC\n" + + " pM/DXGNldpq3f8h5/9BwIb94ZeooiZnvclEbg2EK2ntgAkq0LbG3pSsHWf0Xu9Wd\n" + + " WsM9DkJgIzGth7gqKfkP9UC56gXpE+fgx9ailMydyZKujUZBEVzqYvO49OK7QgbX\n" + + " gqIKzuu6p7gWdpR942BDG/pUHS5MjTC5bQUnSwIDAQABAoIBADEMwlcSAFSPuNln\n" + + " hzJ9udj0k8md4T8p5Usw/2WLyeJDdBjg30wjQniAJBXgDmyueWMNmFz4iYgdP1CG\n" + + " /vYOEPV7iCZ7Da/TDZd77hYKo+MevuhD4lSU1VEoyCDjNA8OxKyHJB77BwmlYS+0\n" + + " nE3UOPLji47EOVfUTbvnRBSmn3DCSHkQiRIUP1xMivoiZgKJn+D+FxSMwwiq2pQR\n" + + " 5tdo7nh2A8RxlYUbaD6i4poUB26HVm8vthXahNEkLpXQOz8MWRzs6xOdDHRzi9kT\n" + + " ItRLa4A/3LIATqviQ2EpwcALHXcULcNUMTHORC1EHPvheWR5nLuRllYzN4ReoeHC\n" + + " 3+A5KEkCgYEA52rlh/22/rLckCWugjyJic17vkg46feSOGhjuP2LelrIxNlg491y\n" + + " o28n8lQPSVnEp3/sT7Y3quVvdboq4DC9LTzq52f6/mCYh9UQRpljuSmFqC2MPG46\n" + + " Zl5KLEVLzhjC8aTWkhVINSpz9vauXderOpFYlPW32lnRTjJWE276kj8CgYEA0T2t\n" + + " ULnn7TBvRSpmeWzEBA5FFo2QYkYvwrcVe0pfUltV6pf05xUmMXYFjpezSTEmPhh6\n" + + " +dZdhwxDk+6j8Oo61rTWucDsIqMj5ZT1hPNph8yQtb5LRlRbLGVrirU9Tp7xTgMq\n" + + " 3uRA2Eka1d98dDBsEbMIVFSZ2MX3iezSGRL6j/UCgYEAxZQ82HjEDn2DVwb1EXjC\n" + + " LQdliTZ8cTXQf5yQ19aRiSuNkpPN536ga+1xe7JNQuEDx8auafg3Ww98tFT4WmUC\n" + + " f2ctX9klMJ4kXISK2twHioVq+gW5X7b04YXLajTX3eTCPDHyiNLmzY2raMWAZdrG\n" + + " 9MA3kyafjCt3Sn4rg3gTM10CgYEAtJ8WRpJEd8aQttcUIItYZdvfnclUMtE9l0su\n" + + " GwCnalN3xguol/X0w0uLHn0rgeoQhhfhyFtY3yQiDcg58tRvODphBXZZIMlNSnic\n" + + " vEjW9ygKXyjGmA5nqdpezB0JsB2aVep8Dm5g35Ozu52xNCc8ksbGUO265Jp3xbMN\n" + + " 5iEw9CUCgYBmfoPnJwzA5S1zMIqESUdVH6p3UwHU/+XTY6JHAnEVsE+BuLe3ioi7\n" + + " 6dU4rFd845MCkunBlASLV8MmMbod9xU0vTVHPtmANaUCPxwUIxXQket09t19Dzg7\n" + + " A23sE+5myXtcfz6YrPhbLkijV4Nd7fmecodwDckvpBaWTMrv52/Www==\n" + + " -----END RSA PRIVATE KEY-----\n" + + " filters:\n" + + " - name: envoy.filters.network.http_connection_manager\n" + + " typed_config:\n" + + " \"@type\": "+ hcmType + "\n" + + " codec_type: HTTP3\n" + + " stat_prefix: remote_hcm\n" + + " route_config:\n" + + " name: remote_route\n" + + " virtual_hosts:\n" + + " - name: remote_service\n" + + " domains: [\"*\"]\n" + + " routes:\n" + + " - match: { prefix: \"/\" }\n" + + " direct_response: { status: 200 }\n" + + " http3_protocol_options:\n" + + " http_filters:\n" + + " - name: envoy.router\n" + + " typed_config:\n" + + " \"@type\": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router\n" + + " - name: base_api_listener\n" + + " address:\n" + + " socket_address: { protocol: TCP, address: 0.0.0.0, port_value: 10000 }\n" + + " api_listener:\n" + + " api_listener:\n" + + " \"@type\": " + hcmType + "\n" + + " stat_prefix: api_hcm\n" + + " route_config:\n" + + " name: api_router\n" + + " virtual_hosts:\n" + + " - name: api\n" + + " domains: [\"*\"]\n" + + " routes:\n" + + " - match: { prefix: \"/\" }\n" + + " route: { host_rewrite_literal: example.com, cluster: h3_remote }\n" + + " http_filters:\n" + + " - name: envoy.router\n" + + " typed_config:\n" + + " \"@type\": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router\n" + + " clusters:\n" + + " - name: h3_remote\n" + + " connect_timeout: 10s\n" + + " type: STATIC\n" + + " dns_lookup_family: V4_ONLY\n" + + " lb_policy: ROUND_ROBIN\n" + + " load_assignment:\n" + + " cluster_name: h3_remote\n" + + " endpoints:\n" + + " - lb_endpoints:\n" + + " - endpoint:\n" + + " address:\n" + + " socket_address: { address: 127.0.0.1, port_value: 10101 }\n" + + " typed_extension_protocol_options:\n" + + " envoy.extensions.upstreams.http.v3.HttpProtocolOptions:\n" + + " \"@type\": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions\n" + + " explicit_http_config:\n" + + " http3_protocol_options: {}\n" + + " common_http_protocol_options:\n" + + " idle_timeout: 1s\n" + + " transport_socket:\n" + + " name: envoy.transport_sockets.quic\n" + + " typed_config:\n" + + " \"@type\": " + quicUpstreamType + "\n" + + " upstream_tls_context:\n" + + " sni: example.com"; + + private static Engine engine; + + @BeforeClass + public static void loadJniLibrary() { + AndroidJniLibrary.loadTestLibrary(); + System.loadLibrary("quic_test_server_jni"); + } + + @AfterClass + public static void shutdownEngine() { + if (engine != null) { + engine.terminate(); + } + } + + @Before + public void setUpEngine() throws Exception { + if (engine == null) { + CountDownLatch latch = new CountDownLatch(1); + engine = new AndroidEngineBuilder(getContext().getApplicationContext(), new Custom(config)) + .setOnEngineRunning(() -> { + latch.countDown(); + return null; + }) + .build(); + latch.await(); // Don't launch a request before initialization has completed. + } + } + + @After + public void shutdownMockWebServer() throws IOException { + QuicTestServer.shutdownQuicTestServer(); + } + + @Test + public void get_simple() throws Exception { + QuicTestServer.startQuicTestServer(getContext()); + QuicTestServerTest.RequestScenario requestScenario = new QuicTestServerTest.RequestScenario() + .setHttpMethod(RequestMethod.GET) + .setUrl(QuicTestServer.getServerURL()); + + QuicTestServerTest.Response response = sendRequest(requestScenario); + + assertThat(response.getHeaders().getHttpStatus()).isEqualTo(200); + assertThat(response.getBodyAsString()).isEqualTo("hello, world"); + assertThat(response.getEnvoyError()).isNull(); + } + + private QuicTestServerTest.Response sendRequest( + QuicTestServerTest.RequestScenario requestScenario) throws Exception { + final CountDownLatch latch = new CountDownLatch(1); + final AtomicReference response = new AtomicReference<>(new QuicTestServerTest.Response()); + + Stream stream = engine.streamClient() + .newStreamPrototype() + .setOnResponseHeaders((responseHeaders, endStream, ignored) -> { + response.get().setHeaders(responseHeaders); + if (endStream) { + latch.countDown(); + } + return null; + }) + .setOnResponseData((data, endStream, ignored) -> { + response.get().addBody(data); + if (endStream) { + latch.countDown(); + } + return null; + }) + .setOnResponseTrailers((trailers, ignored) -> { + response.get().setTrailers(trailers); + latch.countDown(); + return null; + }) + .setOnError((error, ignored) -> { + response.get().setEnvoyError(error); + latch.countDown(); + return null; + }) + .setOnCancel((ignored) -> { + response.get().setCancelled(); + latch.countDown(); + return null; + }) + .start(Executors.newSingleThreadExecutor()) + .sendHeaders(requestScenario.getHeaders(), !requestScenario.hasBody()); + requestScenario.getBodyChunks().forEach(stream::sendData); + requestScenario.getClosingBodyChunk().ifPresent(stream::close); + + latch.await(); + response.get().throwAssertionErrorIfAny(); + return response.get(); + } + + private static class RequestScenario { + private URL url; + private RequestMethod method = null; + private final List bodyChunks = new ArrayList<>(); + private final List> headers = new ArrayList<>(); + private boolean closeBodyStream = false; + + RequestHeaders getHeaders() { + RequestHeadersBuilder requestHeadersBuilder = + new RequestHeadersBuilder(method, url.getProtocol(), url.getAuthority(), url.getPath()); + headers.forEach(entry -> requestHeadersBuilder.add(entry.getKey(), entry.getValue())); + // HTTP1 is the only way to send HTTP requests (not HTTPS) + return requestHeadersBuilder.build(); + } + + List getBodyChunks() { + return closeBodyStream + ? Collections.unmodifiableList(bodyChunks.subList(0, bodyChunks.size() - 1)) + : Collections.unmodifiableList(bodyChunks); + } + + Optional getClosingBodyChunk() { + return closeBodyStream ? Optional.of(bodyChunks.get(bodyChunks.size() - 1)) + : Optional.empty(); + } + + boolean hasBody() { return !bodyChunks.isEmpty(); } + + QuicTestServerTest.RequestScenario setHttpMethod(RequestMethod requestMethod) { + this.method = requestMethod; + return this; + } + + QuicTestServerTest.RequestScenario setUrl(String url) throws MalformedURLException { + this.url = new URL(url); + return this; + } + + QuicTestServerTest.RequestScenario addBody(byte[] requestBodyChunk) { + ByteBuffer byteBuffer = ByteBuffer.allocateDirect(requestBodyChunk.length); + byteBuffer.put(requestBodyChunk); + bodyChunks.add(byteBuffer); + return this; + } + + QuicTestServerTest.RequestScenario addBody(String requestBodyChunk) { + return addBody(requestBodyChunk.getBytes()); + } + + QuicTestServerTest.RequestScenario addHeader(String key, String value) { + headers.add(new SimpleImmutableEntry<>(key, value)); + return this; + } + + QuicTestServerTest.RequestScenario closeBodyStream() { + closeBodyStream = true; + return this; + } + } + + private static class Response { + private final AtomicReference headers = new AtomicReference<>(); + private final AtomicReference trailers = new AtomicReference<>(); + private final AtomicReference envoyError = new AtomicReference<>(); + private final List bodies = new ArrayList<>(); + private final AtomicBoolean cancelled = new AtomicBoolean(false); + private final AtomicReference assertionError = new AtomicReference<>(); + + void setHeaders(ResponseHeaders headers) { + if (!this.headers.compareAndSet(null, headers)) { + assertionError.compareAndSet( + null, new AssertionError("setOnResponseHeaders called more than once.")); + } + } + + void addBody(ByteBuffer body) { bodies.add(body); } + + void setTrailers(ResponseTrailers trailers) { + if (!this.trailers.compareAndSet(null, trailers)) { + assertionError.compareAndSet( + null, new AssertionError("setOnResponseTrailers called more than once.")); + } + } + + void setEnvoyError(EnvoyError envoyError) { + if (!this.envoyError.compareAndSet(null, envoyError)) { + assertionError.compareAndSet(null, new AssertionError("setOnError called more than once.")); + } + } + + void setCancelled() { + if (!cancelled.compareAndSet(false, true)) { + assertionError.compareAndSet(null, + new AssertionError("setOnCancel called more than once.")); + } + } + + EnvoyError getEnvoyError() { return envoyError.get(); } + + ResponseHeaders getHeaders() { return headers.get(); } + + ResponseTrailers getTrailers() { return trailers.get(); } + + boolean isCancelled() { return cancelled.get(); } + + String getBodyAsString() { + int totalSize = bodies.stream().mapToInt(ByteBuffer::limit).sum(); + byte[] body = new byte[totalSize]; + int pos = 0; + for (ByteBuffer buffer : bodies) { + int bytesToRead = buffer.limit(); + buffer.get(body, pos, bytesToRead); + pos += bytesToRead; + } + return new String(body); + } + + int getNbResponseChunks() { return bodies.size(); } + + void throwAssertionErrorIfAny() { + if (assertionError.get() != null) { + throw assertionError.get(); + } + } + } +} + + From a49baf9e06bfc59e4e45509538a83eac282f4db0 Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Tue, 7 Sep 2021 16:38:55 +0000 Subject: [PATCH 05/54] [WIP] quicTestServerTest Signed-off-by: Chidera Olibie --- test/java/org/chromium/net/QuicTest.java | 28 +- .../chromium/net/testing/CronetTestUtil.java | 13 +- .../chromium/net/testing/QuicTestServer.java | 16 +- .../net/testing/QuicTestServerTest.java | 417 +++++++++--------- 4 files changed, 220 insertions(+), 254 deletions(-) diff --git a/test/java/org/chromium/net/QuicTest.java b/test/java/org/chromium/net/QuicTest.java index d3963adb3c..2fb6c543ee 100644 --- a/test/java/org/chromium/net/QuicTest.java +++ b/test/java/org/chromium/net/QuicTest.java @@ -38,8 +38,7 @@ */ @RunWith(AndroidJUnit4.class) public class QuicTest { - @Rule - public final CronetTestRule mTestRule = new CronetTestRule(); + @Rule public final CronetTestRule mTestRule = new CronetTestRule(); private static final String TAG = QuicTest.class.getSimpleName(); private ExperimentalCronetEngine.Builder mBuilder; @@ -117,32 +116,29 @@ public void testQuicLoadUrl() throws Exception { Thread.sleep(10000); boolean contains = false; try { - if (fileContainsString("local_prefs.json", "quic")) break; + if (fileContainsString("local_prefs.json", "quic")) + break; } catch (FileNotFoundException e) { // Ignored this exception since the file will only be created when updates are // flushed to the disk. } } - assertTrue(fileContainsString("local_prefs.json", - QuicTestServer.getServerHost() + ":" + QuicTestServer.getServerPort())); + assertTrue(fileContainsString("local_prefs.json", QuicTestServer.getServerHost() + ":" + + QuicTestServer.getServerPort())); cronetEngine.shutdown(); // Make another request using a new context but with no QUIC hints. - ExperimentalCronetEngine.Builder builder = - new ExperimentalCronetEngine.Builder(getContext()); + ExperimentalCronetEngine.Builder builder = new ExperimentalCronetEngine.Builder(getContext()); builder.setStoragePath(getTestStorage()); builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK, 1000 * 1024); builder.enableQuic(true); JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules(); - JSONObject experimentalOptions = new JSONObject() - .put("HostResolverRules", hostResolverParams); + JSONObject experimentalOptions = new JSONObject().put("HostResolverRules", hostResolverParams); builder.setExperimentalOptions(experimentalOptions.toString()); - CronetTestUtil.setMockCertVerifierForTesting( - builder, QuicTestServer.createMockCertVerifier()); + CronetTestUtil.setMockCertVerifierForTesting(builder, QuicTestServer.createMockCertVerifier()); cronetEngine = builder.build(); TestUrlRequestCallback callback2 = new TestUrlRequestCallback(); - requestBuilder = - cronetEngine.newUrlRequestBuilder(quicURL, callback2, callback2.getExecutor()); + requestBuilder = cronetEngine.newUrlRequestBuilder(quicURL, callback2, callback2.getExecutor()); requestBuilder.build().start(); callback2.blockForDone(); assertEquals(200, callback2.mResponseInfo.getHttpStatusCode()); @@ -158,7 +154,7 @@ public void testQuicLoadUrl() throws Exception { private boolean fileContainsString(String filename, String content) throws IOException { File file = new File(getTestStorage() + "/prefs/" + filename); FileInputStream fileInputStream = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; + byte[] data = new byte[(int)file.length()]; fileInputStream.read(data); fileInputStream.close(); return new String(data, "UTF-8").contains(content); @@ -299,7 +295,7 @@ private boolean fileContainsString(String filename, String content) throws IOExc // Helper method to assert that the request is negotiated over QUIC. private void assertIsQuic(UrlResponseInfo responseInfo) { - assertTrue(responseInfo.getNegotiatedProtocol().startsWith("http/2+quic") - || responseInfo.getNegotiatedProtocol().startsWith("h3")); + assertTrue(responseInfo.getNegotiatedProtocol().startsWith("http/2+quic") || + responseInfo.getNegotiatedProtocol().startsWith("h3")); } } diff --git a/test/java/org/chromium/net/testing/CronetTestUtil.java b/test/java/org/chromium/net/testing/CronetTestUtil.java index 4de7434627..13198fa549 100644 --- a/test/java/org/chromium/net/testing/CronetTestUtil.java +++ b/test/java/org/chromium/net/testing/CronetTestUtil.java @@ -54,7 +54,7 @@ public static class NetworkThreadTestConnector { private final CronetUrlRequestContext mRequestContext; public NetworkThreadTestConnector(CronetEngine cronetEngine) { - mRequestContext = (CronetUrlRequestContext) cronetEngine; + mRequestContext = (CronetUrlRequestContext)cronetEngine; // nativePrepareNetworkThread(mRequestContext.getUrlRequestContextAdapter()); } @@ -72,14 +72,13 @@ public static int getLoadFlags(UrlRequest urlRequest) { return 0; } - public static void setMockCertVerifierForTesting( - ExperimentalCronetEngine.Builder builder, long mockCertVerifier) { + public static void setMockCertVerifierForTesting(ExperimentalCronetEngine.Builder builder, + long mockCertVerifier) { getCronetEngineBuilderImpl(builder).setMockCertVerifierForTesting(mockCertVerifier); } - public static CronetEngineBuilderImpl getCronetEngineBuilderImpl( - ExperimentalCronetEngine.Builder builder) { - return (CronetEngineBuilderImpl) builder.getBuilderDelegate(); + public static CronetEngineBuilderImpl + getCronetEngineBuilderImpl(ExperimentalCronetEngine.Builder builder) { + return (CronetEngineBuilderImpl)builder.getBuilderDelegate(); } } - diff --git a/test/java/org/chromium/net/testing/QuicTestServer.java b/test/java/org/chromium/net/testing/QuicTestServer.java index 267ffec7a3..8ef2490f46 100644 --- a/test/java/org/chromium/net/testing/QuicTestServer.java +++ b/test/java/org/chromium/net/testing/QuicTestServer.java @@ -26,8 +26,8 @@ public static void startQuicTestServer(Context context) { throw new IllegalStateException("Quic server is already running"); } TestFilesInstaller.installIfNeeded(context); - nativeStartQuicTestServer( - TestFilesInstaller.getInstalledPath(context), UrlUtils.getIsolatedTestRoot()); + nativeStartQuicTestServer(TestFilesInstaller.getInstalledPath(context), + UrlUtils.getIsolatedTestRoot()); // sBlock.block(); // sBlock.close(); @@ -54,17 +54,11 @@ public static String getServerHost() { return "127.0.0.1"; } - public static int getServerPort() { - return nativeGetServerPort(); - } + public static int getServerPort() { return nativeGetServerPort(); } - public static final String getServerCert() { - return CERT_USED; - } + public static final String getServerCert() { return CERT_USED; } - public static final String getServerCertKey() { - return KEY_USED; - } + public static final String getServerCertKey() { return KEY_USED; } public static long createMockCertVerifier() { TestFilesInstaller.installIfNeeded(ContextUtils.getApplicationContext()); diff --git a/test/java/org/chromium/net/testing/QuicTestServerTest.java b/test/java/org/chromium/net/testing/QuicTestServerTest.java index d17bea3860..8cbea1e0ab 100644 --- a/test/java/org/chromium/net/testing/QuicTestServerTest.java +++ b/test/java/org/chromium/net/testing/QuicTestServerTest.java @@ -38,152 +38,157 @@ @RunWith(RobolectricTestRunner.class) public class QuicTestServerTest { - private static String hcmType = "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager"; - - private static String quicDownstreamType = "type.googleapis.com/envoy.extensions.transport_sockets.quic.v3.QuicDownstreamTransport"; - - private static String quicUpstreamType = "type.googleapis.com/envoy.extensions.transport_sockets.quic.v3.QuicUpstreamTransport"; - private static String config = - "static_resources:\n" + - " listeners:\n" + - " - name: h3_remote_listener\n" + - " address:\n" + - " socket_address: { protocol: UDP, address: 127.0.0.1, port_value: 10101 }\n" + - " reuse_port: true\n" + - " udp_listener_config:\n" + - " quic_options: {}\n" + - " downstream_socket_config:\n" + - " prefer_gro: true\n" + - " filter_chains:\n" + - " transport_socket:\n" + - " name: envoy.transport_sockets.quic\n" + - " typed_config:\n" + - " \"@type\": " + quicDownstreamType + "\n" + - " downstream_tls_context:\n" + - " common_tls_context:\n" + - " alpn_protocols: h3\n" + - " tls_certificates:\n" + - " certificate_chain:\n" + - " inline_string: |\n" + - " -----BEGIN CERTIFICATE-----\n" + - " MIIEbDCCA1SgAwIBAgIUJuVBh0FKfFgIcO++ljWm7D47eYUwDQYJKoZIhvcNAQEL\n" + - " BQAwdjELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcM\n" + - " DVNhbiBGcmFuY2lzY28xDTALBgNVBAoMBEx5ZnQxGTAXBgNVBAsMEEx5ZnQgRW5n\n" + - " aW5lZXJpbmcxEDAOBgNVBAMMB1Rlc3QgQ0EwHhcNMjAwODA1MTkxNjAxWhcNMjIw\n" + - " ODA1MTkxNjAxWjCBpjELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWEx\n" + - " FjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xDTALBgNVBAoMBEx5ZnQxGTAXBgNVBAsM\n" + - " EEx5ZnQgRW5naW5lZXJpbmcxGjAYBgNVBAMMEVRlc3QgQmFja2VuZCBUZWFtMSQw\n" + - " IgYJKoZIhvcNAQkBFhViYWNrZW5kLXRlYW1AbHlmdC5jb20wggEiMA0GCSqGSIb3\n" + - " DQEBAQUAA4IBDwAwggEKAoIBAQC9JgaI7hxjPM0tsUna/QmivBdKbCrLnLW9Teak\n" + - " RH/Ebg68ovyvrRIlybDT6XhKi+iVpzVY9kqxhGHgrFDgGLBakVMiYJ5EjIgHfoo4\n" + - " UUAHwIYbunJluYCgANzpprBsvTC/yFYDVMqUrjvwHsoYYVm36io994k9+t813b70\n" + - " o0l7/PraBsKkz8NcY2V2mrd/yHn/0HAhv3hl6iiJme9yURuDYQrae2ACSrQtsbel\n" + - " KwdZ/Re71Z1awz0OQmAjMa2HuCop+Q/1QLnqBekT5+DH1qKUzJ3Jkq6NRkERXOpi\n" + - " 87j04rtCBteCogrO67qnuBZ2lH3jYEMb+lQdLkyNMLltBSdLAgMBAAGjgcAwgb0w\n" + - " DAYDVR0TAQH/BAIwADALBgNVHQ8EBAMCBeAwHQYDVR0lBBYwFAYIKwYBBQUHAwIG\n" + - " CCsGAQUFBwMBMEEGA1UdEQQ6MDiGHnNwaWZmZTovL2x5ZnQuY29tL2JhY2tlbmQt\n" + - " dGVhbYIIbHlmdC5jb22CDHd3dy5seWZ0LmNvbTAdBgNVHQ4EFgQU2XcTZbc0xKZf\n" + - " gNVKSvAbMZJCBoYwHwYDVR0jBBgwFoAUlkvaLFO0vpXGk3Pip6SfLg1yGIcwDQYJ\n" + - " KoZIhvcNAQELBQADggEBAFW05aca3hSiEz/g593GAV3XP4lI5kYUjGjbPSy/HmLr\n" + - " rdv/u3bGfacywAPo7yld+arMzd35tIYEqnhoq0+/OxPeyhwZXVVUatg5Oknut5Zv\n" + - " 2+8l+mVW+8oFCXRqr2gwc8Xt4ByYN+HaNUYfoucnjDplOPukkfSuRhbxqnkhA14v\n" + - " Lri2EbISX14sXf2VQ9I0dkm1hXUxiO0LlA1Z7tvJac9zPSoa6Oljke4D1iH2jzwF\n" + - " Yn7S/gGvVQgkTmWrs3S3TGyBDi4GTDhCF1R+ESvXz8z4UW1MrCSdYUXbRtsT7sbE\n" + - " CjlFYuUyxCi1oe3IHCeXVDo/bmzwGQPDuF3WaDNSYWU=\n" + - " -----END CERTIFICATE-----\n" + - " private_key:\n" + - " inline_string: |\n" + - " -----BEGIN RSA PRIVATE KEY-----\n" + - " MIIEpAIBAAKCAQEAvSYGiO4cYzzNLbFJ2v0JorwXSmwqy5y1vU3mpER/xG4OvKL8\n" + - " r60SJcmw0+l4Sovolac1WPZKsYRh4KxQ4BiwWpFTImCeRIyIB36KOFFAB8CGG7py\n" + - " ZbmAoADc6aawbL0wv8hWA1TKlK478B7KGGFZt+oqPfeJPfrfNd2+9KNJe/z62gbC\n" + - " pM/DXGNldpq3f8h5/9BwIb94ZeooiZnvclEbg2EK2ntgAkq0LbG3pSsHWf0Xu9Wd\n" + - " WsM9DkJgIzGth7gqKfkP9UC56gXpE+fgx9ailMydyZKujUZBEVzqYvO49OK7QgbX\n" + - " gqIKzuu6p7gWdpR942BDG/pUHS5MjTC5bQUnSwIDAQABAoIBADEMwlcSAFSPuNln\n" + - " hzJ9udj0k8md4T8p5Usw/2WLyeJDdBjg30wjQniAJBXgDmyueWMNmFz4iYgdP1CG\n" + - " /vYOEPV7iCZ7Da/TDZd77hYKo+MevuhD4lSU1VEoyCDjNA8OxKyHJB77BwmlYS+0\n" + - " nE3UOPLji47EOVfUTbvnRBSmn3DCSHkQiRIUP1xMivoiZgKJn+D+FxSMwwiq2pQR\n" + - " 5tdo7nh2A8RxlYUbaD6i4poUB26HVm8vthXahNEkLpXQOz8MWRzs6xOdDHRzi9kT\n" + - " ItRLa4A/3LIATqviQ2EpwcALHXcULcNUMTHORC1EHPvheWR5nLuRllYzN4ReoeHC\n" + - " 3+A5KEkCgYEA52rlh/22/rLckCWugjyJic17vkg46feSOGhjuP2LelrIxNlg491y\n" + - " o28n8lQPSVnEp3/sT7Y3quVvdboq4DC9LTzq52f6/mCYh9UQRpljuSmFqC2MPG46\n" + - " Zl5KLEVLzhjC8aTWkhVINSpz9vauXderOpFYlPW32lnRTjJWE276kj8CgYEA0T2t\n" + - " ULnn7TBvRSpmeWzEBA5FFo2QYkYvwrcVe0pfUltV6pf05xUmMXYFjpezSTEmPhh6\n" + - " +dZdhwxDk+6j8Oo61rTWucDsIqMj5ZT1hPNph8yQtb5LRlRbLGVrirU9Tp7xTgMq\n" + - " 3uRA2Eka1d98dDBsEbMIVFSZ2MX3iezSGRL6j/UCgYEAxZQ82HjEDn2DVwb1EXjC\n" + - " LQdliTZ8cTXQf5yQ19aRiSuNkpPN536ga+1xe7JNQuEDx8auafg3Ww98tFT4WmUC\n" + - " f2ctX9klMJ4kXISK2twHioVq+gW5X7b04YXLajTX3eTCPDHyiNLmzY2raMWAZdrG\n" + - " 9MA3kyafjCt3Sn4rg3gTM10CgYEAtJ8WRpJEd8aQttcUIItYZdvfnclUMtE9l0su\n" + - " GwCnalN3xguol/X0w0uLHn0rgeoQhhfhyFtY3yQiDcg58tRvODphBXZZIMlNSnic\n" + - " vEjW9ygKXyjGmA5nqdpezB0JsB2aVep8Dm5g35Ozu52xNCc8ksbGUO265Jp3xbMN\n" + - " 5iEw9CUCgYBmfoPnJwzA5S1zMIqESUdVH6p3UwHU/+XTY6JHAnEVsE+BuLe3ioi7\n" + - " 6dU4rFd845MCkunBlASLV8MmMbod9xU0vTVHPtmANaUCPxwUIxXQket09t19Dzg7\n" + - " A23sE+5myXtcfz6YrPhbLkijV4Nd7fmecodwDckvpBaWTMrv52/Www==\n" + - " -----END RSA PRIVATE KEY-----\n" + - " filters:\n" + - " - name: envoy.filters.network.http_connection_manager\n" + - " typed_config:\n" + - " \"@type\": "+ hcmType + "\n" + - " codec_type: HTTP3\n" + - " stat_prefix: remote_hcm\n" + - " route_config:\n" + - " name: remote_route\n" + - " virtual_hosts:\n" + - " - name: remote_service\n" + - " domains: [\"*\"]\n" + - " routes:\n" + - " - match: { prefix: \"/\" }\n" + - " direct_response: { status: 200 }\n" + - " http3_protocol_options:\n" + - " http_filters:\n" + - " - name: envoy.router\n" + - " typed_config:\n" + - " \"@type\": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router\n" + - " - name: base_api_listener\n" + - " address:\n" + - " socket_address: { protocol: TCP, address: 0.0.0.0, port_value: 10000 }\n" + - " api_listener:\n" + - " api_listener:\n" + - " \"@type\": " + hcmType + "\n" + - " stat_prefix: api_hcm\n" + - " route_config:\n" + - " name: api_router\n" + - " virtual_hosts:\n" + - " - name: api\n" + - " domains: [\"*\"]\n" + - " routes:\n" + - " - match: { prefix: \"/\" }\n" + - " route: { host_rewrite_literal: example.com, cluster: h3_remote }\n" + - " http_filters:\n" + - " - name: envoy.router\n" + - " typed_config:\n" + - " \"@type\": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router\n" + - " clusters:\n" + - " - name: h3_remote\n" + - " connect_timeout: 10s\n" + - " type: STATIC\n" + - " dns_lookup_family: V4_ONLY\n" + - " lb_policy: ROUND_ROBIN\n" + - " load_assignment:\n" + - " cluster_name: h3_remote\n" + - " endpoints:\n" + - " - lb_endpoints:\n" + - " - endpoint:\n" + - " address:\n" + - " socket_address: { address: 127.0.0.1, port_value: 10101 }\n" + - " typed_extension_protocol_options:\n" + - " envoy.extensions.upstreams.http.v3.HttpProtocolOptions:\n" + - " \"@type\": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions\n" + - " explicit_http_config:\n" + - " http3_protocol_options: {}\n" + - " common_http_protocol_options:\n" + - " idle_timeout: 1s\n" + - " transport_socket:\n" + - " name: envoy.transport_sockets.quic\n" + - " typed_config:\n" + - " \"@type\": " + quicUpstreamType + "\n" + - " upstream_tls_context:\n" + - " sni: example.com"; + private static final String hcmType = + "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager"; + + private static final String quicDownstreamType = + "type.googleapis.com/envoy.extensions.transport_sockets.quic.v3.QuicDownstreamTransport"; + + private static final String quicUpstreamType = + "type.googleapis.com/envoy.extensions.transport_sockets.quic.v3.QuicUpstreamTransport"; + private static final String config = + "static_resources:\n" + + " listeners:\n" + + " - name: h3_remote_listener\n" + + " address:\n" + + " socket_address: { protocol: UDP, address: 127.0.0.1, port_value: 10101 }\n" + + " reuse_port: true\n" + + " udp_listener_config:\n" + + " quic_options: {}\n" + + " downstream_socket_config:\n" + + " prefer_gro: true\n" + + " filter_chains:\n" + + " transport_socket:\n" + + " name: envoy.transport_sockets.quic\n" + + " typed_config:\n" + + " \"@type\": " + quicDownstreamType + "\n" + + " downstream_tls_context:\n" + + " common_tls_context:\n" + + " alpn_protocols: h3\n" + + " tls_certificates:\n" + + " certificate_chain:\n" + + " inline_string: |\n" + + " -----BEGIN CERTIFICATE-----\n" + + " MIIEbDCCA1SgAwIBAgIUJuVBh0FKfFgIcO++ljWm7D47eYUwDQYJKoZIhvcNAQEL\n" + + " BQAwdjELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcM\n" + + " DVNhbiBGcmFuY2lzY28xDTALBgNVBAoMBEx5ZnQxGTAXBgNVBAsMEEx5ZnQgRW5n\n" + + " aW5lZXJpbmcxEDAOBgNVBAMMB1Rlc3QgQ0EwHhcNMjAwODA1MTkxNjAxWhcNMjIw\n" + + " ODA1MTkxNjAxWjCBpjELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWEx\n" + + " FjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xDTALBgNVBAoMBEx5ZnQxGTAXBgNVBAsM\n" + + " EEx5ZnQgRW5naW5lZXJpbmcxGjAYBgNVBAMMEVRlc3QgQmFja2VuZCBUZWFtMSQw\n" + + " IgYJKoZIhvcNAQkBFhViYWNrZW5kLXRlYW1AbHlmdC5jb20wggEiMA0GCSqGSIb3\n" + + " DQEBAQUAA4IBDwAwggEKAoIBAQC9JgaI7hxjPM0tsUna/QmivBdKbCrLnLW9Teak\n" + + " RH/Ebg68ovyvrRIlybDT6XhKi+iVpzVY9kqxhGHgrFDgGLBakVMiYJ5EjIgHfoo4\n" + + " UUAHwIYbunJluYCgANzpprBsvTC/yFYDVMqUrjvwHsoYYVm36io994k9+t813b70\n" + + " o0l7/PraBsKkz8NcY2V2mrd/yHn/0HAhv3hl6iiJme9yURuDYQrae2ACSrQtsbel\n" + + " KwdZ/Re71Z1awz0OQmAjMa2HuCop+Q/1QLnqBekT5+DH1qKUzJ3Jkq6NRkERXOpi\n" + + " 87j04rtCBteCogrO67qnuBZ2lH3jYEMb+lQdLkyNMLltBSdLAgMBAAGjgcAwgb0w\n" + + " DAYDVR0TAQH/BAIwADALBgNVHQ8EBAMCBeAwHQYDVR0lBBYwFAYIKwYBBQUHAwIG\n" + + " CCsGAQUFBwMBMEEGA1UdEQQ6MDiGHnNwaWZmZTovL2x5ZnQuY29tL2JhY2tlbmQt\n" + + " dGVhbYIIbHlmdC5jb22CDHd3dy5seWZ0LmNvbTAdBgNVHQ4EFgQU2XcTZbc0xKZf\n" + + " gNVKSvAbMZJCBoYwHwYDVR0jBBgwFoAUlkvaLFO0vpXGk3Pip6SfLg1yGIcwDQYJ\n" + + " KoZIhvcNAQELBQADggEBAFW05aca3hSiEz/g593GAV3XP4lI5kYUjGjbPSy/HmLr\n" + + " rdv/u3bGfacywAPo7yld+arMzd35tIYEqnhoq0+/OxPeyhwZXVVUatg5Oknut5Zv\n" + + " 2+8l+mVW+8oFCXRqr2gwc8Xt4ByYN+HaNUYfoucnjDplOPukkfSuRhbxqnkhA14v\n" + + " Lri2EbISX14sXf2VQ9I0dkm1hXUxiO0LlA1Z7tvJac9zPSoa6Oljke4D1iH2jzwF\n" + + " Yn7S/gGvVQgkTmWrs3S3TGyBDi4GTDhCF1R+ESvXz8z4UW1MrCSdYUXbRtsT7sbE\n" + + " CjlFYuUyxCi1oe3IHCeXVDo/bmzwGQPDuF3WaDNSYWU=\n" + + " -----END CERTIFICATE-----\n" + + " private_key:\n" + + " inline_string: |\n" + + " -----BEGIN RSA PRIVATE KEY-----\n" + + " MIIEpAIBAAKCAQEAvSYGiO4cYzzNLbFJ2v0JorwXSmwqy5y1vU3mpER/xG4OvKL8\n" + + " r60SJcmw0+l4Sovolac1WPZKsYRh4KxQ4BiwWpFTImCeRIyIB36KOFFAB8CGG7py\n" + + " ZbmAoADc6aawbL0wv8hWA1TKlK478B7KGGFZt+oqPfeJPfrfNd2+9KNJe/z62gbC\n" + + " pM/DXGNldpq3f8h5/9BwIb94ZeooiZnvclEbg2EK2ntgAkq0LbG3pSsHWf0Xu9Wd\n" + + " WsM9DkJgIzGth7gqKfkP9UC56gXpE+fgx9ailMydyZKujUZBEVzqYvO49OK7QgbX\n" + + " gqIKzuu6p7gWdpR942BDG/pUHS5MjTC5bQUnSwIDAQABAoIBADEMwlcSAFSPuNln\n" + + " hzJ9udj0k8md4T8p5Usw/2WLyeJDdBjg30wjQniAJBXgDmyueWMNmFz4iYgdP1CG\n" + + " /vYOEPV7iCZ7Da/TDZd77hYKo+MevuhD4lSU1VEoyCDjNA8OxKyHJB77BwmlYS+0\n" + + " nE3UOPLji47EOVfUTbvnRBSmn3DCSHkQiRIUP1xMivoiZgKJn+D+FxSMwwiq2pQR\n" + + " 5tdo7nh2A8RxlYUbaD6i4poUB26HVm8vthXahNEkLpXQOz8MWRzs6xOdDHRzi9kT\n" + + " ItRLa4A/3LIATqviQ2EpwcALHXcULcNUMTHORC1EHPvheWR5nLuRllYzN4ReoeHC\n" + + " 3+A5KEkCgYEA52rlh/22/rLckCWugjyJic17vkg46feSOGhjuP2LelrIxNlg491y\n" + + " o28n8lQPSVnEp3/sT7Y3quVvdboq4DC9LTzq52f6/mCYh9UQRpljuSmFqC2MPG46\n" + + " Zl5KLEVLzhjC8aTWkhVINSpz9vauXderOpFYlPW32lnRTjJWE276kj8CgYEA0T2t\n" + + " ULnn7TBvRSpmeWzEBA5FFo2QYkYvwrcVe0pfUltV6pf05xUmMXYFjpezSTEmPhh6\n" + + " +dZdhwxDk+6j8Oo61rTWucDsIqMj5ZT1hPNph8yQtb5LRlRbLGVrirU9Tp7xTgMq\n" + + " 3uRA2Eka1d98dDBsEbMIVFSZ2MX3iezSGRL6j/UCgYEAxZQ82HjEDn2DVwb1EXjC\n" + + " LQdliTZ8cTXQf5yQ19aRiSuNkpPN536ga+1xe7JNQuEDx8auafg3Ww98tFT4WmUC\n" + + " f2ctX9klMJ4kXISK2twHioVq+gW5X7b04YXLajTX3eTCPDHyiNLmzY2raMWAZdrG\n" + + " 9MA3kyafjCt3Sn4rg3gTM10CgYEAtJ8WRpJEd8aQttcUIItYZdvfnclUMtE9l0su\n" + + " GwCnalN3xguol/X0w0uLHn0rgeoQhhfhyFtY3yQiDcg58tRvODphBXZZIMlNSnic\n" + + " vEjW9ygKXyjGmA5nqdpezB0JsB2aVep8Dm5g35Ozu52xNCc8ksbGUO265Jp3xbMN\n" + + " 5iEw9CUCgYBmfoPnJwzA5S1zMIqESUdVH6p3UwHU/+XTY6JHAnEVsE+BuLe3ioi7\n" + + " 6dU4rFd845MCkunBlASLV8MmMbod9xU0vTVHPtmANaUCPxwUIxXQket09t19Dzg7\n" + + " A23sE+5myXtcfz6YrPhbLkijV4Nd7fmecodwDckvpBaWTMrv52/Www==\n" + + " -----END RSA PRIVATE KEY-----\n" + + " filters:\n" + + " - name: envoy.filters.network.http_connection_manager\n" + + " typed_config:\n" + + " \"@type\": " + hcmType + "\n" + + " codec_type: HTTP3\n" + + " stat_prefix: remote_hcm\n" + + " route_config:\n" + + " name: remote_route\n" + + " virtual_hosts:\n" + + " - name: remote_service\n" + + " domains: [\"*\"]\n" + + " routes:\n" + + " - match: { prefix: \"/\" }\n" + + " direct_response: { status: 200 }\n" + + " http3_protocol_options:\n" + + " http_filters:\n" + + " - name: envoy.router\n" + + " typed_config:\n" + + + " \"@type\": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router\n" + + " - name: base_api_listener\n" + + " address:\n" + + " socket_address: { protocol: TCP, address: 0.0.0.0, port_value: 10000 }\n" + + " api_listener:\n" + + " api_listener:\n" + + " \"@type\": " + hcmType + "\n" + + " stat_prefix: api_hcm\n" + + " route_config:\n" + + " name: api_router\n" + + " virtual_hosts:\n" + + " - name: api\n" + + " domains: [\"*\"]\n" + + " routes:\n" + + " - match: { prefix: \"/\" }\n" + + " route: { host_rewrite_literal: example.com, cluster: h3_remote }\n" + + " http_filters:\n" + + " - name: envoy.router\n" + + " typed_config:\n" + + " \"@type\": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router\n" + + " clusters:\n" + + " - name: h3_remote\n" + + " connect_timeout: 10s\n" + + " type: STATIC\n" + + " dns_lookup_family: V4_ONLY\n" + + " lb_policy: ROUND_ROBIN\n" + + " load_assignment:\n" + + " cluster_name: h3_remote\n" + + " endpoints:\n" + + " - lb_endpoints:\n" + + " - endpoint:\n" + + " address:\n" + + " socket_address: { address: 127.0.0.1, port_value: 10101 }\n" + + " typed_extension_protocol_options:\n" + + " envoy.extensions.upstreams.http.v3.HttpProtocolOptions:\n" + + + " \"@type\": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions\n" + + " explicit_http_config:\n" + + " http3_protocol_options: {}\n" + + " common_http_protocol_options:\n" + + " idle_timeout: 1s\n" + + " transport_socket:\n" + + " name: envoy.transport_sockets.quic\n" + + " typed_config:\n" + + " \"@type\": " + quicUpstreamType + "\n" + + " upstream_tls_context:\n" + + " sni: example.com"; private static Engine engine; @@ -205,11 +210,11 @@ public void setUpEngine() throws Exception { if (engine == null) { CountDownLatch latch = new CountDownLatch(1); engine = new AndroidEngineBuilder(getContext().getApplicationContext(), new Custom(config)) - .setOnEngineRunning(() -> { - latch.countDown(); - return null; - }) - .build(); + .setOnEngineRunning(() -> { + latch.countDown(); + return null; + }) + .build(); latch.await(); // Don't launch a request before initialization has completed. } } @@ -223,8 +228,8 @@ public void shutdownMockWebServer() throws IOException { public void get_simple() throws Exception { QuicTestServer.startQuicTestServer(getContext()); QuicTestServerTest.RequestScenario requestScenario = new QuicTestServerTest.RequestScenario() - .setHttpMethod(RequestMethod.GET) - .setUrl(QuicTestServer.getServerURL()); + .setHttpMethod(RequestMethod.GET) + .setUrl(QuicTestServer.getServerURL()); QuicTestServerTest.Response response = sendRequest(requestScenario); @@ -233,44 +238,45 @@ public void get_simple() throws Exception { assertThat(response.getEnvoyError()).isNull(); } - private QuicTestServerTest.Response sendRequest( - QuicTestServerTest.RequestScenario requestScenario) throws Exception { + private QuicTestServerTest.Response + sendRequest(QuicTestServerTest.RequestScenario requestScenario) throws Exception { final CountDownLatch latch = new CountDownLatch(1); - final AtomicReference response = new AtomicReference<>(new QuicTestServerTest.Response()); + final AtomicReference response = + new AtomicReference<>(new QuicTestServerTest.Response()); Stream stream = engine.streamClient() - .newStreamPrototype() - .setOnResponseHeaders((responseHeaders, endStream, ignored) -> { - response.get().setHeaders(responseHeaders); - if (endStream) { - latch.countDown(); - } - return null; - }) - .setOnResponseData((data, endStream, ignored) -> { - response.get().addBody(data); - if (endStream) { - latch.countDown(); - } - return null; - }) - .setOnResponseTrailers((trailers, ignored) -> { - response.get().setTrailers(trailers); - latch.countDown(); - return null; - }) - .setOnError((error, ignored) -> { - response.get().setEnvoyError(error); - latch.countDown(); - return null; - }) - .setOnCancel((ignored) -> { - response.get().setCancelled(); - latch.countDown(); - return null; - }) - .start(Executors.newSingleThreadExecutor()) - .sendHeaders(requestScenario.getHeaders(), !requestScenario.hasBody()); + .newStreamPrototype() + .setOnResponseHeaders((responseHeaders, endStream, ignored) -> { + response.get().setHeaders(responseHeaders); + if (endStream) { + latch.countDown(); + } + return null; + }) + .setOnResponseData((data, endStream, ignored) -> { + response.get().addBody(data); + if (endStream) { + latch.countDown(); + } + return null; + }) + .setOnResponseTrailers((trailers, ignored) -> { + response.get().setTrailers(trailers); + latch.countDown(); + return null; + }) + .setOnError((error, ignored) -> { + response.get().setEnvoyError(error); + latch.countDown(); + return null; + }) + .setOnCancel((ignored) -> { + response.get().setCancelled(); + latch.countDown(); + return null; + }) + .start(Executors.newSingleThreadExecutor()) + .sendHeaders(requestScenario.getHeaders(), !requestScenario.hasBody()); requestScenario.getBodyChunks().forEach(stream::sendData); requestScenario.getClosingBodyChunk().ifPresent(stream::close); @@ -284,7 +290,7 @@ private static class RequestScenario { private RequestMethod method = null; private final List bodyChunks = new ArrayList<>(); private final List> headers = new ArrayList<>(); - private boolean closeBodyStream = false; + private final boolean closeBodyStream = false; RequestHeaders getHeaders() { RequestHeadersBuilder requestHeadersBuilder = @@ -302,7 +308,7 @@ List getBodyChunks() { Optional getClosingBodyChunk() { return closeBodyStream ? Optional.of(bodyChunks.get(bodyChunks.size() - 1)) - : Optional.empty(); + : Optional.empty(); } boolean hasBody() { return !bodyChunks.isEmpty(); } @@ -316,27 +322,6 @@ QuicTestServerTest.RequestScenario setUrl(String url) throws MalformedURLExcepti this.url = new URL(url); return this; } - - QuicTestServerTest.RequestScenario addBody(byte[] requestBodyChunk) { - ByteBuffer byteBuffer = ByteBuffer.allocateDirect(requestBodyChunk.length); - byteBuffer.put(requestBodyChunk); - bodyChunks.add(byteBuffer); - return this; - } - - QuicTestServerTest.RequestScenario addBody(String requestBodyChunk) { - return addBody(requestBodyChunk.getBytes()); - } - - QuicTestServerTest.RequestScenario addHeader(String key, String value) { - headers.add(new SimpleImmutableEntry<>(key, value)); - return this; - } - - QuicTestServerTest.RequestScenario closeBodyStream() { - closeBodyStream = true; - return this; - } } private static class Response { @@ -372,7 +357,7 @@ void setEnvoyError(EnvoyError envoyError) { void setCancelled() { if (!cancelled.compareAndSet(false, true)) { assertionError.compareAndSet(null, - new AssertionError("setOnCancel called more than once.")); + new AssertionError("setOnCancel called more than once.")); } } @@ -380,10 +365,6 @@ void setCancelled() { ResponseHeaders getHeaders() { return headers.get(); } - ResponseTrailers getTrailers() { return trailers.get(); } - - boolean isCancelled() { return cancelled.get(); } - String getBodyAsString() { int totalSize = bodies.stream().mapToInt(ByteBuffer::limit).sum(); byte[] body = new byte[totalSize]; @@ -396,8 +377,6 @@ String getBodyAsString() { return new String(body); } - int getNbResponseChunks() { return bodies.size(); } - void throwAssertionErrorIfAny() { if (assertionError.get() != null) { throw assertionError.get(); @@ -405,5 +384,3 @@ void throwAssertionErrorIfAny() { } } } - - From c608e2efe3fb15b9dfb1370dd8aae1e16ac5e507 Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Wed, 22 Sep 2021 10:50:30 +0000 Subject: [PATCH 06/54] [WIP] checkpoint Signed-off-by: Chidera Olibie --- test/common/integration/quic_test_server.cc | 29 +++---- .../net/testing/QuicTestServerTest.java | 86 +++++++++++++------ 2 files changed, 73 insertions(+), 42 deletions(-) diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc index 3d23f9b13b..2202626735 100644 --- a/test/common/integration/quic_test_server.cc +++ b/test/common/integration/quic_test_server.cc @@ -1,21 +1,6 @@ #include "quic_test_server.h" namespace Envoy { -// see https://github.com/envoyproxy/envoy/blob/main/test/test_runner.cc -void QuicTestServer::setup() { - - ProcessWide process_wide; - Thread::MutexBasicLockable lock; - - Logger::Registry::getSink()->setLock(lock); - Logger::Registry::getSink()->setShouldEscape(false); - Logger::Registry::setLogLevel(spdlog::level::level_enum::err); // options.logLevel() - Logger::Registry::setLogFormat("[%Y-%m-%d %T.%e][%t][%l][%n] [%g:%#] %v"); // options.logFormat() - - // TODO(colibie) this doesnt work. Why? - // Logger::Context logging_state(options.logLevel(), options.logFormat(), lock, false, - // options.enableFineGrainLogging()); -} Network::TransportSocketFactoryPtr QuicTestServer::createUpstreamTlsContext( testing::NiceMock& factory_context) { @@ -150,10 +135,16 @@ QuicTestServer::QuicTestServer() ON_CALL(factory_context_, api()).WillByDefault(testing::ReturnRef(*api_)); ON_CALL(factory_context_, scope()).WillByDefault(testing::ReturnRef(stats_store_)); - setup(); } void QuicTestServer::startQuicTestServer() { + // pre-setup: see https://github.com/envoyproxy/envoy/blob/main/test/test_runner.cc + ProcessWide process_wide; + Thread::MutexBasicLockable lock; + Logger::Context logging_state(spdlog::level::level_enum::err, "[%Y-%m-%d %T.%e][%t][%l][%n] [%g:%#] %v", lock, false, + false); + // end pre-setup + FakeUpstreamConfig upstream_config_{time_system_}; upstream_config_.upstream_protocol_ = Http::CodecType::HTTP3; upstream_config_.udp_fake_upstream_ = FakeUpstreamConfig::UdpConfig(); @@ -165,10 +156,14 @@ void QuicTestServer::startQuicTestServer() { aupstream = std::make_unique(std::move(factory), port, version_, upstream_config_, false); + aupstream->setLastRequestHeaders(Http::TestRequestHeaderMapImpl{ + {"response_size_bytes", "2"}}); + aupstream->setResponseHeaders(std::make_unique( + Http::TestResponseHeaderMapImpl({{":status", "203"}}))); + // see what port was selected. std::cerr << "Upstream now listening on " << aupstream->localAddress()->asString() << "\n"; - Logger::Registry::getSink()->clearLock(); } void QuicTestServer::shutdownQuicTestServer() { diff --git a/test/java/org/chromium/net/testing/QuicTestServerTest.java b/test/java/org/chromium/net/testing/QuicTestServerTest.java index 8cbea1e0ab..e4030ff7b0 100644 --- a/test/java/org/chromium/net/testing/QuicTestServerTest.java +++ b/test/java/org/chromium/net/testing/QuicTestServerTest.java @@ -1,6 +1,7 @@ package org.chromium.net.testing; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.chromium.net.testing.CronetTestRule.getContext; import io.envoyproxy.envoymobile.AndroidEngineBuilder; @@ -18,7 +19,6 @@ import java.net.MalformedURLException; import java.net.URL; import java.nio.ByteBuffer; -import java.util.AbstractMap.SimpleImmutableEntry; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -30,7 +30,7 @@ import java.util.concurrent.atomic.AtomicReference; import org.junit.After; import org.junit.AfterClass; -import org.junit.Before; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -205,37 +205,73 @@ public static void shutdownEngine() { } } - @Before - public void setUpEngine() throws Exception { - if (engine == null) { - CountDownLatch latch = new CountDownLatch(1); - engine = new AndroidEngineBuilder(getContext().getApplicationContext(), new Custom(config)) - .setOnEngineRunning(() -> { - latch.countDown(); - return null; - }) - .build(); - latch.await(); // Don't launch a request before initialization has completed. - } - } + // @Before + // public void setUpEngine() throws Exception { + // if (engine == null) { + // CountDownLatch latch = new CountDownLatch(1); + // engine = new AndroidEngineBuilder(getContext().getApplicationContext(), new Custom(config)) + // .setOnEngineRunning(() -> { + // latch.countDown(); + // return null; + // }) + // .build(); + // latch.await(); // Don't launch a request before initialization has completed. + // } + // } @After public void shutdownMockWebServer() throws IOException { - QuicTestServer.shutdownQuicTestServer(); + // QuicTestServer.shutdownQuicTestServer(); } @Test public void get_simple() throws Exception { - QuicTestServer.startQuicTestServer(getContext()); - QuicTestServerTest.RequestScenario requestScenario = new QuicTestServerTest.RequestScenario() - .setHttpMethod(RequestMethod.GET) - .setUrl(QuicTestServer.getServerURL()); - - QuicTestServerTest.Response response = sendRequest(requestScenario); + CountDownLatch latch = new CountDownLatch(1); + Engine engine = new AndroidEngineBuilder(getContext().getApplicationContext(), new Custom(config)) + .setOnEngineRunning(() -> { + latch.countDown(); + return null; + }) + .build(); + latch.await(); - assertThat(response.getHeaders().getHttpStatus()).isEqualTo(200); - assertThat(response.getBodyAsString()).isEqualTo("hello, world"); - assertThat(response.getEnvoyError()).isNull(); + RequestMethod requestMethod = RequestMethod.valueOf("GET"); + RequestHeaders requestHeaders = new RequestHeadersBuilder(requestMethod, "https", + "example.com", "/test") + .build(); + + engine + .streamClient() + .newStreamPrototype() + .setOnResponseHeaders((responseHeaders, lastCallback, ignored) -> { + assertThat(responseHeaders.getHttpStatus()).isEqualTo(200); + if (lastCallback) { + System.err.println("SUCCESSFUL HEADERS!!!"); + } + return null; + }) + .setOnResponseData((data, endStream, ignored) -> { + if (endStream) { + System.err.println("SUCCESSFUL DATA!!!"); + } + return null; + }) + .setOnError((error, ignored) -> { + fail("An error"); + return null; + }) + .start(Executors.newSingleThreadExecutor()) + .sendHeaders(requestHeaders, true); + // QuicTestServer.startQuicTestServer(getContext()); + // QuicTestServerTest.RequestScenario requestScenario = new QuicTestServerTest.RequestScenario() + // .setHttpMethod(RequestMethod.GET) + // .setUrl(QuicTestServer.getServerURL()); + // + // QuicTestServerTest.Response response = sendRequest(requestScenario); + // + // assertThat(response.getHeaders().getHttpStatus()).isEqualTo(200); + // assertThat(response.getBodyAsString()).isEqualTo("hello, world"); + // assertThat(response.getEnvoyError()).isNull(); } private QuicTestServerTest.Response From 1e98c4dbdc7dda94293dd7537232854f9c1c1ccb Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Thu, 23 Sep 2021 10:32:51 +0000 Subject: [PATCH 07/54] move submodule to latest commit in main Signed-off-by: Chidera Olibie --- envoy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/envoy b/envoy index fe81eaba52..539ebc03d0 160000 --- a/envoy +++ b/envoy @@ -1 +1 @@ -Subproject commit fe81eaba52a43eaacb19fbfa23acc23506f9d9d7 +Subproject commit 539ebc03d09a2b6aff85e2e22e1d71e80d973b47 From 8a6208f0619b3d00baf7487105a35fb08754280d Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Thu, 23 Sep 2021 14:23:42 +0000 Subject: [PATCH 08/54] added direct response to test engine Signed-off-by: Chidera Olibie --- .../net/testing/QuicTestServerTest.java | 97 ++++++------------- 1 file changed, 32 insertions(+), 65 deletions(-) diff --git a/test/java/org/chromium/net/testing/QuicTestServerTest.java b/test/java/org/chromium/net/testing/QuicTestServerTest.java index e4030ff7b0..a82f69fcf0 100644 --- a/test/java/org/chromium/net/testing/QuicTestServerTest.java +++ b/test/java/org/chromium/net/testing/QuicTestServerTest.java @@ -31,6 +31,7 @@ import org.junit.After; import org.junit.AfterClass; import org.junit.Assert; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -135,14 +136,16 @@ public class QuicTestServerTest { + " - name: remote_service\n" + " domains: [\"*\"]\n" + " routes:\n" - + " - match: { prefix: \"/\" }\n" - + " direct_response: { status: 200 }\n" + + " - match: { prefix: \"/base\" }\n" + + " direct_response:\n" + + " status: 200\n" + + " body:\n" + + " inline_string: \"hello, world\"\n" + " http3_protocol_options:\n" + " http_filters:\n" + " - name: envoy.router\n" + " typed_config:\n" - + - " \"@type\": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router\n" + + " \"@type\": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router\n" + " - name: base_api_listener\n" + " address:\n" + " socket_address: { protocol: TCP, address: 0.0.0.0, port_value: 10000 }\n" @@ -157,7 +160,7 @@ public class QuicTestServerTest { + " domains: [\"*\"]\n" + " routes:\n" + " - match: { prefix: \"/\" }\n" - + " route: { host_rewrite_literal: example.com, cluster: h3_remote }\n" + + " route: { host_rewrite_literal: lyft.com, cluster: h3_remote }\n" + " http_filters:\n" + " - name: envoy.router\n" + " typed_config:\n" @@ -188,7 +191,7 @@ public class QuicTestServerTest { + " typed_config:\n" + " \"@type\": " + quicUpstreamType + "\n" + " upstream_tls_context:\n" - + " sni: example.com"; + + " sni: lyft.com"; private static Engine engine; @@ -205,73 +208,37 @@ public static void shutdownEngine() { } } - // @Before - // public void setUpEngine() throws Exception { - // if (engine == null) { - // CountDownLatch latch = new CountDownLatch(1); - // engine = new AndroidEngineBuilder(getContext().getApplicationContext(), new Custom(config)) - // .setOnEngineRunning(() -> { - // latch.countDown(); - // return null; - // }) - // .build(); - // latch.await(); // Don't launch a request before initialization has completed. - // } - // } + @Before + public void setUpEngine() throws Exception { + if (engine == null) { + CountDownLatch latch = new CountDownLatch(1); + engine = new AndroidEngineBuilder(getContext().getApplicationContext(), new Custom(config)) + .setOnEngineRunning(() -> { + latch.countDown(); + return null; + }) + .build(); + latch.await(); // Don't launch a request before initialization has completed. + } + } @After public void shutdownMockWebServer() throws IOException { - // QuicTestServer.shutdownQuicTestServer(); + QuicTestServer.shutdownQuicTestServer(); } @Test public void get_simple() throws Exception { - CountDownLatch latch = new CountDownLatch(1); - Engine engine = new AndroidEngineBuilder(getContext().getApplicationContext(), new Custom(config)) - .setOnEngineRunning(() -> { - latch.countDown(); - return null; - }) - .build(); - latch.await(); + QuicTestServer.startQuicTestServer(getContext()); + QuicTestServerTest.RequestScenario requestScenario = new QuicTestServerTest.RequestScenario() + .setHttpMethod(RequestMethod.GET) + .setUrl(QuicTestServer.getServerURL()); + + QuicTestServerTest.Response response = sendRequest(requestScenario); - RequestMethod requestMethod = RequestMethod.valueOf("GET"); - RequestHeaders requestHeaders = new RequestHeadersBuilder(requestMethod, "https", - "example.com", "/test") - .build(); - - engine - .streamClient() - .newStreamPrototype() - .setOnResponseHeaders((responseHeaders, lastCallback, ignored) -> { - assertThat(responseHeaders.getHttpStatus()).isEqualTo(200); - if (lastCallback) { - System.err.println("SUCCESSFUL HEADERS!!!"); - } - return null; - }) - .setOnResponseData((data, endStream, ignored) -> { - if (endStream) { - System.err.println("SUCCESSFUL DATA!!!"); - } - return null; - }) - .setOnError((error, ignored) -> { - fail("An error"); - return null; - }) - .start(Executors.newSingleThreadExecutor()) - .sendHeaders(requestHeaders, true); - // QuicTestServer.startQuicTestServer(getContext()); - // QuicTestServerTest.RequestScenario requestScenario = new QuicTestServerTest.RequestScenario() - // .setHttpMethod(RequestMethod.GET) - // .setUrl(QuicTestServer.getServerURL()); - // - // QuicTestServerTest.Response response = sendRequest(requestScenario); - // - // assertThat(response.getHeaders().getHttpStatus()).isEqualTo(200); - // assertThat(response.getBodyAsString()).isEqualTo("hello, world"); - // assertThat(response.getEnvoyError()).isNull(); + assertThat(response.getHeaders().getHttpStatus()).isEqualTo(200); + assertThat(response.getBodyAsString()).isEqualTo("hello, world"); + assertThat(response.getEnvoyError()).isNull(); } private QuicTestServerTest.Response From 189e3e958f970382e48cb18e82d89c3447241a0c Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Thu, 30 Sep 2021 01:54:16 +0000 Subject: [PATCH 09/54] WIP Signed-off-by: Chidera Olibie --- envoy | 2 +- test/common/integration/quic_test_server.cc | 8 +- test/java/org/chromium/net/QuicTest.java | 4 +- .../net/testing/QuicTestServerTest.java | 102 +++++++++--------- 4 files changed, 58 insertions(+), 58 deletions(-) diff --git a/envoy b/envoy index 0656e34e0c..539ebc03d0 160000 --- a/envoy +++ b/envoy @@ -1 +1 @@ -Subproject commit 0656e34e0c87a77fb87273be89afd4922a30c7db +Subproject commit 539ebc03d09a2b6aff85e2e22e1d71e80d973b47 diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc index 2202626735..36f671290a 100644 --- a/test/common/integration/quic_test_server.cc +++ b/test/common/integration/quic_test_server.cc @@ -124,7 +124,7 @@ QuicTestServer::QuicTestServer() - name: remote_service domains: ["*"] routes: - - match: { prefix: "/simple" } + - match: { prefix: "/" } direct_response: { status: 200 } http3_protocol_options: http_filters: @@ -149,12 +149,12 @@ void QuicTestServer::startQuicTestServer() { upstream_config_.upstream_protocol_ = Http::CodecType::HTTP3; upstream_config_.udp_fake_upstream_ = FakeUpstreamConfig::UdpConfig(); - Network::TransportSocketFactoryPtr factory = - createUpstreamTlsContext(factory_context_); // Network::Test::createRawBufferSocketFactory(); + Network::TransportSocketFactoryPtr factory = createUpstreamTlsContext(factory_context_); + // Network::Test::createRawBufferSocketFactory(); int port = 0; // let the kernel pick a port that is not in use (avoids test races) aupstream = std::make_unique(std::move(factory), port, version_, - upstream_config_, false); + upstream_config_, true); aupstream->setLastRequestHeaders(Http::TestRequestHeaderMapImpl{ {"response_size_bytes", "2"}}); diff --git a/test/java/org/chromium/net/QuicTest.java b/test/java/org/chromium/net/QuicTest.java index 2fb6c543ee..ea4796ab2c 100644 --- a/test/java/org/chromium/net/QuicTest.java +++ b/test/java/org/chromium/net/QuicTest.java @@ -91,7 +91,7 @@ public void tearDown() throws Exception { public void testQuicLoadUrl() throws Exception { ExperimentalCronetEngine cronetEngine = mBuilder.build(); String quicURL = QuicTestServer.getServerURL(); - Thread.sleep(100000); + // Thread.sleep(100000); TestUrlRequestCallback callback = new TestUrlRequestCallback(); // Although the native stack races QUIC and SPDY for the first request, // since there is no http server running on the corresponding TCP port, @@ -113,7 +113,7 @@ public void testQuicLoadUrl() throws Exception { // after kUpdatePrefsDelayMs in http_server_properties_manager.cc. while (true) { Log.i(TAG, "Still waiting for pref file update....."); - Thread.sleep(10000); + // Thread.sleep(10000); boolean contains = false; try { if (fileContainsString("local_prefs.json", "quic")) diff --git a/test/java/org/chromium/net/testing/QuicTestServerTest.java b/test/java/org/chromium/net/testing/QuicTestServerTest.java index a82f69fcf0..c84ae3abb6 100644 --- a/test/java/org/chromium/net/testing/QuicTestServerTest.java +++ b/test/java/org/chromium/net/testing/QuicTestServerTest.java @@ -14,6 +14,7 @@ import io.envoyproxy.envoymobile.ResponseHeaders; import io.envoyproxy.envoymobile.ResponseTrailers; import io.envoyproxy.envoymobile.Stream; +import io.envoyproxy.envoymobile.UpstreamHttpProtocol; import io.envoyproxy.envoymobile.engine.AndroidJniLibrary; import java.io.IOException; import java.net.MalformedURLException; @@ -70,59 +71,58 @@ public class QuicTestServerTest { + " certificate_chain:\n" + " inline_string: |\n" + " -----BEGIN CERTIFICATE-----\n" - + " MIIEbDCCA1SgAwIBAgIUJuVBh0FKfFgIcO++ljWm7D47eYUwDQYJKoZIhvcNAQEL\n" - + " BQAwdjELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcM\n" + + " MIIEPjCCAyagAwIBAgIUEuy1WgSCzX6mojPirk7Th6uhNHowDQYJKoZIhvcNAQEL\n" + + " BQAwfzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcM\n" + " DVNhbiBGcmFuY2lzY28xDTALBgNVBAoMBEx5ZnQxGTAXBgNVBAsMEEx5ZnQgRW5n\n" - + " aW5lZXJpbmcxEDAOBgNVBAMMB1Rlc3QgQ0EwHhcNMjAwODA1MTkxNjAxWhcNMjIw\n" - + " ODA1MTkxNjAxWjCBpjELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWEx\n" - + " FjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xDTALBgNVBAoMBEx5ZnQxGTAXBgNVBAsM\n" - + " EEx5ZnQgRW5naW5lZXJpbmcxGjAYBgNVBAMMEVRlc3QgQmFja2VuZCBUZWFtMSQw\n" - + " IgYJKoZIhvcNAQkBFhViYWNrZW5kLXRlYW1AbHlmdC5jb20wggEiMA0GCSqGSIb3\n" - + " DQEBAQUAA4IBDwAwggEKAoIBAQC9JgaI7hxjPM0tsUna/QmivBdKbCrLnLW9Teak\n" - + " RH/Ebg68ovyvrRIlybDT6XhKi+iVpzVY9kqxhGHgrFDgGLBakVMiYJ5EjIgHfoo4\n" - + " UUAHwIYbunJluYCgANzpprBsvTC/yFYDVMqUrjvwHsoYYVm36io994k9+t813b70\n" - + " o0l7/PraBsKkz8NcY2V2mrd/yHn/0HAhv3hl6iiJme9yURuDYQrae2ACSrQtsbel\n" - + " KwdZ/Re71Z1awz0OQmAjMa2HuCop+Q/1QLnqBekT5+DH1qKUzJ3Jkq6NRkERXOpi\n" - + " 87j04rtCBteCogrO67qnuBZ2lH3jYEMb+lQdLkyNMLltBSdLAgMBAAGjgcAwgb0w\n" - + " DAYDVR0TAQH/BAIwADALBgNVHQ8EBAMCBeAwHQYDVR0lBBYwFAYIKwYBBQUHAwIG\n" - + " CCsGAQUFBwMBMEEGA1UdEQQ6MDiGHnNwaWZmZTovL2x5ZnQuY29tL2JhY2tlbmQt\n" - + " dGVhbYIIbHlmdC5jb22CDHd3dy5seWZ0LmNvbTAdBgNVHQ4EFgQU2XcTZbc0xKZf\n" - + " gNVKSvAbMZJCBoYwHwYDVR0jBBgwFoAUlkvaLFO0vpXGk3Pip6SfLg1yGIcwDQYJ\n" - + " KoZIhvcNAQELBQADggEBAFW05aca3hSiEz/g593GAV3XP4lI5kYUjGjbPSy/HmLr\n" - + " rdv/u3bGfacywAPo7yld+arMzd35tIYEqnhoq0+/OxPeyhwZXVVUatg5Oknut5Zv\n" - + " 2+8l+mVW+8oFCXRqr2gwc8Xt4ByYN+HaNUYfoucnjDplOPukkfSuRhbxqnkhA14v\n" - + " Lri2EbISX14sXf2VQ9I0dkm1hXUxiO0LlA1Z7tvJac9zPSoa6Oljke4D1iH2jzwF\n" - + " Yn7S/gGvVQgkTmWrs3S3TGyBDi4GTDhCF1R+ESvXz8z4UW1MrCSdYUXbRtsT7sbE\n" - + " CjlFYuUyxCi1oe3IHCeXVDo/bmzwGQPDuF3WaDNSYWU=\n" + + " aW5lZXJpbmcxGTAXBgNVBAMMEFRlc3QgVXBzdHJlYW0gQ0EwHhcNMjAwODA1MTkx\n" + + " NjAyWhcNMjIwODA1MTkxNjAyWjCBgzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNh\n" + + " bGlmb3JuaWExFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xDTALBgNVBAoMBEx5ZnQx\n" + + " GTAXBgNVBAsMEEx5ZnQgRW5naW5lZXJpbmcxHTAbBgNVBAMMFFRlc3QgVXBzdHJl\n" + + " YW0gU2VydmVyMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtpiYA4/I\n" + + " NuflkPe4L/GTslmngNQUCo8TzPXG0gt7uoxr4FeuVy7AaD28S2/hwhbl+bDtHTQY\n" + + " mvBUwNMsYzpND2eQ3sSIumdeLzBEKP2mnnZ9gE/Zd2TIuZl686RpDq0B6ZdZSpCu\n" + + " bqQmmPFLiRNH8JViJZMN5yqMt7T5oq+DnCYQZllqmpAwd6NnhKALrYmZ87oqc0zh\n" + + " kf+5amP7zMYKkwQuRwcx4QPZkEp3+qhszolpAJ52dFGJ+pLuUVDg0Gf0cnxLjFKc\n" + + " 6vcTlj4tsymR4ci58MHRt4EdGdhShw0oaj67gRRfU4Vj61I2ZAVH07kL0mjO2TZT\n" + + " EKrOEJJ7/dtxdwIDAQABo4GsMIGpMAwGA1UdEwEB/wQCMAAwCwYDVR0PBAQDAgXg\n" + + " MB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDATAtBgNVHREEJjAkggoqLmx5\n" + + " ZnQuY29thwR/AAABhxAAAAAAAAAAAAAAAAAAAAABMB0GA1UdDgQWBBQeoC5wxwX5\n" + + " k3ggIN/844/6jKx9czAfBgNVHSMEGDAWgBQ7Zh1TopMm7SY1RCOEO8L1G8IAZDAN\n" + + " BgkqhkiG9w0BAQsFAAOCAQEA18wEg8LnPm99cIouFUFMAO+BpiY2KVa9Bu6x07m9\n" + + " quNFv7/4mLt87sk/umD3LH/tDjqW0D84vhG9a+0yDq7ZrD/P5eK3R+yBINwhe4/x\n" + + " obJlThEsbcZF1FkMnq1rt53izukyQLLQwoVxidQl3HCg3hosWmpH1VBPgwoize6V\n" + + " aAhKLW0n+JSfIE1d80nvZdYlHuCnS6UhLmAbTBCnwT0aGTfzT0Dd4KlYiY8vGZRu\n" + + " tXOw4MzKtJcOL3t7Zpz2mhqN25dyiuyvKEhLXdx48aemwa2t6ISfFKsd0/glnNe/\n" + + " PFZMakzKv1G0xLGURjsInCZ0kePAmerfZN6CBZDo4laYEg==\n" + " -----END CERTIFICATE-----\n" + " private_key:\n" + " inline_string: |\n" + " -----BEGIN RSA PRIVATE KEY-----\n" - + " MIIEpAIBAAKCAQEAvSYGiO4cYzzNLbFJ2v0JorwXSmwqy5y1vU3mpER/xG4OvKL8\n" - + " r60SJcmw0+l4Sovolac1WPZKsYRh4KxQ4BiwWpFTImCeRIyIB36KOFFAB8CGG7py\n" - + " ZbmAoADc6aawbL0wv8hWA1TKlK478B7KGGFZt+oqPfeJPfrfNd2+9KNJe/z62gbC\n" - + " pM/DXGNldpq3f8h5/9BwIb94ZeooiZnvclEbg2EK2ntgAkq0LbG3pSsHWf0Xu9Wd\n" - + " WsM9DkJgIzGth7gqKfkP9UC56gXpE+fgx9ailMydyZKujUZBEVzqYvO49OK7QgbX\n" - + " gqIKzuu6p7gWdpR942BDG/pUHS5MjTC5bQUnSwIDAQABAoIBADEMwlcSAFSPuNln\n" - + " hzJ9udj0k8md4T8p5Usw/2WLyeJDdBjg30wjQniAJBXgDmyueWMNmFz4iYgdP1CG\n" - + " /vYOEPV7iCZ7Da/TDZd77hYKo+MevuhD4lSU1VEoyCDjNA8OxKyHJB77BwmlYS+0\n" - + " nE3UOPLji47EOVfUTbvnRBSmn3DCSHkQiRIUP1xMivoiZgKJn+D+FxSMwwiq2pQR\n" - + " 5tdo7nh2A8RxlYUbaD6i4poUB26HVm8vthXahNEkLpXQOz8MWRzs6xOdDHRzi9kT\n" - + " ItRLa4A/3LIATqviQ2EpwcALHXcULcNUMTHORC1EHPvheWR5nLuRllYzN4ReoeHC\n" - + " 3+A5KEkCgYEA52rlh/22/rLckCWugjyJic17vkg46feSOGhjuP2LelrIxNlg491y\n" - + " o28n8lQPSVnEp3/sT7Y3quVvdboq4DC9LTzq52f6/mCYh9UQRpljuSmFqC2MPG46\n" - + " Zl5KLEVLzhjC8aTWkhVINSpz9vauXderOpFYlPW32lnRTjJWE276kj8CgYEA0T2t\n" - + " ULnn7TBvRSpmeWzEBA5FFo2QYkYvwrcVe0pfUltV6pf05xUmMXYFjpezSTEmPhh6\n" - + " +dZdhwxDk+6j8Oo61rTWucDsIqMj5ZT1hPNph8yQtb5LRlRbLGVrirU9Tp7xTgMq\n" - + " 3uRA2Eka1d98dDBsEbMIVFSZ2MX3iezSGRL6j/UCgYEAxZQ82HjEDn2DVwb1EXjC\n" - + " LQdliTZ8cTXQf5yQ19aRiSuNkpPN536ga+1xe7JNQuEDx8auafg3Ww98tFT4WmUC\n" - + " f2ctX9klMJ4kXISK2twHioVq+gW5X7b04YXLajTX3eTCPDHyiNLmzY2raMWAZdrG\n" - + " 9MA3kyafjCt3Sn4rg3gTM10CgYEAtJ8WRpJEd8aQttcUIItYZdvfnclUMtE9l0su\n" - + " GwCnalN3xguol/X0w0uLHn0rgeoQhhfhyFtY3yQiDcg58tRvODphBXZZIMlNSnic\n" - + " vEjW9ygKXyjGmA5nqdpezB0JsB2aVep8Dm5g35Ozu52xNCc8ksbGUO265Jp3xbMN\n" - + " 5iEw9CUCgYBmfoPnJwzA5S1zMIqESUdVH6p3UwHU/+XTY6JHAnEVsE+BuLe3ioi7\n" - + " 6dU4rFd845MCkunBlASLV8MmMbod9xU0vTVHPtmANaUCPxwUIxXQket09t19Dzg7\n" - + " A23sE+5myXtcfz6YrPhbLkijV4Nd7fmecodwDckvpBaWTMrv52/Www==\n" + + " MIIEpAIBAAKCAQEAtpiYA4/INuflkPe4L/GTslmngNQUCo8TzPXG0gt7uoxr4Feu\n" + + " Vy7AaD28S2/hwhbl+bDtHTQYmvBUwNMsYzpND2eQ3sSIumdeLzBEKP2mnnZ9gE/Z\n" + + " d2TIuZl686RpDq0B6ZdZSpCubqQmmPFLiRNH8JViJZMN5yqMt7T5oq+DnCYQZllq\n" + + " mpAwd6NnhKALrYmZ87oqc0zhkf+5amP7zMYKkwQuRwcx4QPZkEp3+qhszolpAJ52\n" + + " dFGJ+pLuUVDg0Gf0cnxLjFKc6vcTlj4tsymR4ci58MHRt4EdGdhShw0oaj67gRRf\n" + + " U4Vj61I2ZAVH07kL0mjO2TZTEKrOEJJ7/dtxdwIDAQABAoIBACz6E1+1N/0GTA7U\n" + + " ZgMxP09MNC1QkAs1yQvQcoPknjqKQjxFfMUu1+gVZN80FOjpGQbTJOTvoyvvDQFe\n" + + " Qu3CO58SxKWKxZ8cvR9khTWPnU4lI67KfGejZKoK+zUuh049IV53kGAEmWLZfkRo\n" + + " E1IVdL/3G/DjcyZA3d6WbnM7RnDcqORPnig4lq5HxN76eBdssbxtrAi3Sjy3ChMy\n" + + " BLInnryF4UtaT5xqR26YjgtFmYkunrgXTe1i/ewQgBBkSPXcNr7or69hCCv0SG9e\n" + + " vRsv1r+Uug3/iRZDjEhKBmXWNAZJ/IsDF37ywiyeBdUY+klDX+mWz+0BB0us8b4u\n" + + " LxoZQTECgYEA2Gu9EVC0RMrQ9FF5AgKKJWmZKkOn346RkPrtbl5lbuUgnVdBXJjr\n" + + " wfMZVTD/8E/tMN4EMSGmC9bxCpRRzhrphrm7SHGD6b9O30DH9q0TV0r0A8IG/bMO\n" + + " xJLYjrYVxtEE+KckzvyvfIefbDG7wYkI3u+ObmjBg9t6jcErKlI/PdkCgYEA1/1E\n" + + " T+cpR16iOPz1mz+f/GU4YmPkdSDj/PrjMv0c1OTDvdPiZPpLkhLUKiICnKSKbYjX\n" + + " Ko8fdZc3cmakgD1dXtAfR7Tf/hXQIR5+iHD48I5e9DVlkqMNDObfj82ohTFKVe/P\n" + + " ZSwgDiAPTMFxWr26u/GzY5D3adCQYJyKE2wTh88CgYEAu7vpzGVnmu0ciXNLNvUh\n" + + " BQcvODxsGT9BArTI1Z7I+oOD4TjZmAuHJz1L0lypB7stk+BjXoND2K1hdr3moJUz\n" + + " 0gy3a0YdGd07++nkDBVi26xHNCNRkS2MN/TyKgnFpiuW1mOXSH5lc+7p2h7iMiY/\n" + + " LbQ8p4Xzp//xtZnFafbiqTECgYEAwDN5KZ1r5z24H/xCVv+cT46HSU7ZCr3VA9cC\n" + + " fOouUOitouu9J9xviTJGKKQRLPFi2awOxKmN9ic1SRE7y35P60JKw5WaSdGBXydy\n" + + " s9nMPMyEhM5Lb9y2jUeZo68ACl5dZvG63a4RbGBtHQF67KOvWvXvi2eCM2BMShyi\n" + + " 5jujeZMCgYAjewq1hVqL1FOD8sIFpmndsH3+Dfc7BJ/erqGOX9bQYGvJO4nCe+7K\n" + + " 4o8qFQf4jwdxu0iNxYJIMdn+l4/pz2e7GUFHjgMduUclf27Qj1p+8EyYqp6cmkzM\n" + + " 8mcwRkYo3aM70EmUu0Xxi3d5O5F1bIJ5MkgXaX/zSF2N02B3jXroxQ==\n" + " -----END RSA PRIVATE KEY-----\n" + " filters:\n" + " - name: envoy.filters.network.http_connection_manager\n" @@ -191,7 +191,7 @@ public class QuicTestServerTest { + " typed_config:\n" + " \"@type\": " + quicUpstreamType + "\n" + " upstream_tls_context:\n" - + " sni: lyft.com"; + + " sni: localhost"; private static Engine engine; @@ -235,7 +235,8 @@ public void get_simple() throws Exception { .setUrl(QuicTestServer.getServerURL()); QuicTestServerTest.Response response = sendRequest(requestScenario); - + System.err.println(response.getBodyAsString()); + System.err.println(response.getHeaders()); assertThat(response.getHeaders().getHttpStatus()).isEqualTo(200); assertThat(response.getBodyAsString()).isEqualTo("hello, world"); assertThat(response.getEnvoyError()).isNull(); @@ -299,7 +300,6 @@ RequestHeaders getHeaders() { RequestHeadersBuilder requestHeadersBuilder = new RequestHeadersBuilder(method, url.getProtocol(), url.getAuthority(), url.getPath()); headers.forEach(entry -> requestHeadersBuilder.add(entry.getKey(), entry.getValue())); - // HTTP1 is the only way to send HTTP requests (not HTTPS) return requestHeadersBuilder.build(); } From 751198645349209ca375c018080ea3b8e932034e Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Mon, 4 Oct 2021 14:28:51 +0000 Subject: [PATCH 10/54] [wip] Signed-off-by: Chidera Olibie --- test/common/integration/quic_test_server.cc | 4 ++-- .../net/testing/QuicTestServerTest.java | 17 +++++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc index 36f671290a..e7546f1938 100644 --- a/test/common/integration/quic_test_server.cc +++ b/test/common/integration/quic_test_server.cc @@ -152,9 +152,9 @@ void QuicTestServer::startQuicTestServer() { Network::TransportSocketFactoryPtr factory = createUpstreamTlsContext(factory_context_); // Network::Test::createRawBufferSocketFactory(); - int port = 0; // let the kernel pick a port that is not in use (avoids test races) + int port = 34210; // let the kernel pick a port that is not in use (avoids test races) aupstream = std::make_unique(std::move(factory), port, version_, - upstream_config_, true); + upstream_config_, false); aupstream->setLastRequestHeaders(Http::TestRequestHeaderMapImpl{ {"response_size_bytes", "2"}}); diff --git a/test/java/org/chromium/net/testing/QuicTestServerTest.java b/test/java/org/chromium/net/testing/QuicTestServerTest.java index c84ae3abb6..f45aab602c 100644 --- a/test/java/org/chromium/net/testing/QuicTestServerTest.java +++ b/test/java/org/chromium/net/testing/QuicTestServerTest.java @@ -136,11 +136,8 @@ public class QuicTestServerTest { + " - name: remote_service\n" + " domains: [\"*\"]\n" + " routes:\n" - + " - match: { prefix: \"/base\" }\n" - + " direct_response:\n" - + " status: 200\n" - + " body:\n" - + " inline_string: \"hello, world\"\n" + + " - match: { prefix: \"/\" }\n" + + " route: { host_rewrite_literal: 127.0.0.1, cluster: h3_remote }\n" + " http3_protocol_options:\n" + " http_filters:\n" + " - name: envoy.router\n" @@ -160,7 +157,7 @@ public class QuicTestServerTest { + " domains: [\"*\"]\n" + " routes:\n" + " - match: { prefix: \"/\" }\n" - + " route: { host_rewrite_literal: lyft.com, cluster: h3_remote }\n" + + " route: { host_rewrite_literal: www.lyft.com, cluster: h3_remote }\n" + " http_filters:\n" + " - name: envoy.router\n" + " typed_config:\n" @@ -180,18 +177,17 @@ public class QuicTestServerTest { + " socket_address: { address: 127.0.0.1, port_value: 10101 }\n" + " typed_extension_protocol_options:\n" + " envoy.extensions.upstreams.http.v3.HttpProtocolOptions:\n" - + - " \"@type\": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions\n" + + " \"@type\": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions\n" + " explicit_http_config:\n" + " http3_protocol_options: {}\n" + " common_http_protocol_options:\n" - + " idle_timeout: 1s\n" + + " idle_timeout: 10s\n" + " transport_socket:\n" + " name: envoy.transport_sockets.quic\n" + " typed_config:\n" + " \"@type\": " + quicUpstreamType + "\n" + " upstream_tls_context:\n" - + " sni: localhost"; + + " sni: www.lyft.com"; private static Engine engine; @@ -300,6 +296,7 @@ RequestHeaders getHeaders() { RequestHeadersBuilder requestHeadersBuilder = new RequestHeadersBuilder(method, url.getProtocol(), url.getAuthority(), url.getPath()); headers.forEach(entry -> requestHeadersBuilder.add(entry.getKey(), entry.getValue())); + // requestHeadersBuilder.add("x-envoy-mobile-upstream-protocol", "http3"); return requestHeadersBuilder.build(); } From 2b61716dc9a389ff278824c8c509ca3498ba861a Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Mon, 4 Oct 2021 19:48:48 +0000 Subject: [PATCH 11/54] add JVM test for the QuicTestServer Signed-off-by: Chidera Olibie --- test/common/integration/quic_test_server.cc | 9 +- .../net/testing/QuicTestServerTest.java | 104 +----------------- 2 files changed, 11 insertions(+), 102 deletions(-) diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc index e7546f1938..c8b358d0ca 100644 --- a/test/common/integration/quic_test_server.cc +++ b/test/common/integration/quic_test_server.cc @@ -150,16 +150,17 @@ void QuicTestServer::startQuicTestServer() { upstream_config_.udp_fake_upstream_ = FakeUpstreamConfig::UdpConfig(); Network::TransportSocketFactoryPtr factory = createUpstreamTlsContext(factory_context_); - // Network::Test::createRawBufferSocketFactory(); + + // Network::TransportSocketFactoryPtr factory = Network::Test::createRawBufferSocketFactory(); int port = 34210; // let the kernel pick a port that is not in use (avoids test races) aupstream = std::make_unique(std::move(factory), port, version_, upstream_config_, false); - aupstream->setLastRequestHeaders(Http::TestRequestHeaderMapImpl{ - {"response_size_bytes", "2"}}); aupstream->setResponseHeaders(std::make_unique( - Http::TestResponseHeaderMapImpl({{":status", "203"}}))); + Http::TestResponseHeaderMapImpl({{":status", "200"}}))); + aupstream->setResponseTrailers(std::make_unique( + Http::TestResponseTrailerMapImpl({{"foo", "bar"}}))); // see what port was selected. std::cerr << "Upstream now listening on " << aupstream->localAddress()->asString() << "\n"; diff --git a/test/java/org/chromium/net/testing/QuicTestServerTest.java b/test/java/org/chromium/net/testing/QuicTestServerTest.java index f45aab602c..9c46334c7d 100644 --- a/test/java/org/chromium/net/testing/QuicTestServerTest.java +++ b/test/java/org/chromium/net/testing/QuicTestServerTest.java @@ -4,6 +4,7 @@ import static org.assertj.core.api.Assertions.fail; import static org.chromium.net.testing.CronetTestRule.getContext; +import io.envoyproxy.envoymobile.LogLevel; import io.envoyproxy.envoymobile.AndroidEngineBuilder; import io.envoyproxy.envoymobile.Custom; import io.envoyproxy.envoymobile.Engine; @@ -51,98 +52,6 @@ public class QuicTestServerTest { private static final String config = "static_resources:\n" + " listeners:\n" - + " - name: h3_remote_listener\n" - + " address:\n" - + " socket_address: { protocol: UDP, address: 127.0.0.1, port_value: 10101 }\n" - + " reuse_port: true\n" - + " udp_listener_config:\n" - + " quic_options: {}\n" - + " downstream_socket_config:\n" - + " prefer_gro: true\n" - + " filter_chains:\n" - + " transport_socket:\n" - + " name: envoy.transport_sockets.quic\n" - + " typed_config:\n" - + " \"@type\": " + quicDownstreamType + "\n" - + " downstream_tls_context:\n" - + " common_tls_context:\n" - + " alpn_protocols: h3\n" - + " tls_certificates:\n" - + " certificate_chain:\n" - + " inline_string: |\n" - + " -----BEGIN CERTIFICATE-----\n" - + " MIIEPjCCAyagAwIBAgIUEuy1WgSCzX6mojPirk7Th6uhNHowDQYJKoZIhvcNAQEL\n" - + " BQAwfzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcM\n" - + " DVNhbiBGcmFuY2lzY28xDTALBgNVBAoMBEx5ZnQxGTAXBgNVBAsMEEx5ZnQgRW5n\n" - + " aW5lZXJpbmcxGTAXBgNVBAMMEFRlc3QgVXBzdHJlYW0gQ0EwHhcNMjAwODA1MTkx\n" - + " NjAyWhcNMjIwODA1MTkxNjAyWjCBgzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNh\n" - + " bGlmb3JuaWExFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xDTALBgNVBAoMBEx5ZnQx\n" - + " GTAXBgNVBAsMEEx5ZnQgRW5naW5lZXJpbmcxHTAbBgNVBAMMFFRlc3QgVXBzdHJl\n" - + " YW0gU2VydmVyMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtpiYA4/I\n" - + " NuflkPe4L/GTslmngNQUCo8TzPXG0gt7uoxr4FeuVy7AaD28S2/hwhbl+bDtHTQY\n" - + " mvBUwNMsYzpND2eQ3sSIumdeLzBEKP2mnnZ9gE/Zd2TIuZl686RpDq0B6ZdZSpCu\n" - + " bqQmmPFLiRNH8JViJZMN5yqMt7T5oq+DnCYQZllqmpAwd6NnhKALrYmZ87oqc0zh\n" - + " kf+5amP7zMYKkwQuRwcx4QPZkEp3+qhszolpAJ52dFGJ+pLuUVDg0Gf0cnxLjFKc\n" - + " 6vcTlj4tsymR4ci58MHRt4EdGdhShw0oaj67gRRfU4Vj61I2ZAVH07kL0mjO2TZT\n" - + " EKrOEJJ7/dtxdwIDAQABo4GsMIGpMAwGA1UdEwEB/wQCMAAwCwYDVR0PBAQDAgXg\n" - + " MB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDATAtBgNVHREEJjAkggoqLmx5\n" - + " ZnQuY29thwR/AAABhxAAAAAAAAAAAAAAAAAAAAABMB0GA1UdDgQWBBQeoC5wxwX5\n" - + " k3ggIN/844/6jKx9czAfBgNVHSMEGDAWgBQ7Zh1TopMm7SY1RCOEO8L1G8IAZDAN\n" - + " BgkqhkiG9w0BAQsFAAOCAQEA18wEg8LnPm99cIouFUFMAO+BpiY2KVa9Bu6x07m9\n" - + " quNFv7/4mLt87sk/umD3LH/tDjqW0D84vhG9a+0yDq7ZrD/P5eK3R+yBINwhe4/x\n" - + " obJlThEsbcZF1FkMnq1rt53izukyQLLQwoVxidQl3HCg3hosWmpH1VBPgwoize6V\n" - + " aAhKLW0n+JSfIE1d80nvZdYlHuCnS6UhLmAbTBCnwT0aGTfzT0Dd4KlYiY8vGZRu\n" - + " tXOw4MzKtJcOL3t7Zpz2mhqN25dyiuyvKEhLXdx48aemwa2t6ISfFKsd0/glnNe/\n" - + " PFZMakzKv1G0xLGURjsInCZ0kePAmerfZN6CBZDo4laYEg==\n" - + " -----END CERTIFICATE-----\n" - + " private_key:\n" - + " inline_string: |\n" - + " -----BEGIN RSA PRIVATE KEY-----\n" - + " MIIEpAIBAAKCAQEAtpiYA4/INuflkPe4L/GTslmngNQUCo8TzPXG0gt7uoxr4Feu\n" - + " Vy7AaD28S2/hwhbl+bDtHTQYmvBUwNMsYzpND2eQ3sSIumdeLzBEKP2mnnZ9gE/Z\n" - + " d2TIuZl686RpDq0B6ZdZSpCubqQmmPFLiRNH8JViJZMN5yqMt7T5oq+DnCYQZllq\n" - + " mpAwd6NnhKALrYmZ87oqc0zhkf+5amP7zMYKkwQuRwcx4QPZkEp3+qhszolpAJ52\n" - + " dFGJ+pLuUVDg0Gf0cnxLjFKc6vcTlj4tsymR4ci58MHRt4EdGdhShw0oaj67gRRf\n" - + " U4Vj61I2ZAVH07kL0mjO2TZTEKrOEJJ7/dtxdwIDAQABAoIBACz6E1+1N/0GTA7U\n" - + " ZgMxP09MNC1QkAs1yQvQcoPknjqKQjxFfMUu1+gVZN80FOjpGQbTJOTvoyvvDQFe\n" - + " Qu3CO58SxKWKxZ8cvR9khTWPnU4lI67KfGejZKoK+zUuh049IV53kGAEmWLZfkRo\n" - + " E1IVdL/3G/DjcyZA3d6WbnM7RnDcqORPnig4lq5HxN76eBdssbxtrAi3Sjy3ChMy\n" - + " BLInnryF4UtaT5xqR26YjgtFmYkunrgXTe1i/ewQgBBkSPXcNr7or69hCCv0SG9e\n" - + " vRsv1r+Uug3/iRZDjEhKBmXWNAZJ/IsDF37ywiyeBdUY+klDX+mWz+0BB0us8b4u\n" - + " LxoZQTECgYEA2Gu9EVC0RMrQ9FF5AgKKJWmZKkOn346RkPrtbl5lbuUgnVdBXJjr\n" - + " wfMZVTD/8E/tMN4EMSGmC9bxCpRRzhrphrm7SHGD6b9O30DH9q0TV0r0A8IG/bMO\n" - + " xJLYjrYVxtEE+KckzvyvfIefbDG7wYkI3u+ObmjBg9t6jcErKlI/PdkCgYEA1/1E\n" - + " T+cpR16iOPz1mz+f/GU4YmPkdSDj/PrjMv0c1OTDvdPiZPpLkhLUKiICnKSKbYjX\n" - + " Ko8fdZc3cmakgD1dXtAfR7Tf/hXQIR5+iHD48I5e9DVlkqMNDObfj82ohTFKVe/P\n" - + " ZSwgDiAPTMFxWr26u/GzY5D3adCQYJyKE2wTh88CgYEAu7vpzGVnmu0ciXNLNvUh\n" - + " BQcvODxsGT9BArTI1Z7I+oOD4TjZmAuHJz1L0lypB7stk+BjXoND2K1hdr3moJUz\n" - + " 0gy3a0YdGd07++nkDBVi26xHNCNRkS2MN/TyKgnFpiuW1mOXSH5lc+7p2h7iMiY/\n" - + " LbQ8p4Xzp//xtZnFafbiqTECgYEAwDN5KZ1r5z24H/xCVv+cT46HSU7ZCr3VA9cC\n" - + " fOouUOitouu9J9xviTJGKKQRLPFi2awOxKmN9ic1SRE7y35P60JKw5WaSdGBXydy\n" - + " s9nMPMyEhM5Lb9y2jUeZo68ACl5dZvG63a4RbGBtHQF67KOvWvXvi2eCM2BMShyi\n" - + " 5jujeZMCgYAjewq1hVqL1FOD8sIFpmndsH3+Dfc7BJ/erqGOX9bQYGvJO4nCe+7K\n" - + " 4o8qFQf4jwdxu0iNxYJIMdn+l4/pz2e7GUFHjgMduUclf27Qj1p+8EyYqp6cmkzM\n" - + " 8mcwRkYo3aM70EmUu0Xxi3d5O5F1bIJ5MkgXaX/zSF2N02B3jXroxQ==\n" - + " -----END RSA PRIVATE KEY-----\n" - + " filters:\n" - + " - name: envoy.filters.network.http_connection_manager\n" - + " typed_config:\n" - + " \"@type\": " + hcmType + "\n" - + " codec_type: HTTP3\n" - + " stat_prefix: remote_hcm\n" - + " route_config:\n" - + " name: remote_route\n" - + " virtual_hosts:\n" - + " - name: remote_service\n" - + " domains: [\"*\"]\n" - + " routes:\n" - + " - match: { prefix: \"/\" }\n" - + " route: { host_rewrite_literal: 127.0.0.1, cluster: h3_remote }\n" - + " http3_protocol_options:\n" - + " http_filters:\n" - + " - name: envoy.router\n" - + " typed_config:\n" - + " \"@type\": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router\n" + " - name: base_api_listener\n" + " address:\n" + " socket_address: { protocol: TCP, address: 0.0.0.0, port_value: 10000 }\n" @@ -157,7 +66,7 @@ public class QuicTestServerTest { + " domains: [\"*\"]\n" + " routes:\n" + " - match: { prefix: \"/\" }\n" - + " route: { host_rewrite_literal: www.lyft.com, cluster: h3_remote }\n" + + " route: { cluster: h3_remote }\n" + " http_filters:\n" + " - name: envoy.router\n" + " typed_config:\n" @@ -174,14 +83,14 @@ public class QuicTestServerTest { + " - lb_endpoints:\n" + " - endpoint:\n" + " address:\n" - + " socket_address: { address: 127.0.0.1, port_value: 10101 }\n" + + " socket_address: { address: 127.0.0.1, port_value: 34210 }\n" + " typed_extension_protocol_options:\n" + " envoy.extensions.upstreams.http.v3.HttpProtocolOptions:\n" + " \"@type\": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions\n" + " explicit_http_config:\n" + " http3_protocol_options: {}\n" + " common_http_protocol_options:\n" - + " idle_timeout: 10s\n" + + " idle_timeout: 1s\n" + " transport_socket:\n" + " name: envoy.transport_sockets.quic\n" + " typed_config:\n" @@ -209,6 +118,7 @@ public void setUpEngine() throws Exception { if (engine == null) { CountDownLatch latch = new CountDownLatch(1); engine = new AndroidEngineBuilder(getContext().getApplicationContext(), new Custom(config)) + .addLogLevel(LogLevel.TRACE) .setOnEngineRunning(() -> { latch.countDown(); return null; @@ -231,10 +141,8 @@ public void get_simple() throws Exception { .setUrl(QuicTestServer.getServerURL()); QuicTestServerTest.Response response = sendRequest(requestScenario); - System.err.println(response.getBodyAsString()); - System.err.println(response.getHeaders()); assertThat(response.getHeaders().getHttpStatus()).isEqualTo(200); - assertThat(response.getBodyAsString()).isEqualTo("hello, world"); + assertThat(response.getBodyAsString()).isEqualTo("aaaaaaaaaa"); assertThat(response.getEnvoyError()).isNull(); } From 75f52ef687fd0a928b9b52f6389c44a223d6eb73 Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Thu, 7 Oct 2021 12:29:45 +0000 Subject: [PATCH 12/54] wip Signed-off-by: Chidera Olibie --- test/common/integration/quic_test_server.cc | 29 +++---------------- test/common/integration/quic_test_server.h | 1 - .../jni/quic_test_server_jni_interface.cc | 6 ++-- .../chromium/net/testing/QuicTestServer.java | 6 +--- .../net/testing/QuicTestServerTest.java | 2 +- 5 files changed, 8 insertions(+), 36 deletions(-) diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc index c8b358d0ca..81bbdf9bcf 100644 --- a/test/common/integration/quic_test_server.cc +++ b/test/common/integration/quic_test_server.cc @@ -109,29 +109,7 @@ Network::TransportSocketFactoryPtr QuicTestServer::createUpstreamTlsContext( QuicTestServer::QuicTestServer() : api_(Api::createApiForTest(stats_store_, time_system_)), - version_(Network::Address::IpVersion::v4), - config_helper_(version_, *api_, ConfigHelper::baseConfig() + R"EOF( - filter_chains: - filters: - - name: envoy.filters.network.http_connection_manager - typed_config: - "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager - codec_type: HTTP3 - stat_prefix: remote_hcm - route_config: - name: remote_route - virtual_hosts: - - name: remote_service - domains: ["*"] - routes: - - match: { prefix: "/" } - direct_response: { status: 200 } - http3_protocol_options: - http_filters: - - name: envoy.router - typed_config: - "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router - )EOF") { + version_(Network::Address::IpVersion::v4) { ON_CALL(factory_context_, api()).WillByDefault(testing::ReturnRef(*api_)); ON_CALL(factory_context_, scope()).WillByDefault(testing::ReturnRef(stats_store_)); @@ -156,9 +134,10 @@ void QuicTestServer::startQuicTestServer() { int port = 34210; // let the kernel pick a port that is not in use (avoids test races) aupstream = std::make_unique(std::move(factory), port, version_, upstream_config_, false); + // upstream = std::make_unique(std::move(factory), port, version_, upstream_config_); - aupstream->setResponseHeaders(std::make_unique( - Http::TestResponseHeaderMapImpl({{":status", "200"}}))); + //aupstream->setResponseHeaders(std::make_unique( + // Http::TestResponseHeaderMapImpl({{":status", "200"}}))); aupstream->setResponseTrailers(std::make_unique( Http::TestResponseTrailerMapImpl({{"foo", "bar"}}))); diff --git a/test/common/integration/quic_test_server.h b/test/common/integration/quic_test_server.h index 4e0db398aa..725a6fa64c 100644 --- a/test/common/integration/quic_test_server.h +++ b/test/common/integration/quic_test_server.h @@ -28,7 +28,6 @@ class QuicTestServer { Event::GlobalTimeSystem time_system_; Api::ApiPtr api_; Network::Address::IpVersion version_; - ConfigHelper config_helper_; std::unique_ptr upstream; std::unique_ptr aupstream; diff --git a/test/common/jni/quic_test_server_jni_interface.cc b/test/common/jni/quic_test_server_jni_interface.cc index 25820bccc3..33f155c49c 100644 --- a/test/common/jni/quic_test_server_jni_interface.cc +++ b/test/common/jni/quic_test_server_jni_interface.cc @@ -6,21 +6,20 @@ #include "library/common/jni/jni_utility.h" #include "library/common/jni/jni_version.h" -// Quic Test ServerJniLibrary // NOLINT(namespace-envoy) +// Quic Test ServerJniLibrary + extern "C" JNIEXPORT void JNICALL Java_org_chromium_net_testing_QuicTestServer_nativeStartQuicTestServer(JNIEnv* env, jclass clazz, jstring file_path, jstring test_data_dir) { - // TODO: implement nativeStartQuicTestServer() jni_log("[QTS]", "starting server"); start_server(); } extern "C" JNIEXPORT jint JNICALL Java_org_chromium_net_testing_QuicTestServer_nativeGetServerPort(JNIEnv* env, jclass clazz) { - // TODO: implement nativeGetServerPort() jni_log("[QTS]", "getting server port"); return get_server_port(); } @@ -28,7 +27,6 @@ Java_org_chromium_net_testing_QuicTestServer_nativeGetServerPort(JNIEnv* env, jc extern "C" JNIEXPORT void JNICALL Java_org_chromium_net_testing_QuicTestServer_nativeShutdownQuicTestServer(JNIEnv* env, jclass clazz) { - // TODO: implement nativeShutdownQuicTestServer() jni_log("[QTS]", "shutting down server"); shutdown_server(); } \ No newline at end of file diff --git a/test/java/org/chromium/net/testing/QuicTestServer.java b/test/java/org/chromium/net/testing/QuicTestServer.java index 8ef2490f46..2d4d200b86 100644 --- a/test/java/org/chromium/net/testing/QuicTestServer.java +++ b/test/java/org/chromium/net/testing/QuicTestServer.java @@ -28,9 +28,6 @@ public static void startQuicTestServer(Context context) { TestFilesInstaller.installIfNeeded(context); nativeStartQuicTestServer(TestFilesInstaller.getInstalledPath(context), UrlUtils.getIsolatedTestRoot()); - - // sBlock.block(); - // sBlock.close(); sServerRunning = true; } @@ -50,8 +47,7 @@ public static String getServerURL() { } public static String getServerHost() { - // return CronetTestUtil.QUIC_FAKE_HOST; - return "127.0.0.1"; + return "test.example.com"; } public static int getServerPort() { return nativeGetServerPort(); } diff --git a/test/java/org/chromium/net/testing/QuicTestServerTest.java b/test/java/org/chromium/net/testing/QuicTestServerTest.java index 9c46334c7d..ccbc60a39b 100644 --- a/test/java/org/chromium/net/testing/QuicTestServerTest.java +++ b/test/java/org/chromium/net/testing/QuicTestServerTest.java @@ -49,6 +49,7 @@ public class QuicTestServerTest { private static final String quicUpstreamType = "type.googleapis.com/envoy.extensions.transport_sockets.quic.v3.QuicUpstreamTransport"; + private static final String config = "static_resources:\n" + " listeners:\n" @@ -204,7 +205,6 @@ RequestHeaders getHeaders() { RequestHeadersBuilder requestHeadersBuilder = new RequestHeadersBuilder(method, url.getProtocol(), url.getAuthority(), url.getPath()); headers.forEach(entry -> requestHeadersBuilder.add(entry.getKey(), entry.getValue())); - // requestHeadersBuilder.add("x-envoy-mobile-upstream-protocol", "http3"); return requestHeadersBuilder.build(); } From 9004b8ce0c419b2ce14c3f9ad1fef2cf5395b4e4 Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Fri, 8 Oct 2021 11:01:00 +0000 Subject: [PATCH 13/54] add QuicTestServer and its associated test Signed-off-by: Chidera Olibie --- bazel/kotlin_test.bzl | 3 +- .../chromium/net/impl/CronetUrlRequest.java | 3 +- test/common/integration/BUILD | 25 -- test/common/integration/quic_test_server.cc | 23 +- test/common/integration/quic_test_server.h | 8 - test/common/jni/BUILD | 7 - test/java/org/chromium/net/BUILD | 22 -- test/java/org/chromium/net/QuicTest.java | 301 ------------------ .../chromium/net/testing/QuicTestServer.java | 4 +- .../net/testing/QuicTestServerTest.java | 6 +- 10 files changed, 12 insertions(+), 390 deletions(-) delete mode 100644 test/java/org/chromium/net/QuicTest.java diff --git a/bazel/kotlin_test.bzl b/bazel/kotlin_test.bzl index 547780a4a3..5d0c3e0569 100644 --- a/bazel/kotlin_test.bzl +++ b/bazel/kotlin_test.bzl @@ -1,5 +1,4 @@ -load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library", "kt_jvm_test") -load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories") +load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_test") load("//bazel:kotlin_lib.bzl", "native_lib_name") def _internal_kt_test(name, srcs, deps = [], data = [], jvm_flags = [], repository = ""): diff --git a/library/java/org/chromium/net/impl/CronetUrlRequest.java b/library/java/org/chromium/net/impl/CronetUrlRequest.java index d0e13e9de2..1fd5f0d9cf 100644 --- a/library/java/org/chromium/net/impl/CronetUrlRequest.java +++ b/library/java/org/chromium/net/impl/CronetUrlRequest.java @@ -563,7 +563,8 @@ public void onCancel(EnvoyStreamIntel streamIntel) { headers.computeIfAbsent(":authority", unused -> new ArrayList<>()).add(url.getAuthority()); headers.computeIfAbsent(":method", unused -> new ArrayList<>()).add(initialMethod); - headers.computeIfAbsent(":path", unused -> new ArrayList<>()).add(url.getFile().isEmpty() ? "/" : url.getFile()); + headers.computeIfAbsent(":path", unused -> new ArrayList<>()) + .add(url.getFile().isEmpty() ? "/" : url.getFile()); headers.computeIfAbsent(":scheme", unused -> new ArrayList<>()).add(url.getProtocol()); boolean hasUserAgent = false; diff --git a/test/common/integration/BUILD b/test/common/integration/BUILD index 20c5e937fa..980de26aab 100644 --- a/test/common/integration/BUILD +++ b/test/common/integration/BUILD @@ -20,28 +20,6 @@ envoy_cc_test( ], ) -# ignore, used this test that the server java file works standalone -envoy_cc_test( - name = "quic_s", - srcs = ["quic_s.cc"], - data = [ - "@envoy//test/config/integration/certs", - ], - repository = "@envoy", - deps = [ - "@envoy//source/common/quic:quic_stat_names_lib", - "@envoy//source/common/quic:active_quic_listener_lib", - "@envoy//source/common/quic:quic_factory_lib", - "@envoy//source/common/stats:isolated_store_lib", - "@envoy//test/config:utility_lib", - "@envoy//test/integration:autonomous_upstream_lib", - "@envoy//test/integration:fake_upstream_lib", - "@envoy//test/test_common:network_utility_lib", - "@envoy_api//envoy/extensions/transport_sockets/quic/v3:pkg_cc_proto", - # "@envoy_api//envoy/extensions/transport_sockets/quic/v3:pkg_cc_proto", - ], -) - # interface libs for jni implementation envoy_cc_test_library( name = "quic_test_server_interface_lib", @@ -70,11 +48,8 @@ envoy_cc_test_library( "@envoy//source/common/stats:isolated_store_lib", "@envoy//test:test_pch", "@envoy//source/exe:process_wide_lib", - "@envoy//test/mocks/access_log:access_log_mocks", - "@envoy//test/config:utility_lib", "@envoy//source/common/common:logger_lib", "@envoy//test/integration:autonomous_upstream_lib", - "@envoy//test/integration:fake_upstream_lib", "@envoy//test/test_common:network_utility_lib", "@envoy_api//envoy/extensions/filters/common/matcher/action/v3:pkg_cc_proto", "@envoy_api//envoy/extensions/transport_sockets/quic/v3:pkg_cc_proto", diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc index 81bbdf9bcf..0770f2878c 100644 --- a/test/common/integration/quic_test_server.cc +++ b/test/common/integration/quic_test_server.cc @@ -112,15 +112,14 @@ QuicTestServer::QuicTestServer() version_(Network::Address::IpVersion::v4) { ON_CALL(factory_context_, api()).WillByDefault(testing::ReturnRef(*api_)); ON_CALL(factory_context_, scope()).WillByDefault(testing::ReturnRef(stats_store_)); - } void QuicTestServer::startQuicTestServer() { // pre-setup: see https://github.com/envoyproxy/envoy/blob/main/test/test_runner.cc ProcessWide process_wide; Thread::MutexBasicLockable lock; - Logger::Context logging_state(spdlog::level::level_enum::err, "[%Y-%m-%d %T.%e][%t][%l][%n] [%g:%#] %v", lock, false, - false); + Logger::Context logging_state(spdlog::level::level_enum::err, + "[%Y-%m-%d %T.%e][%t][%l][%n] [%g:%#] %v", lock, false, false); // end pre-setup FakeUpstreamConfig upstream_config_{time_system_}; @@ -129,27 +128,15 @@ void QuicTestServer::startQuicTestServer() { Network::TransportSocketFactoryPtr factory = createUpstreamTlsContext(factory_context_); - // Network::TransportSocketFactoryPtr factory = Network::Test::createRawBufferSocketFactory(); - - int port = 34210; // let the kernel pick a port that is not in use (avoids test races) + int port = 34210; aupstream = std::make_unique(std::move(factory), port, version_, upstream_config_, false); - // upstream = std::make_unique(std::move(factory), port, version_, upstream_config_); - - //aupstream->setResponseHeaders(std::make_unique( - // Http::TestResponseHeaderMapImpl({{":status", "200"}}))); - aupstream->setResponseTrailers(std::make_unique( - Http::TestResponseTrailerMapImpl({{"foo", "bar"}}))); - // see what port was selected. + // see upstream address std::cerr << "Upstream now listening on " << aupstream->localAddress()->asString() << "\n"; - } -void QuicTestServer::shutdownQuicTestServer() { - aupstream.reset(); - // FAIL() << "this way blaze will give you a test log"; -} +void QuicTestServer::shutdownQuicTestServer() { aupstream.reset(); } int QuicTestServer::getServerPort() { return aupstream->localAddress()->ip()->port(); } } // namespace Envoy diff --git a/test/common/integration/quic_test_server.h b/test/common/integration/quic_test_server.h index 725a6fa64c..5a2a7d54e3 100644 --- a/test/common/integration/quic_test_server.h +++ b/test/common/integration/quic_test_server.h @@ -5,19 +5,12 @@ // test_runner setups #include "source/common/common/logger.h" -#include "source/common/common/logger_delegates.h" #include "source/exe/process_wide.h" -#include "test/mocks/access_log/mocks.h" - -#include "gtest/gtest.h" #include "absl/strings/str_format.h" #include "envoy/extensions/transport_sockets/quic/v3/quic_transport.pb.h" #include "test/mocks/server/transport_socket_factory_context.h" -#include "test/test_common/environment.h" -#include "test/integration/fake_upstream.h" #include "test/integration/autonomous_upstream.h" -#include "test/config/utility.h" #include "test/test_common/network_utility.h" namespace Envoy { @@ -28,7 +21,6 @@ class QuicTestServer { Event::GlobalTimeSystem time_system_; Api::ApiPtr api_; Network::Address::IpVersion version_; - std::unique_ptr upstream; std::unique_ptr aupstream; void setup(); diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index 87c051b591..e5f2dd42cc 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -4,13 +4,6 @@ licenses(["notice"]) # Apache 2 envoy_package() -### Targets for local execution -## OS X binary (.jnilib) for NDK testing -#envoy_mobile_so_to_jni_lib_test( -# name = "libquic_test_server_jni.jnilib", -# native_dep = "libquic_test_server_jni.so", -#) - # dynamic library for the Envoy Mobile aar cc_binary( name = "libquic_test_server_jni.so", diff --git a/test/java/org/chromium/net/BUILD b/test/java/org/chromium/net/BUILD index 20c594d2de..a871a3a1b1 100644 --- a/test/java/org/chromium/net/BUILD +++ b/test/java/org/chromium/net/BUILD @@ -32,28 +32,6 @@ envoy_mobile_android_test( ], ) -envoy_mobile_android_test( - name = "quic_test", - srcs = [ - "QuicTest.java", - ], - library_path = "library/common/jni:test/common/jni", - native_deps = [ - "//library/common/jni:libndk_envoy_jni.so", - "//library/common/jni:libndk_envoy_jni.jnilib", - "//test/common/jni:libquic_test_server_jni.so", - ], - deps = [ - "//library/java/io/envoyproxy/envoymobile/engine:envoy_base_engine_lib", - "//library/java/io/envoyproxy/envoymobile/engine:envoy_engine_lib", - "//library/java/org/chromium/net", - "//library/java/org/chromium/net/impl:cronvoy", - "//library/kotlin/io/envoyproxy/envoymobile:envoy_interfaces_lib", - "//library/kotlin/io/envoyproxy/envoymobile:envoy_lib", - "//test/java/org/chromium/net/testing", - ], -) - envoy_mobile_android_test( name = "cronet_url_request_context_test", srcs = [ diff --git a/test/java/org/chromium/net/QuicTest.java b/test/java/org/chromium/net/QuicTest.java deleted file mode 100644 index ea4796ab2c..0000000000 --- a/test/java/org/chromium/net/QuicTest.java +++ /dev/null @@ -1,301 +0,0 @@ -package org.chromium.net; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import static org.chromium.net.testing.CronetTestRule.getContext; -import static org.chromium.net.testing.CronetTestRule.getTestStorage; - -import androidx.test.ext.junit.runners.AndroidJUnit4; -import androidx.test.filters.LargeTest; -import androidx.test.filters.SmallTest; - -import org.chromium.net.testing.CronetTestRule; -import org.chromium.net.testing.CronetTestUtil; -import org.chromium.net.testing.QuicTestServer; -import org.chromium.net.testing.TestUrlRequestCallback; -import org.json.JSONObject; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import android.util.Log; -import org.chromium.net.testing.Feature; -import org.chromium.net.testing.CronetTestRule.OnlyRunNativeCronet; -import org.chromium.net.testing.MetricsTestUtil.TestRequestFinishedListener; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.Date; -import java.util.concurrent.Executors; - -/** - * Tests making requests using QUIC. - */ -@RunWith(AndroidJUnit4.class) -public class QuicTest { - @Rule public final CronetTestRule mTestRule = new CronetTestRule(); - - private static final String TAG = QuicTest.class.getSimpleName(); - private ExperimentalCronetEngine.Builder mBuilder; - - @Before - public void setUp() throws Exception { - // Load library first, since we need the Quic test server's URL. - System.loadLibrary("quic_test_server_jni"); - QuicTestServer.startQuicTestServer(getContext()); - mBuilder = new ExperimentalCronetEngine.Builder(getContext()); - // mBuilder.enableNetworkQualityEstimator(true).enableQuic(true); - // mBuilder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getServerPort(), - // QuicTestServer.getServerPort()); - // - // // The pref may not be written if the computed Effective Connection Type (ECT) matches the - // // default ECT for the current connection type. Force the ECT to "Slow-2G". Since "Slow-2G" - // // is not the default ECT for any connection type, this ensures that the pref is written to. - // JSONObject nqeParams = new JSONObject().put("force_effective_connection_type", "Slow-2G"); - // // TODO(mgersh): Enable connection migration once it works, see http://crbug.com/634910 - // JSONObject quicParams = new JSONObject() - // .put("connection_options", "PACE,IW10,FOO,DEADBEEF") - // .put("max_server_configs_stored_in_properties", 2) - // .put("idle_connection_timeout_seconds", 300) - // .put("migrate_sessions_on_network_change_v2", false) - // .put("migrate_sessions_early_v2", false) - // .put("race_cert_verification", true); - // JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules(); - // JSONObject experimentalOptions = new JSONObject() - // .put("QUIC", quicParams) - // .put("HostResolverRules", hostResolverParams) - // .put("NetworkQualityEstimator", nqeParams); - // mBuilder.setExperimentalOptions(experimentalOptions.toString()); - // mBuilder.setStoragePath(getTestStorage()); - // mBuilder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK_NO_HTTP, 1000 * 1024); - // CronetTestUtil.setMockCertVerifierForTesting( - // mBuilder, QuicTestServer.createMockCertVerifier()); - } - - @After - public void tearDown() throws Exception { - System.out.println("QTS: quicTestJavaL88\n"); - - QuicTestServer.shutdownQuicTestServer(); - } - - @Test - @LargeTest - @Feature({"Cronet"}) - @OnlyRunNativeCronet - public void testQuicLoadUrl() throws Exception { - ExperimentalCronetEngine cronetEngine = mBuilder.build(); - String quicURL = QuicTestServer.getServerURL(); - // Thread.sleep(100000); - TestUrlRequestCallback callback = new TestUrlRequestCallback(); - // Although the native stack races QUIC and SPDY for the first request, - // since there is no http server running on the corresponding TCP port, - // QUIC will always succeed with a 200 (see - // net::HttpStreamFactoryImpl::Request::OnStreamFailed). - UrlRequest.Builder requestBuilder = - cronetEngine.newUrlRequestBuilder(quicURL, callback, callback.getExecutor()); - requestBuilder.build().start(); - callback.blockForDone(); - System.out.println("QTS:" + callback.mResponseInfo); - assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); - String expectedContent = "This is a simple text file served by QUIC.\n"; - assertEquals(expectedContent, callback.mResponseAsString); - assertIsQuic(callback.mResponseInfo); - // The total received bytes should be larger than the content length, to account for - // headers. - assertTrue(callback.mResponseInfo.getReceivedByteCount() > expectedContent.length()); - // This test takes a long time, since the update will only be scheduled - // after kUpdatePrefsDelayMs in http_server_properties_manager.cc. - while (true) { - Log.i(TAG, "Still waiting for pref file update....."); - // Thread.sleep(10000); - boolean contains = false; - try { - if (fileContainsString("local_prefs.json", "quic")) - break; - } catch (FileNotFoundException e) { - // Ignored this exception since the file will only be created when updates are - // flushed to the disk. - } - } - assertTrue(fileContainsString("local_prefs.json", QuicTestServer.getServerHost() + ":" + - QuicTestServer.getServerPort())); - cronetEngine.shutdown(); - - // Make another request using a new context but with no QUIC hints. - ExperimentalCronetEngine.Builder builder = new ExperimentalCronetEngine.Builder(getContext()); - builder.setStoragePath(getTestStorage()); - builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK, 1000 * 1024); - builder.enableQuic(true); - JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules(); - JSONObject experimentalOptions = new JSONObject().put("HostResolverRules", hostResolverParams); - builder.setExperimentalOptions(experimentalOptions.toString()); - CronetTestUtil.setMockCertVerifierForTesting(builder, QuicTestServer.createMockCertVerifier()); - cronetEngine = builder.build(); - TestUrlRequestCallback callback2 = new TestUrlRequestCallback(); - requestBuilder = cronetEngine.newUrlRequestBuilder(quicURL, callback2, callback2.getExecutor()); - requestBuilder.build().start(); - callback2.blockForDone(); - assertEquals(200, callback2.mResponseInfo.getHttpStatusCode()); - assertEquals(expectedContent, callback2.mResponseAsString); - assertIsQuic(callback.mResponseInfo); - // The total received bytes should be larger than the content length, to account for - // headers. - assertTrue(callback2.mResponseInfo.getReceivedByteCount() > expectedContent.length()); - cronetEngine.shutdown(); - } - - // Returns whether a file contains a particular string. - private boolean fileContainsString(String filename, String content) throws IOException { - File file = new File(getTestStorage() + "/prefs/" + filename); - FileInputStream fileInputStream = new FileInputStream(file); - byte[] data = new byte[(int)file.length()]; - fileInputStream.read(data); - fileInputStream.close(); - return new String(data, "UTF-8").contains(content); - } - - /** - * Tests that the network quality listeners are propoerly notified when QUIC is enabled. - */ - // @Test - // @LargeTest - // @Feature({"Cronet"}) - // @OnlyRunNativeCronet - // @SuppressWarnings("deprecation") - // public void testNQEWithQuic() throws Exception { - // ExperimentalCronetEngine cronetEngine = mBuilder.build(); - // String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; - // - // TestNetworkQualityRttListener rttListener = - // new TestNetworkQualityRttListener(Executors.newSingleThreadExecutor()); - // TestNetworkQualityThroughputListener throughputListener = - // new TestNetworkQualityThroughputListener(Executors.newSingleThreadExecutor()); - // - // cronetEngine.addRttListener(rttListener); - // cronetEngine.addThroughputListener(throughputListener); - // - // cronetEngine.configureNetworkQualityEstimatorForTesting(true, true, true); - // TestUrlRequestCallback callback = new TestUrlRequestCallback(); - // - // // Although the native stack races QUIC and SPDY for the first request, - // // since there is no http server running on the corresponding TCP port, - // // QUIC will always succeed with a 200 (see - // // net::HttpStreamFactoryImpl::Request::OnStreamFailed). - // UrlRequest.Builder requestBuilder = - // cronetEngine.newUrlRequestBuilder(quicURL, callback, callback.getExecutor()); - // requestBuilder.build().start(); - // callback.blockForDone(); - // - // assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); - // String expectedContent = "This is a simple text file served by QUIC.\n"; - // assertEquals(expectedContent, callback.mResponseAsString); - // assertIsQuic(callback.mResponseInfo); - // - // // Throughput observation is posted to the network quality estimator on the network thread - // // after the UrlRequest is completed. The observations are then eventually posted to - // // throughput listeners on the executor provided to network quality. - // throughputListener.waitUntilFirstThroughputObservationReceived(); - // - // // Wait for RTT observation (at the URL request layer) to be posted. - // rttListener.waitUntilFirstUrlRequestRTTReceived(); - // - // assertTrue(throughputListener.throughputObservationCount() > 0); - // - // // Check RTT observation count after throughput observation has been received. This ensures - // // that executor has finished posting the RTT observation to the RTT listeners. - // // NETWORK_QUALITY_OBSERVATION_SOURCE_URL_REQUEST - // assertTrue(rttListener.rttObservationCount(0) > 0); - // - // // NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC - // assertTrue(rttListener.rttObservationCount(2) > 0); - // - // // Verify that effective connection type callback is received and - // // effective connection type is correctly set. - // assertTrue( - // cronetEngine.getEffectiveConnectionType() != EffectiveConnectionType.TYPE_UNKNOWN); - // - // // Verify that the HTTP RTT, transport RTT and downstream throughput - // // estimates are available. - // assertTrue(cronetEngine.getHttpRttMs() >= 0); - // assertTrue(cronetEngine.getTransportRttMs() >= 0); - // assertTrue(cronetEngine.getDownstreamThroughputKbps() >= 0); - // - // // Verify that the cached estimates were written to the prefs. - // while (true) { - // Log.i(TAG, "Still waiting for pref file update....."); - // Thread.sleep(10000); - // try { - // if (fileContainsString("local_prefs.json", "network_qualities")) { - // break; - // } - // } catch (FileNotFoundException e) { - // // Ignored this exception since the file will only be created when updates are - // // flushed to the disk. - // } - // } - // assertTrue(fileContainsString("local_prefs.json", "network_qualities")); - // cronetEngine.shutdown(); - // } - // - // @Test - // @SmallTest - // @OnlyRunNativeCronet - // @Feature({"Cronet"}) - // public void testMetricsWithQuic() throws Exception { - // ExperimentalCronetEngine cronetEngine = mBuilder.build(); - // TestRequestFinishedListener requestFinishedListener = new TestRequestFinishedListener(); - // cronetEngine.addRequestFinishedListener(requestFinishedListener); - // - // String quicURL = QuicTestServer.getServerURL() + "/simple.txt"; - // TestUrlRequestCallback callback = new TestUrlRequestCallback(); - // - // UrlRequest.Builder requestBuilder = - // cronetEngine.newUrlRequestBuilder(quicURL, callback, callback.getExecutor()); - // Date startTime = new Date(); - // requestBuilder.build().start(); - // callback.blockForDone(); - // requestFinishedListener.blockUntilDone(); - // Date endTime = new Date(); - // - // assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); - // assertIsQuic(callback.mResponseInfo); - // - // RequestFinishedInfo requestInfo = requestFinishedListener.getRequestInfo(); - // MetricsTestUtil.checkRequestFinishedInfo(requestInfo, quicURL, startTime, endTime); - // assertEquals(RequestFinishedInfo.SUCCEEDED, requestInfo.getFinishedReason()); - // MetricsTestUtil.checkHasConnectTiming(requestInfo.getMetrics(), startTime, endTime, true); - // - // // Second request should use the same connection and not have ConnectTiming numbers - // callback = new TestUrlRequestCallback(); - // requestFinishedListener.reset(); - // requestBuilder = - // cronetEngine.newUrlRequestBuilder(quicURL, callback, callback.getExecutor()); - // startTime = new Date(); - // requestBuilder.build().start(); - // callback.blockForDone(); - // requestFinishedListener.blockUntilDone(); - // endTime = new Date(); - // - // assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); - // assertIsQuic(callback.mResponseInfo); - // - // requestInfo = requestFinishedListener.getRequestInfo(); - // MetricsTestUtil.checkRequestFinishedInfo(requestInfo, quicURL, startTime, endTime); - // assertEquals(RequestFinishedInfo.SUCCEEDED, requestInfo.getFinishedReason()); - // MetricsTestUtil.checkNoConnectTiming(requestInfo.getMetrics()); - // - // cronetEngine.shutdown(); - // } - - // Helper method to assert that the request is negotiated over QUIC. - private void assertIsQuic(UrlResponseInfo responseInfo) { - assertTrue(responseInfo.getNegotiatedProtocol().startsWith("http/2+quic") || - responseInfo.getNegotiatedProtocol().startsWith("h3")); - } -} diff --git a/test/java/org/chromium/net/testing/QuicTestServer.java b/test/java/org/chromium/net/testing/QuicTestServer.java index 2d4d200b86..efe862cb08 100644 --- a/test/java/org/chromium/net/testing/QuicTestServer.java +++ b/test/java/org/chromium/net/testing/QuicTestServer.java @@ -46,9 +46,7 @@ public static String getServerURL() { return "https://" + getServerHost() + ":" + getServerPort() + "/"; } - public static String getServerHost() { - return "test.example.com"; - } + public static String getServerHost() { return "test.example.com"; } public static int getServerPort() { return nativeGetServerPort(); } diff --git a/test/java/org/chromium/net/testing/QuicTestServerTest.java b/test/java/org/chromium/net/testing/QuicTestServerTest.java index ccbc60a39b..3ad9e496fc 100644 --- a/test/java/org/chromium/net/testing/QuicTestServerTest.java +++ b/test/java/org/chromium/net/testing/QuicTestServerTest.java @@ -87,7 +87,8 @@ public class QuicTestServerTest { + " socket_address: { address: 127.0.0.1, port_value: 34210 }\n" + " typed_extension_protocol_options:\n" + " envoy.extensions.upstreams.http.v3.HttpProtocolOptions:\n" - + " \"@type\": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions\n" + + + " \"@type\": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions\n" + " explicit_http_config:\n" + " http3_protocol_options: {}\n" + " common_http_protocol_options:\n" @@ -198,13 +199,12 @@ private static class RequestScenario { private URL url; private RequestMethod method = null; private final List bodyChunks = new ArrayList<>(); - private final List> headers = new ArrayList<>(); private final boolean closeBodyStream = false; RequestHeaders getHeaders() { RequestHeadersBuilder requestHeadersBuilder = new RequestHeadersBuilder(method, url.getProtocol(), url.getAuthority(), url.getPath()); - headers.forEach(entry -> requestHeadersBuilder.add(entry.getKey(), entry.getValue())); + requestHeadersBuilder.add("no_trailers", "0"); return requestHeadersBuilder.build(); } From 48646766c731fcad860b186250c085cca73f8934 Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Fri, 8 Oct 2021 11:27:48 +0000 Subject: [PATCH 14/54] checkout to correct envoy version Signed-off-by: Chidera Olibie --- envoy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/envoy b/envoy index 539ebc03d0..5423325ccf 160000 --- a/envoy +++ b/envoy @@ -1 +1 @@ -Subproject commit 539ebc03d09a2b6aff85e2e22e1d71e80d973b47 +Subproject commit 5423325ccf04c7f50069cb8662e51208526bd4a9 From 69983ddd799d5b3bab61e4ecf89657acdb62a6ec Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Mon, 11 Oct 2021 13:45:53 +0000 Subject: [PATCH 15/54] Fix thread issue Signed-off-by: Chidera Olibie --- test/common/integration/quic_test_server.cc | 1 + test/common/integration/quic_test_server.h | 2 +- test/common/integration/quic_test_server_interface.cc | 2 +- test/common/jni/BUILD | 7 ++++++- test/common/jni/quic_test_server_jni_interface.cc | 2 +- test/java/org/chromium/net/testing/QuicTestServer.java | 2 +- 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc index 0770f2878c..ba2d0506e6 100644 --- a/test/common/integration/quic_test_server.cc +++ b/test/common/integration/quic_test_server.cc @@ -116,6 +116,7 @@ QuicTestServer::QuicTestServer() void QuicTestServer::startQuicTestServer() { // pre-setup: see https://github.com/envoyproxy/envoy/blob/main/test/test_runner.cc + Thread::TestThread test_thread; ProcessWide process_wide; Thread::MutexBasicLockable lock; Logger::Context logging_state(spdlog::level::level_enum::err, diff --git a/test/common/integration/quic_test_server.h b/test/common/integration/quic_test_server.h index 5a2a7d54e3..21790ac8e0 100644 --- a/test/common/integration/quic_test_server.h +++ b/test/common/integration/quic_test_server.h @@ -37,4 +37,4 @@ class QuicTestServer { int getServerPort(); }; -} // namespace Envoy \ No newline at end of file +} // namespace Envoy diff --git a/test/common/integration/quic_test_server_interface.cc b/test/common/integration/quic_test_server_interface.cc index 09e33e9138..dee22fb44c 100644 --- a/test/common/integration/quic_test_server_interface.cc +++ b/test/common/integration/quic_test_server_interface.cc @@ -31,4 +31,4 @@ int get_server_port() { } // TODO (colibie) write a more suitable error code return 1; // failure -} \ No newline at end of file +} diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index e5f2dd42cc..4ea4329f54 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -14,7 +14,11 @@ cc_binary( ], copts = ["-std=c++17"], linkopts = [ - ], + "-lm", + ] + select({ + "@envoy//bazel:dbg_build": ["-Wl,--build-id=sha1"], + "//conditions:default": ["-Wl,-s"], + }), linkshared = True, deps = [ "//bazel:jni", @@ -23,5 +27,6 @@ cc_binary( "//library/common/jni:base_java_jni_lib", "//library/common/jni:java_jni_support", "//test/common/integration:quic_test_server_interface_lib", + "@envoy_mobile_extra_jni_deps//:extra_jni_dep", ], ) diff --git a/test/common/jni/quic_test_server_jni_interface.cc b/test/common/jni/quic_test_server_jni_interface.cc index 33f155c49c..b3052c1daf 100644 --- a/test/common/jni/quic_test_server_jni_interface.cc +++ b/test/common/jni/quic_test_server_jni_interface.cc @@ -29,4 +29,4 @@ Java_org_chromium_net_testing_QuicTestServer_nativeShutdownQuicTestServer(JNIEnv jclass clazz) { jni_log("[QTS]", "shutting down server"); shutdown_server(); -} \ No newline at end of file +} diff --git a/test/java/org/chromium/net/testing/QuicTestServer.java b/test/java/org/chromium/net/testing/QuicTestServer.java index efe862cb08..fdb2c6e7df 100644 --- a/test/java/org/chromium/net/testing/QuicTestServer.java +++ b/test/java/org/chromium/net/testing/QuicTestServer.java @@ -68,4 +68,4 @@ private static void onServerStarted() { private static native void nativeStartQuicTestServer(String filePath, String testDataDir); private static native void nativeShutdownQuicTestServer(); private static native int nativeGetServerPort(); -} \ No newline at end of file +} From 0789bec6aad5c4231c24d664e00da854c5366e9f Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Mon, 11 Oct 2021 13:45:53 +0000 Subject: [PATCH 16/54] Fix thread issue Signed-off-by: Chidera Olibie --- test/common/integration/quic_test_server.cc | 27 +------------------ test/common/integration/quic_test_server.h | 2 +- .../integration/quic_test_server_interface.cc | 2 +- test/common/jni/BUILD | 4 +-- .../jni/quic_test_server_jni_interface.cc | 2 +- .../chromium/net/testing/QuicTestServer.java | 4 ++- 6 files changed, 9 insertions(+), 32 deletions(-) diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc index 0770f2878c..b72a2acc09 100644 --- a/test/common/integration/quic_test_server.cc +++ b/test/common/integration/quic_test_server.cc @@ -68,32 +68,6 @@ Network::TransportSocketFactoryPtr QuicTestServer::createUpstreamTlsContext( 4o8qFQf4jwdxu0iNxYJIMdn+l4/pz2e7GUFHjgMduUclf27Qj1p+8EyYqp6cmkzM 8mcwRkYo3aM70EmUu0Xxi3d5O5F1bIJ5MkgXaX/zSF2N02B3jXroxQ== -----END RSA PRIVATE KEY----- - validation_context: - trusted_ca: - inline_string: | - -----BEGIN CERTIFICATE----- - MIID3TCCAsWgAwIBAgIUdCu/mLip3X/We37vh3BA9u/nxakwDQYJKoZIhvcNAQEL - BQAwdjELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcM - DVNhbiBGcmFuY2lzY28xDTALBgNVBAoMBEx5ZnQxGTAXBgNVBAsMEEx5ZnQgRW5n - aW5lZXJpbmcxEDAOBgNVBAMMB1Rlc3QgQ0EwHhcNMjAwODA1MTkxNjAwWhcNMjIw - ODA1MTkxNjAwWjB2MQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEW - MBQGA1UEBwwNU2FuIEZyYW5jaXNjbzENMAsGA1UECgwETHlmdDEZMBcGA1UECwwQ - THlmdCBFbmdpbmVlcmluZzEQMA4GA1UEAwwHVGVzdCBDQTCCASIwDQYJKoZIhvcN - AQEBBQADggEPADCCAQoCggEBALu2Ihi4DmaQG7zySZlWyM9SjxOXCI5840V7Hn0C - XoiI8sQQmKSC2YCzsaphQoJ0lXCi6Y47o5FkooYyLeNDQTGS0nh+IWm5RCyochtO - fnaKPv/hYxhpyFQEwkJkbF1Zt1s6j2rq5MzmbWZx090uXZEE82DNZ9QJaMPu6VWt - iwGoGoS5HF5HNlUVxLNUsklNH0ZfDafR7/LC2ty1vO1c6EJ6yCGiyJZZ7Ilbz27Q - HPAUd8CcDNKCHZDoMWkLSLN3Nj1MvPVZ5HDsHiNHXthP+zV8FQtloAuZ8Srsmlyg - rJREkc7gF3f6HrH5ShNhsRFFc53NUjDbYZuha1u4hiOE8lcCAwEAAaNjMGEwDwYD - VR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFJZL2ixTtL6V - xpNz4qekny4NchiHMB8GA1UdIwQYMBaAFJZL2ixTtL6VxpNz4qekny4NchiHMA0G - CSqGSIb3DQEBCwUAA4IBAQAcgG+AaCdrUFEVJDn9UsO7zqzQ3c1VOp+WAtAU8OQK - Oc4vJYVVKpDs8OZFxmukCeqm1gz2zDeH7TfgCs5UnLtkplx1YO1bd9qvserJVHiD - LAK+Yl24ZEbrHPaq0zI1RLchqYUOGWmi51pcXi1gsfc8DQ3GqIXoai6kYJeV3jFJ - jxpQSR32nx6oNN/6kVKlgmBjlWrOy7JyDXGim6Z97TzmS6Clctewmw/5gZ9g+M8e - g0ZdFbFkNUjzSNm44hiDX8nR6yJRn+gLaARaJvp1dnT+MlvofZuER17WYKH4OyMs - ie3qKR3an4KC20CtFbpZfv540BVuTTOCtQ5xqZ/LTE78 - -----END CERTIFICATE----- )EOF"); TestUtility::loadFromYaml(yaml, tls_context); envoy::extensions::transport_sockets::quic::v3::QuicDownstreamTransport quic_config; @@ -116,6 +90,7 @@ QuicTestServer::QuicTestServer() void QuicTestServer::startQuicTestServer() { // pre-setup: see https://github.com/envoyproxy/envoy/blob/main/test/test_runner.cc + Thread::TestThread test_thread; ProcessWide process_wide; Thread::MutexBasicLockable lock; Logger::Context logging_state(spdlog::level::level_enum::err, diff --git a/test/common/integration/quic_test_server.h b/test/common/integration/quic_test_server.h index 5a2a7d54e3..21790ac8e0 100644 --- a/test/common/integration/quic_test_server.h +++ b/test/common/integration/quic_test_server.h @@ -37,4 +37,4 @@ class QuicTestServer { int getServerPort(); }; -} // namespace Envoy \ No newline at end of file +} // namespace Envoy diff --git a/test/common/integration/quic_test_server_interface.cc b/test/common/integration/quic_test_server_interface.cc index 09e33e9138..dee22fb44c 100644 --- a/test/common/integration/quic_test_server_interface.cc +++ b/test/common/integration/quic_test_server_interface.cc @@ -31,4 +31,4 @@ int get_server_port() { } // TODO (colibie) write a more suitable error code return 1; // failure -} \ No newline at end of file +} diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index e5f2dd42cc..187ec2a4e7 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -14,14 +14,14 @@ cc_binary( ], copts = ["-std=c++17"], linkopts = [ + "-lm", ], linkshared = True, deps = [ - "//bazel:jni", "//library/common:envoy_main_interface_lib", "//library/common/api:c_types", "//library/common/jni:base_java_jni_lib", - "//library/common/jni:java_jni_support", "//test/common/integration:quic_test_server_interface_lib", + "@envoy_mobile_extra_jni_deps//:extra_jni_dep", ], ) diff --git a/test/common/jni/quic_test_server_jni_interface.cc b/test/common/jni/quic_test_server_jni_interface.cc index 33f155c49c..b3052c1daf 100644 --- a/test/common/jni/quic_test_server_jni_interface.cc +++ b/test/common/jni/quic_test_server_jni_interface.cc @@ -29,4 +29,4 @@ Java_org_chromium_net_testing_QuicTestServer_nativeShutdownQuicTestServer(JNIEnv jclass clazz) { jni_log("[QTS]", "shutting down server"); shutdown_server(); -} \ No newline at end of file +} diff --git a/test/java/org/chromium/net/testing/QuicTestServer.java b/test/java/org/chromium/net/testing/QuicTestServer.java index efe862cb08..5a54a713fd 100644 --- a/test/java/org/chromium/net/testing/QuicTestServer.java +++ b/test/java/org/chromium/net/testing/QuicTestServer.java @@ -68,4 +68,6 @@ private static void onServerStarted() { private static native void nativeStartQuicTestServer(String filePath, String testDataDir); private static native void nativeShutdownQuicTestServer(); private static native int nativeGetServerPort(); -} \ No newline at end of file + + private QuicTestServer() {} +} From 7aca613cdb1205fbbb7c485060adf64bec750810 Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Tue, 12 Oct 2021 16:24:19 +0000 Subject: [PATCH 17/54] add linux jni header and nit changes Signed-off-by: Chidera Olibie --- test/common/integration/quic_test_server.cc | 18 ++-- test/common/integration/quic_test_server.h | 2 +- .../integration/quic_test_server_interface.cc | 3 +- test/common/jni/BUILD | 1 + .../jni/quic_test_server_jni_interface.cc | 17 ++-- .../envoymobile/engine/testing/BUILD | 44 ++++++++++ .../engine}/testing/QuicTestServer.java | 10 ++- .../engine}/testing/QuicTestServerTest.java | 2 +- test/java/org/chromium/net/testing/BUILD | 24 ------ .../chromium/net/testing/CronetTestUtil.java | 84 ------------------- .../net/testing/MockCertVerifier.java | 21 ----- 11 files changed, 75 insertions(+), 151 deletions(-) create mode 100644 test/java/io/envoyproxy/envoymobile/engine/testing/BUILD rename test/java/{org/chromium/net => io/envoyproxy/envoymobile/engine}/testing/QuicTestServer.java (90%) rename test/java/{org/chromium/net => io/envoyproxy/envoymobile/engine}/testing/QuicTestServerTest.java (99%) delete mode 100644 test/java/org/chromium/net/testing/CronetTestUtil.java delete mode 100644 test/java/org/chromium/net/testing/MockCertVerifier.java diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc index b72a2acc09..9cb08f7ae6 100644 --- a/test/common/integration/quic_test_server.cc +++ b/test/common/integration/quic_test_server.cc @@ -5,7 +5,7 @@ namespace Envoy { Network::TransportSocketFactoryPtr QuicTestServer::createUpstreamTlsContext( testing::NiceMock& factory_context) { envoy::extensions::transport_sockets::tls::v3::DownstreamTlsContext tls_context; - Extensions::TransportSockets::Tls::ContextManagerImpl context_manager_{time_system_}; + Extensions::TransportSockets::Tls::ContextManagerImpl context_manager{time_system_}; const std::string yaml = absl::StrFormat( R"EOF( @@ -97,21 +97,21 @@ void QuicTestServer::startQuicTestServer() { "[%Y-%m-%d %T.%e][%t][%l][%n] [%g:%#] %v", lock, false, false); // end pre-setup - FakeUpstreamConfig upstream_config_{time_system_}; - upstream_config_.upstream_protocol_ = Http::CodecType::HTTP3; - upstream_config_.udp_fake_upstream_ = FakeUpstreamConfig::UdpConfig(); + FakeUpstreamConfig upstream_config{time_system_}; + upstream_config.upstream_protocol_ = Http::CodecType::HTTP3; + upstream_config.udp_fake_upstream_ = FakeUpstreamConfig::UdpConfig(); Network::TransportSocketFactoryPtr factory = createUpstreamTlsContext(factory_context_); int port = 34210; - aupstream = std::make_unique(std::move(factory), port, version_, - upstream_config_, false); + aupstream_ = std::make_unique(std::move(factory), port, version_, + upstream_config, false); // see upstream address - std::cerr << "Upstream now listening on " << aupstream->localAddress()->asString() << "\n"; + std::cerr << "Upstream now listening on " << aupstream_->localAddress()->asString() << "\n"; } -void QuicTestServer::shutdownQuicTestServer() { aupstream.reset(); } +void QuicTestServer::shutdownQuicTestServer() { aupstream_.reset(); } -int QuicTestServer::getServerPort() { return aupstream->localAddress()->ip()->port(); } +int QuicTestServer::getServerPort() { return aupstream_->localAddress()->ip()->port(); } } // namespace Envoy diff --git a/test/common/integration/quic_test_server.h b/test/common/integration/quic_test_server.h index 21790ac8e0..cf30175875 100644 --- a/test/common/integration/quic_test_server.h +++ b/test/common/integration/quic_test_server.h @@ -21,7 +21,7 @@ class QuicTestServer { Event::GlobalTimeSystem time_system_; Api::ApiPtr api_; Network::Address::IpVersion version_; - std::unique_ptr aupstream; + std::unique_ptr aupstream_; void setup(); Network::TransportSocketFactoryPtr createUpstreamTlsContext( diff --git a/test/common/integration/quic_test_server_interface.cc b/test/common/integration/quic_test_server_interface.cc index dee22fb44c..e49135f1f9 100644 --- a/test/common/integration/quic_test_server_interface.cc +++ b/test/common/integration/quic_test_server_interface.cc @@ -29,6 +29,5 @@ int get_server_port() { if (auto e = quic_test_server()) { return e->getServerPort(); } - // TODO (colibie) write a more suitable error code - return 1; // failure + return -1; // failure } diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index 187ec2a4e7..8265d0433d 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -11,6 +11,7 @@ cc_binary( srcs = [ "quic_test_server_jni_interface.cc", "@local_jdk//:jni_header", + "@local_jdk//:jni_md_header-linux", ], copts = ["-std=c++17"], linkopts = [ diff --git a/test/common/jni/quic_test_server_jni_interface.cc b/test/common/jni/quic_test_server_jni_interface.cc index b3052c1daf..37c38db4f0 100644 --- a/test/common/jni/quic_test_server_jni_interface.cc +++ b/test/common/jni/quic_test_server_jni_interface.cc @@ -1,5 +1,7 @@ #include +#include + #include "test/common/integration/quic_test_server_interface.h" #include "library/common/jni/jni_support.h" @@ -11,22 +13,25 @@ // Quic Test ServerJniLibrary extern "C" JNIEXPORT void JNICALL -Java_org_chromium_net_testing_QuicTestServer_nativeStartQuicTestServer(JNIEnv* env, jclass clazz, - jstring file_path, - jstring test_data_dir) { +Java_io_envoyproxy_envoymobile_engine_testing_QuicTestServer_nativeStartQuicTestServer( + JNIEnv* env, jclass clazz, jstring file_path, jstring test_data_dir) { jni_log("[QTS]", "starting server"); start_server(); + + // Call java method to open block + env->CallStaticVoidMethod(clazz, env->GetStaticMethodID(clazz, "onServerStarted", "()V")); } extern "C" JNIEXPORT jint JNICALL -Java_org_chromium_net_testing_QuicTestServer_nativeGetServerPort(JNIEnv* env, jclass clazz) { +Java_io_envoyproxy_envoymobile_engine_testing_QuicTestServer_nativeGetServerPort(JNIEnv* env, + jclass clazz) { jni_log("[QTS]", "getting server port"); return get_server_port(); } extern "C" JNIEXPORT void JNICALL -Java_org_chromium_net_testing_QuicTestServer_nativeShutdownQuicTestServer(JNIEnv* env, - jclass clazz) { +Java_io_envoyproxy_envoymobile_engine_testing_QuicTestServer_nativeShutdownQuicTestServer( + JNIEnv* env, jclass clazz) { jni_log("[QTS]", "shutting down server"); shutdown_server(); } diff --git a/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD b/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD new file mode 100644 index 0000000000..eea644e0ca --- /dev/null +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD @@ -0,0 +1,44 @@ +load("@envoy//bazel:envoy_build_system.bzl", "envoy_package") +load("@envoy_mobile//bazel:kotlin_test.bzl", "envoy_mobile_android_test") + +licenses(["notice"]) # Apache 2 + +envoy_package() + +android_library( + name = "testing", + srcs = [ + "QuicTestServer.java", + ], + data = glob(["data/*"]), + visibility = ["//test:__subpackages__"], + deps = [ + "//library/java/io/envoyproxy/envoymobile/engine:envoy_base_engine_lib", + "//library/java/io/envoyproxy/envoymobile/engine:envoy_engine_lib", + "//library/kotlin/io/envoyproxy/envoymobile:envoy_interfaces_lib", + "//library/kotlin/io/envoyproxy/envoymobile:envoy_lib", + "//test/java/org/chromium/net/testing", + "@maven//:junit_junit", + ], +) + +envoy_mobile_android_test( + name = "quic_test_server_test", + srcs = [ + "QuicTestServerTest.java", + ], + library_path = "library/common/jni:test/common/jni", + native_deps = [ + "//library/common/jni:libndk_envoy_jni.so", + "//library/common/jni:libndk_envoy_jni.jnilib", + "//test/common/jni:libquic_test_server_jni.so", + ], + deps = [ + ":testing", + "//library/java/io/envoyproxy/envoymobile/engine:envoy_base_engine_lib", + "//library/java/io/envoyproxy/envoymobile/engine:envoy_engine_lib", + "//library/kotlin/io/envoyproxy/envoymobile:envoy_interfaces_lib", + "//library/kotlin/io/envoyproxy/envoymobile:envoy_lib", + "//test/java/org/chromium/net/testing", + ], +) diff --git a/test/java/org/chromium/net/testing/QuicTestServer.java b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServer.java similarity index 90% rename from test/java/org/chromium/net/testing/QuicTestServer.java rename to test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServer.java index 5a54a713fd..d80d7b5544 100644 --- a/test/java/org/chromium/net/testing/QuicTestServer.java +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServer.java @@ -1,8 +1,10 @@ -package org.chromium.net.testing; +package io.envoyproxy.envoymobile.engine.testing; import android.content.Context; import android.os.ConditionVariable; import android.util.Log; +import org.chromium.net.testing.UrlUtils; +import org.chromium.net.testing.TestFilesInstaller; /** * Wrapper class to start a Quic test server. @@ -28,6 +30,8 @@ public static void startQuicTestServer(Context context) { TestFilesInstaller.installIfNeeded(context); nativeStartQuicTestServer(TestFilesInstaller.getInstalledPath(context), UrlUtils.getIsolatedTestRoot()); + sBlock.block(); + sBlock.close(); sServerRunning = true; } @@ -55,8 +59,8 @@ public static String getServerURL() { public static final String getServerCertKey() { return KEY_USED; } public static long createMockCertVerifier() { - TestFilesInstaller.installIfNeeded(ContextUtils.getApplicationContext()); - return MockCertVerifier.createMockCertVerifier(CERTS_USED, true); + // to be implemented + return 0L; } // @CalledByNative diff --git a/test/java/org/chromium/net/testing/QuicTestServerTest.java b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java similarity index 99% rename from test/java/org/chromium/net/testing/QuicTestServerTest.java rename to test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java index 3ad9e496fc..58507a2be6 100644 --- a/test/java/org/chromium/net/testing/QuicTestServerTest.java +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java @@ -1,4 +1,4 @@ -package org.chromium.net.testing; +package io.envoyproxy.envoymobile.engine.testing; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; diff --git a/test/java/org/chromium/net/testing/BUILD b/test/java/org/chromium/net/testing/BUILD index 4c93d3bd0f..249d0e76c7 100644 --- a/test/java/org/chromium/net/testing/BUILD +++ b/test/java/org/chromium/net/testing/BUILD @@ -13,16 +13,13 @@ android_library( "ConditionVariable.java", "ContextUtils.java", "CronetTestRule.java", - "CronetTestUtil.java", "FailurePhase.java", "Feature.java", "FileUtils.java", "MetricsTestUtil.java", - "MockCertVerifier.java", "MockUrlRequestJobFactory.java", "NativeTestServer.java", "PathUtils.java", - "QuicTestServer.java", "StrictModeContext.java", "TestFilesInstaller.java", "TestUploadDataProvider.java", @@ -64,24 +61,3 @@ envoy_mobile_android_test( "//library/kotlin/io/envoyproxy/envoymobile:envoy_lib", ], ) - -envoy_mobile_android_test( - name = "quic_test_server_test", - srcs = [ - "QuicTestServerTest.java", - ], - library_path = "library/common/jni:test/common/jni", - native_deps = [ - "//library/common/jni:libndk_envoy_jni.so", - "//library/common/jni:libndk_envoy_jni.jnilib", - "//test/common/jni:libquic_test_server_jni.so", - ], - deps = [ - ":testing", - "//library/java/io/envoyproxy/envoymobile/engine:envoy_base_engine_lib", - "//library/java/io/envoyproxy/envoymobile/engine:envoy_engine_lib", - "//library/java/org/chromium/net/impl:cronvoy", - "//library/kotlin/io/envoyproxy/envoymobile:envoy_interfaces_lib", - "//library/kotlin/io/envoyproxy/envoymobile:envoy_lib", - ], -) diff --git a/test/java/org/chromium/net/testing/CronetTestUtil.java b/test/java/org/chromium/net/testing/CronetTestUtil.java deleted file mode 100644 index 13198fa549..0000000000 --- a/test/java/org/chromium/net/testing/CronetTestUtil.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.chromium.net.testing; - -import org.chromium.net.CronetEngine; -import org.chromium.net.ExperimentalCronetEngine; -import org.chromium.net.UrlRequest; -import org.chromium.net.impl.CronetEngineBuilderImpl; -import org.chromium.net.impl.CronetUrlRequestContext; -import org.json.JSONException; -import org.json.JSONObject; - -/** - * Utilities for Cronet testing - */ -public class CronetTestUtil { - // QUIC test domain must match the certificate used - // (quic-chain.pem and quic-leaf-cert.key), and the file served ( - // components/cronet/android/test/assets/test/quic_data/simple.txt). - static final String QUIC_FAKE_HOST = "test.example.com"; - private static final String[] TEST_DOMAINS = {QUIC_FAKE_HOST}; - private static final String LOOPBACK_ADDRESS = "127.0.0.1"; - - /** - * Generates rules for customized DNS mapping for testing hostnames used by test servers, - * namely: - *
    - *
  • {@link QuicTestServer#getServerHost}
  • - *
- * Maps the test hostnames to 127.0.0.1. - */ - public static JSONObject generateHostResolverRules() throws JSONException { - return generateHostResolverRules(LOOPBACK_ADDRESS); - } - - /** - * Generates rules for customized DNS mapping for testing hostnames used by test servers, - * namely: - *
    - *
  • {@link QuicTestServer#getServerHost}
  • - *
- * @param destination host to map to - */ - public static JSONObject generateHostResolverRules(String destination) throws JSONException { - StringBuilder rules = new StringBuilder(); - for (String domain : TEST_DOMAINS) { - rules.append("MAP " + domain + " " + destination + ","); - } - return new JSONObject().put("host_resolver_rules", rules); - } - - /** - * Prepare {@code cronetEngine}'s network thread so libcronet_test code can run on it. - */ - public static class NetworkThreadTestConnector { - private final CronetUrlRequestContext mRequestContext; - - public NetworkThreadTestConnector(CronetEngine cronetEngine) { - mRequestContext = (CronetUrlRequestContext)cronetEngine; - // nativePrepareNetworkThread(mRequestContext.getUrlRequestContextAdapter()); - } - - public void shutdown() { - // TODO(colibie): to be implemented - } - } - - /** - * Returns the value of load flags in |urlRequest|. - * @param urlRequest is the UrlRequest object of interest. - */ - public static int getLoadFlags(UrlRequest urlRequest) { - // To be implemented - return 0; - } - - public static void setMockCertVerifierForTesting(ExperimentalCronetEngine.Builder builder, - long mockCertVerifier) { - getCronetEngineBuilderImpl(builder).setMockCertVerifierForTesting(mockCertVerifier); - } - - public static CronetEngineBuilderImpl - getCronetEngineBuilderImpl(ExperimentalCronetEngine.Builder builder) { - return (CronetEngineBuilderImpl)builder.getBuilderDelegate(); - } -} diff --git a/test/java/org/chromium/net/testing/MockCertVerifier.java b/test/java/org/chromium/net/testing/MockCertVerifier.java deleted file mode 100644 index 3534fdd614..0000000000 --- a/test/java/org/chromium/net/testing/MockCertVerifier.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.chromium.net.testing; - -/** - * A Java wrapper to supply a net::MockCertVerifier which can be then passed - * into {@link CronetEngine.Builder#setMockCertVerifierForTesting}. - * The native pointer will be freed when the CronetEngine is torn down. - */ -public class MockCertVerifier { - private MockCertVerifier() {} - - /** - * Creates a new net::MockCertVerifier, and returns a pointer to it. - * @param certs a String array of certificate filenames in - * net::GetTestCertsDirectory() to accept in testing. - * @return a pointer to the newly created net::MockCertVerifier. - */ - public static long createMockCertVerifier(String[] certs, boolean knownRoot) { - // TODO: to be implemented - return 0L; - } -} From 79819e2a05ef65fef2cdbcfb1d2676b2f0cd7c20 Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Tue, 12 Oct 2021 16:24:19 +0000 Subject: [PATCH 18/54] add linux jni header and nit changes Signed-off-by: Chidera Olibie --- test/common/integration/quic_test_server.cc | 18 ++-- test/common/integration/quic_test_server.h | 2 +- .../integration/quic_test_server_interface.cc | 3 +- test/common/jni/BUILD | 2 + .../jni/quic_test_server_jni_interface.cc | 17 ++-- .../envoymobile/engine/testing/BUILD | 44 ++++++++++ .../engine}/testing/QuicTestServer.java | 10 ++- .../engine}/testing/QuicTestServerTest.java | 2 +- test/java/org/chromium/net/testing/BUILD | 24 ------ .../chromium/net/testing/CronetTestUtil.java | 84 ------------------- .../net/testing/MockCertVerifier.java | 21 ----- 11 files changed, 76 insertions(+), 151 deletions(-) create mode 100644 test/java/io/envoyproxy/envoymobile/engine/testing/BUILD rename test/java/{org/chromium/net => io/envoyproxy/envoymobile/engine}/testing/QuicTestServer.java (90%) rename test/java/{org/chromium/net => io/envoyproxy/envoymobile/engine}/testing/QuicTestServerTest.java (99%) delete mode 100644 test/java/org/chromium/net/testing/CronetTestUtil.java delete mode 100644 test/java/org/chromium/net/testing/MockCertVerifier.java diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc index b72a2acc09..9cb08f7ae6 100644 --- a/test/common/integration/quic_test_server.cc +++ b/test/common/integration/quic_test_server.cc @@ -5,7 +5,7 @@ namespace Envoy { Network::TransportSocketFactoryPtr QuicTestServer::createUpstreamTlsContext( testing::NiceMock& factory_context) { envoy::extensions::transport_sockets::tls::v3::DownstreamTlsContext tls_context; - Extensions::TransportSockets::Tls::ContextManagerImpl context_manager_{time_system_}; + Extensions::TransportSockets::Tls::ContextManagerImpl context_manager{time_system_}; const std::string yaml = absl::StrFormat( R"EOF( @@ -97,21 +97,21 @@ void QuicTestServer::startQuicTestServer() { "[%Y-%m-%d %T.%e][%t][%l][%n] [%g:%#] %v", lock, false, false); // end pre-setup - FakeUpstreamConfig upstream_config_{time_system_}; - upstream_config_.upstream_protocol_ = Http::CodecType::HTTP3; - upstream_config_.udp_fake_upstream_ = FakeUpstreamConfig::UdpConfig(); + FakeUpstreamConfig upstream_config{time_system_}; + upstream_config.upstream_protocol_ = Http::CodecType::HTTP3; + upstream_config.udp_fake_upstream_ = FakeUpstreamConfig::UdpConfig(); Network::TransportSocketFactoryPtr factory = createUpstreamTlsContext(factory_context_); int port = 34210; - aupstream = std::make_unique(std::move(factory), port, version_, - upstream_config_, false); + aupstream_ = std::make_unique(std::move(factory), port, version_, + upstream_config, false); // see upstream address - std::cerr << "Upstream now listening on " << aupstream->localAddress()->asString() << "\n"; + std::cerr << "Upstream now listening on " << aupstream_->localAddress()->asString() << "\n"; } -void QuicTestServer::shutdownQuicTestServer() { aupstream.reset(); } +void QuicTestServer::shutdownQuicTestServer() { aupstream_.reset(); } -int QuicTestServer::getServerPort() { return aupstream->localAddress()->ip()->port(); } +int QuicTestServer::getServerPort() { return aupstream_->localAddress()->ip()->port(); } } // namespace Envoy diff --git a/test/common/integration/quic_test_server.h b/test/common/integration/quic_test_server.h index 21790ac8e0..cf30175875 100644 --- a/test/common/integration/quic_test_server.h +++ b/test/common/integration/quic_test_server.h @@ -21,7 +21,7 @@ class QuicTestServer { Event::GlobalTimeSystem time_system_; Api::ApiPtr api_; Network::Address::IpVersion version_; - std::unique_ptr aupstream; + std::unique_ptr aupstream_; void setup(); Network::TransportSocketFactoryPtr createUpstreamTlsContext( diff --git a/test/common/integration/quic_test_server_interface.cc b/test/common/integration/quic_test_server_interface.cc index dee22fb44c..e49135f1f9 100644 --- a/test/common/integration/quic_test_server_interface.cc +++ b/test/common/integration/quic_test_server_interface.cc @@ -29,6 +29,5 @@ int get_server_port() { if (auto e = quic_test_server()) { return e->getServerPort(); } - // TODO (colibie) write a more suitable error code - return 1; // failure + return -1; // failure } diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index 187ec2a4e7..0ebaab7e1e 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -10,7 +10,9 @@ cc_binary( testonly = True, srcs = [ "quic_test_server_jni_interface.cc", + "@bazel_tools//tools/jdk:current_java_runtime", "@local_jdk//:jni_header", + "@local_jdk//:jni_md_header-linux", ], copts = ["-std=c++17"], linkopts = [ diff --git a/test/common/jni/quic_test_server_jni_interface.cc b/test/common/jni/quic_test_server_jni_interface.cc index b3052c1daf..37c38db4f0 100644 --- a/test/common/jni/quic_test_server_jni_interface.cc +++ b/test/common/jni/quic_test_server_jni_interface.cc @@ -1,5 +1,7 @@ #include +#include + #include "test/common/integration/quic_test_server_interface.h" #include "library/common/jni/jni_support.h" @@ -11,22 +13,25 @@ // Quic Test ServerJniLibrary extern "C" JNIEXPORT void JNICALL -Java_org_chromium_net_testing_QuicTestServer_nativeStartQuicTestServer(JNIEnv* env, jclass clazz, - jstring file_path, - jstring test_data_dir) { +Java_io_envoyproxy_envoymobile_engine_testing_QuicTestServer_nativeStartQuicTestServer( + JNIEnv* env, jclass clazz, jstring file_path, jstring test_data_dir) { jni_log("[QTS]", "starting server"); start_server(); + + // Call java method to open block + env->CallStaticVoidMethod(clazz, env->GetStaticMethodID(clazz, "onServerStarted", "()V")); } extern "C" JNIEXPORT jint JNICALL -Java_org_chromium_net_testing_QuicTestServer_nativeGetServerPort(JNIEnv* env, jclass clazz) { +Java_io_envoyproxy_envoymobile_engine_testing_QuicTestServer_nativeGetServerPort(JNIEnv* env, + jclass clazz) { jni_log("[QTS]", "getting server port"); return get_server_port(); } extern "C" JNIEXPORT void JNICALL -Java_org_chromium_net_testing_QuicTestServer_nativeShutdownQuicTestServer(JNIEnv* env, - jclass clazz) { +Java_io_envoyproxy_envoymobile_engine_testing_QuicTestServer_nativeShutdownQuicTestServer( + JNIEnv* env, jclass clazz) { jni_log("[QTS]", "shutting down server"); shutdown_server(); } diff --git a/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD b/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD new file mode 100644 index 0000000000..eea644e0ca --- /dev/null +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD @@ -0,0 +1,44 @@ +load("@envoy//bazel:envoy_build_system.bzl", "envoy_package") +load("@envoy_mobile//bazel:kotlin_test.bzl", "envoy_mobile_android_test") + +licenses(["notice"]) # Apache 2 + +envoy_package() + +android_library( + name = "testing", + srcs = [ + "QuicTestServer.java", + ], + data = glob(["data/*"]), + visibility = ["//test:__subpackages__"], + deps = [ + "//library/java/io/envoyproxy/envoymobile/engine:envoy_base_engine_lib", + "//library/java/io/envoyproxy/envoymobile/engine:envoy_engine_lib", + "//library/kotlin/io/envoyproxy/envoymobile:envoy_interfaces_lib", + "//library/kotlin/io/envoyproxy/envoymobile:envoy_lib", + "//test/java/org/chromium/net/testing", + "@maven//:junit_junit", + ], +) + +envoy_mobile_android_test( + name = "quic_test_server_test", + srcs = [ + "QuicTestServerTest.java", + ], + library_path = "library/common/jni:test/common/jni", + native_deps = [ + "//library/common/jni:libndk_envoy_jni.so", + "//library/common/jni:libndk_envoy_jni.jnilib", + "//test/common/jni:libquic_test_server_jni.so", + ], + deps = [ + ":testing", + "//library/java/io/envoyproxy/envoymobile/engine:envoy_base_engine_lib", + "//library/java/io/envoyproxy/envoymobile/engine:envoy_engine_lib", + "//library/kotlin/io/envoyproxy/envoymobile:envoy_interfaces_lib", + "//library/kotlin/io/envoyproxy/envoymobile:envoy_lib", + "//test/java/org/chromium/net/testing", + ], +) diff --git a/test/java/org/chromium/net/testing/QuicTestServer.java b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServer.java similarity index 90% rename from test/java/org/chromium/net/testing/QuicTestServer.java rename to test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServer.java index 5a54a713fd..d80d7b5544 100644 --- a/test/java/org/chromium/net/testing/QuicTestServer.java +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServer.java @@ -1,8 +1,10 @@ -package org.chromium.net.testing; +package io.envoyproxy.envoymobile.engine.testing; import android.content.Context; import android.os.ConditionVariable; import android.util.Log; +import org.chromium.net.testing.UrlUtils; +import org.chromium.net.testing.TestFilesInstaller; /** * Wrapper class to start a Quic test server. @@ -28,6 +30,8 @@ public static void startQuicTestServer(Context context) { TestFilesInstaller.installIfNeeded(context); nativeStartQuicTestServer(TestFilesInstaller.getInstalledPath(context), UrlUtils.getIsolatedTestRoot()); + sBlock.block(); + sBlock.close(); sServerRunning = true; } @@ -55,8 +59,8 @@ public static String getServerURL() { public static final String getServerCertKey() { return KEY_USED; } public static long createMockCertVerifier() { - TestFilesInstaller.installIfNeeded(ContextUtils.getApplicationContext()); - return MockCertVerifier.createMockCertVerifier(CERTS_USED, true); + // to be implemented + return 0L; } // @CalledByNative diff --git a/test/java/org/chromium/net/testing/QuicTestServerTest.java b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java similarity index 99% rename from test/java/org/chromium/net/testing/QuicTestServerTest.java rename to test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java index 3ad9e496fc..58507a2be6 100644 --- a/test/java/org/chromium/net/testing/QuicTestServerTest.java +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java @@ -1,4 +1,4 @@ -package org.chromium.net.testing; +package io.envoyproxy.envoymobile.engine.testing; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; diff --git a/test/java/org/chromium/net/testing/BUILD b/test/java/org/chromium/net/testing/BUILD index 4c93d3bd0f..249d0e76c7 100644 --- a/test/java/org/chromium/net/testing/BUILD +++ b/test/java/org/chromium/net/testing/BUILD @@ -13,16 +13,13 @@ android_library( "ConditionVariable.java", "ContextUtils.java", "CronetTestRule.java", - "CronetTestUtil.java", "FailurePhase.java", "Feature.java", "FileUtils.java", "MetricsTestUtil.java", - "MockCertVerifier.java", "MockUrlRequestJobFactory.java", "NativeTestServer.java", "PathUtils.java", - "QuicTestServer.java", "StrictModeContext.java", "TestFilesInstaller.java", "TestUploadDataProvider.java", @@ -64,24 +61,3 @@ envoy_mobile_android_test( "//library/kotlin/io/envoyproxy/envoymobile:envoy_lib", ], ) - -envoy_mobile_android_test( - name = "quic_test_server_test", - srcs = [ - "QuicTestServerTest.java", - ], - library_path = "library/common/jni:test/common/jni", - native_deps = [ - "//library/common/jni:libndk_envoy_jni.so", - "//library/common/jni:libndk_envoy_jni.jnilib", - "//test/common/jni:libquic_test_server_jni.so", - ], - deps = [ - ":testing", - "//library/java/io/envoyproxy/envoymobile/engine:envoy_base_engine_lib", - "//library/java/io/envoyproxy/envoymobile/engine:envoy_engine_lib", - "//library/java/org/chromium/net/impl:cronvoy", - "//library/kotlin/io/envoyproxy/envoymobile:envoy_interfaces_lib", - "//library/kotlin/io/envoyproxy/envoymobile:envoy_lib", - ], -) diff --git a/test/java/org/chromium/net/testing/CronetTestUtil.java b/test/java/org/chromium/net/testing/CronetTestUtil.java deleted file mode 100644 index 13198fa549..0000000000 --- a/test/java/org/chromium/net/testing/CronetTestUtil.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.chromium.net.testing; - -import org.chromium.net.CronetEngine; -import org.chromium.net.ExperimentalCronetEngine; -import org.chromium.net.UrlRequest; -import org.chromium.net.impl.CronetEngineBuilderImpl; -import org.chromium.net.impl.CronetUrlRequestContext; -import org.json.JSONException; -import org.json.JSONObject; - -/** - * Utilities for Cronet testing - */ -public class CronetTestUtil { - // QUIC test domain must match the certificate used - // (quic-chain.pem and quic-leaf-cert.key), and the file served ( - // components/cronet/android/test/assets/test/quic_data/simple.txt). - static final String QUIC_FAKE_HOST = "test.example.com"; - private static final String[] TEST_DOMAINS = {QUIC_FAKE_HOST}; - private static final String LOOPBACK_ADDRESS = "127.0.0.1"; - - /** - * Generates rules for customized DNS mapping for testing hostnames used by test servers, - * namely: - *
    - *
  • {@link QuicTestServer#getServerHost}
  • - *
- * Maps the test hostnames to 127.0.0.1. - */ - public static JSONObject generateHostResolverRules() throws JSONException { - return generateHostResolverRules(LOOPBACK_ADDRESS); - } - - /** - * Generates rules for customized DNS mapping for testing hostnames used by test servers, - * namely: - *
    - *
  • {@link QuicTestServer#getServerHost}
  • - *
- * @param destination host to map to - */ - public static JSONObject generateHostResolverRules(String destination) throws JSONException { - StringBuilder rules = new StringBuilder(); - for (String domain : TEST_DOMAINS) { - rules.append("MAP " + domain + " " + destination + ","); - } - return new JSONObject().put("host_resolver_rules", rules); - } - - /** - * Prepare {@code cronetEngine}'s network thread so libcronet_test code can run on it. - */ - public static class NetworkThreadTestConnector { - private final CronetUrlRequestContext mRequestContext; - - public NetworkThreadTestConnector(CronetEngine cronetEngine) { - mRequestContext = (CronetUrlRequestContext)cronetEngine; - // nativePrepareNetworkThread(mRequestContext.getUrlRequestContextAdapter()); - } - - public void shutdown() { - // TODO(colibie): to be implemented - } - } - - /** - * Returns the value of load flags in |urlRequest|. - * @param urlRequest is the UrlRequest object of interest. - */ - public static int getLoadFlags(UrlRequest urlRequest) { - // To be implemented - return 0; - } - - public static void setMockCertVerifierForTesting(ExperimentalCronetEngine.Builder builder, - long mockCertVerifier) { - getCronetEngineBuilderImpl(builder).setMockCertVerifierForTesting(mockCertVerifier); - } - - public static CronetEngineBuilderImpl - getCronetEngineBuilderImpl(ExperimentalCronetEngine.Builder builder) { - return (CronetEngineBuilderImpl)builder.getBuilderDelegate(); - } -} diff --git a/test/java/org/chromium/net/testing/MockCertVerifier.java b/test/java/org/chromium/net/testing/MockCertVerifier.java deleted file mode 100644 index 3534fdd614..0000000000 --- a/test/java/org/chromium/net/testing/MockCertVerifier.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.chromium.net.testing; - -/** - * A Java wrapper to supply a net::MockCertVerifier which can be then passed - * into {@link CronetEngine.Builder#setMockCertVerifierForTesting}. - * The native pointer will be freed when the CronetEngine is torn down. - */ -public class MockCertVerifier { - private MockCertVerifier() {} - - /** - * Creates a new net::MockCertVerifier, and returns a pointer to it. - * @param certs a String array of certificate filenames in - * net::GetTestCertsDirectory() to accept in testing. - * @return a pointer to the newly created net::MockCertVerifier. - */ - public static long createMockCertVerifier(String[] certs, boolean knownRoot) { - // TODO: to be implemented - return 0L; - } -} From d09958c86daf4c7d7e80c4eff4ac3cb8719b1e3e Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Tue, 12 Oct 2021 17:49:00 +0000 Subject: [PATCH 19/54] fix PR comments and check test asan build Signed-off-by: Chidera Olibie --- test/common/integration/quic_test_server.cc | 18 ++++++++---------- test/common/integration/quic_test_server.h | 5 +++-- .../integration/quic_test_server_interface.cc | 9 +++++---- test/common/jni/BUILD | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc index 9cb08f7ae6..84b1c4d366 100644 --- a/test/common/integration/quic_test_server.cc +++ b/test/common/integration/quic_test_server.cc @@ -83,7 +83,7 @@ Network::TransportSocketFactoryPtr QuicTestServer::createUpstreamTlsContext( QuicTestServer::QuicTestServer() : api_(Api::createApiForTest(stats_store_, time_system_)), - version_(Network::Address::IpVersion::v4) { + version_(Network::Address::IpVersion::v4), port_(34210), upstream_config_(time_system_) { ON_CALL(factory_context_, api()).WillByDefault(testing::ReturnRef(*api_)); ON_CALL(factory_context_, scope()).WillByDefault(testing::ReturnRef(stats_store_)); } @@ -97,21 +97,19 @@ void QuicTestServer::startQuicTestServer() { "[%Y-%m-%d %T.%e][%t][%l][%n] [%g:%#] %v", lock, false, false); // end pre-setup - FakeUpstreamConfig upstream_config{time_system_}; - upstream_config.upstream_protocol_ = Http::CodecType::HTTP3; - upstream_config.udp_fake_upstream_ = FakeUpstreamConfig::UdpConfig(); + upstream_config_.upstream_protocol_ = Http::CodecType::HTTP3; + upstream_config_.udp_fake_upstream_ = FakeUpstreamConfig::UdpConfig(); Network::TransportSocketFactoryPtr factory = createUpstreamTlsContext(factory_context_); - int port = 34210; - aupstream_ = std::make_unique(std::move(factory), port, version_, - upstream_config, false); + upstream_ = std::make_unique(std::move(factory), port_, version_, + upstream_config_, false); // see upstream address - std::cerr << "Upstream now listening on " << aupstream_->localAddress()->asString() << "\n"; + ENVOY_LOG_MISC(debug, "Upstream now listening on {}", upstream_->localAddress()->asString()); } -void QuicTestServer::shutdownQuicTestServer() { aupstream_.reset(); } +void QuicTestServer::shutdownQuicTestServer() { upstream_.reset(); } -int QuicTestServer::getServerPort() { return aupstream_->localAddress()->ip()->port(); } +int QuicTestServer::getServerPort() { return upstream_->localAddress()->ip()->port(); } } // namespace Envoy diff --git a/test/common/integration/quic_test_server.h b/test/common/integration/quic_test_server.h index cf30175875..cf84ebf42c 100644 --- a/test/common/integration/quic_test_server.h +++ b/test/common/integration/quic_test_server.h @@ -21,9 +21,10 @@ class QuicTestServer { Event::GlobalTimeSystem time_system_; Api::ApiPtr api_; Network::Address::IpVersion version_; - std::unique_ptr aupstream_; + std::unique_ptr upstream_; + FakeUpstreamConfig upstream_config_; + int port_; - void setup(); Network::TransportSocketFactoryPtr createUpstreamTlsContext( testing::NiceMock&); diff --git a/test/common/integration/quic_test_server_interface.cc b/test/common/integration/quic_test_server_interface.cc index e49135f1f9..4fd695f337 100644 --- a/test/common/integration/quic_test_server_interface.cc +++ b/test/common/integration/quic_test_server_interface.cc @@ -3,16 +3,15 @@ // NOLINT(namespace-envoy) static std::shared_ptr strong_quic_test_server_; -static std::weak_ptr quic_test_server_; +static std::weak_ptr weak_quic_test_server_; static std::shared_ptr quic_test_server() { - return quic_test_server_.lock(); + return weak_quic_test_server_.lock(); } void start_server() { - // start server strong_quic_test_server_ = std::make_shared(); - quic_test_server_ = strong_quic_test_server_; + weak_quic_test_server_ = strong_quic_test_server_; if (auto e = quic_test_server()) { e->startQuicTestServer(); @@ -20,6 +19,8 @@ void start_server() { } void shutdown_server() { + // Reset the primary handle to the test_server, + // but retain it long enough to synchronously shutdown. auto e = strong_quic_test_server_; strong_quic_test_server_.reset(); e->shutdownQuicTestServer(); diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index 0ebaab7e1e..d242f10a19 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -11,8 +11,8 @@ cc_binary( srcs = [ "quic_test_server_jni_interface.cc", "@bazel_tools//tools/jdk:current_java_runtime", - "@local_jdk//:jni_header", - "@local_jdk//:jni_md_header-linux", + # "@local_jdk//:jni_header", + # "@local_jdk//:jni_md_header-linux", ], copts = ["-std=c++17"], linkopts = [ From 4123d5640096b10a020803f4933ad1c5e087e806 Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Tue, 12 Oct 2021 17:56:56 +0000 Subject: [PATCH 20/54] ci test Signed-off-by: Chidera Olibie --- test/common/jni/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index d242f10a19..2980436c2c 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -10,7 +10,7 @@ cc_binary( testonly = True, srcs = [ "quic_test_server_jni_interface.cc", - "@bazel_tools//tools/jdk:current_java_runtime", + "@bazel_tools//tools/jdk:remote_jdk11", # "@local_jdk//:jni_header", # "@local_jdk//:jni_md_header-linux", ], From cb3e22b9ff7faad3aef5f1a72f07f388119abc4b Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Tue, 12 Oct 2021 18:38:30 +0000 Subject: [PATCH 21/54] ci testing Signed-off-by: Chidera Olibie --- library/common/jni/BUILD | 9 ++++++--- test/common/integration/quic_test_server.cc | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/library/common/jni/BUILD b/library/common/jni/BUILD index 84697d8f63..37dd14b0ae 100644 --- a/library/common/jni/BUILD +++ b/library/common/jni/BUILD @@ -80,7 +80,8 @@ cc_binary( srcs = [ "android_test_jni_interface.cc", "jni_interface.cc", - "@local_jdk//:jni_header", + "@bazel_tools//tools/jdk:remote_jdk11", +# "@local_jdk//:jni_header", ], copts = ["-std=c++17"], linkopts = [ @@ -121,7 +122,8 @@ cc_library( srcs = [ "jni_utility.cc", "jni_version.cc", - "@local_jdk//:jni_header", + "@bazel_tools//tools/jdk:remote_jdk11", +# "@local_jdk//:jni_header", ], hdrs = [ "jni_utility.h", @@ -145,7 +147,8 @@ cc_library( name = "java_jni_support", srcs = [ "java_jni_support.cc", - "@local_jdk//:jni_header", + "@bazel_tools//tools/jdk:remote_jdk11", +# "@local_jdk//:jni_header", ], hdrs = ["jni_support.h"], copts = ["-std=c++14"], diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc index 84b1c4d366..dfdeca1272 100644 --- a/test/common/integration/quic_test_server.cc +++ b/test/common/integration/quic_test_server.cc @@ -83,7 +83,9 @@ Network::TransportSocketFactoryPtr QuicTestServer::createUpstreamTlsContext( QuicTestServer::QuicTestServer() : api_(Api::createApiForTest(stats_store_, time_system_)), - version_(Network::Address::IpVersion::v4), port_(34210), upstream_config_(time_system_) { + version_(Network::Address::IpVersion::v4), + upstream_config_(time_system_), + port_(34210) { ON_CALL(factory_context_, api()).WillByDefault(testing::ReturnRef(*api_)); ON_CALL(factory_context_, scope()).WillByDefault(testing::ReturnRef(stats_store_)); } From 9836d3864227e639c6da05e70be181cad8e483f7 Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Tue, 12 Oct 2021 18:50:08 +0000 Subject: [PATCH 22/54] reverting cc_binary changes Signed-off-by: Chidera Olibie --- library/common/jni/BUILD | 9 +++------ test/common/jni/BUILD | 4 +--- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/library/common/jni/BUILD b/library/common/jni/BUILD index 37dd14b0ae..84697d8f63 100644 --- a/library/common/jni/BUILD +++ b/library/common/jni/BUILD @@ -80,8 +80,7 @@ cc_binary( srcs = [ "android_test_jni_interface.cc", "jni_interface.cc", - "@bazel_tools//tools/jdk:remote_jdk11", -# "@local_jdk//:jni_header", + "@local_jdk//:jni_header", ], copts = ["-std=c++17"], linkopts = [ @@ -122,8 +121,7 @@ cc_library( srcs = [ "jni_utility.cc", "jni_version.cc", - "@bazel_tools//tools/jdk:remote_jdk11", -# "@local_jdk//:jni_header", + "@local_jdk//:jni_header", ], hdrs = [ "jni_utility.h", @@ -147,8 +145,7 @@ cc_library( name = "java_jni_support", srcs = [ "java_jni_support.cc", - "@bazel_tools//tools/jdk:remote_jdk11", -# "@local_jdk//:jni_header", + "@local_jdk//:jni_header", ], hdrs = ["jni_support.h"], copts = ["-std=c++14"], diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index 2980436c2c..187ec2a4e7 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -10,9 +10,7 @@ cc_binary( testonly = True, srcs = [ "quic_test_server_jni_interface.cc", - "@bazel_tools//tools/jdk:remote_jdk11", - # "@local_jdk//:jni_header", - # "@local_jdk//:jni_md_header-linux", + "@local_jdk//:jni_header", ], copts = ["-std=c++17"], linkopts = [ From 03c20539e4bf1a3ca6e5d2beb177ba041f0d6e43 Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Fri, 15 Oct 2021 10:42:31 +0000 Subject: [PATCH 23/54] pull in updates Signed-off-by: Chidera Olibie --- envoy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/envoy b/envoy index a5b3af2670..5423325ccf 160000 --- a/envoy +++ b/envoy @@ -1 +1 @@ -Subproject commit a5b3af2670b7848c628c23e26a8ec6ea26e24d17 +Subproject commit 5423325ccf04c7f50069cb8662e51208526bd4a9 From 274aae75993f18bf4538a594dd9309065d9aee2b Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Fri, 15 Oct 2021 11:45:20 +0000 Subject: [PATCH 24/54] fix format issues Signed-off-by: Chidera Olibie --- envoy | 2 +- test/common/integration/quic_test_server.cc | 4 +--- test/common/jni/BUILD | 4 +--- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/envoy b/envoy index 5423325ccf..a5b3af2670 160000 --- a/envoy +++ b/envoy @@ -1 +1 @@ -Subproject commit 5423325ccf04c7f50069cb8662e51208526bd4a9 +Subproject commit a5b3af2670b7848c628c23e26a8ec6ea26e24d17 diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc index dfdeca1272..26d20f0e6c 100644 --- a/test/common/integration/quic_test_server.cc +++ b/test/common/integration/quic_test_server.cc @@ -83,9 +83,7 @@ Network::TransportSocketFactoryPtr QuicTestServer::createUpstreamTlsContext( QuicTestServer::QuicTestServer() : api_(Api::createApiForTest(stats_store_, time_system_)), - version_(Network::Address::IpVersion::v4), - upstream_config_(time_system_), - port_(34210) { + version_(Network::Address::IpVersion::v4), upstream_config_(time_system_), port_(34210) { ON_CALL(factory_context_, api()).WillByDefault(testing::ReturnRef(*api_)); ON_CALL(factory_context_, scope()).WillByDefault(testing::ReturnRef(stats_store_)); } diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index 187ec2a4e7..20c085658c 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -13,9 +13,7 @@ cc_binary( "@local_jdk//:jni_header", ], copts = ["-std=c++17"], - linkopts = [ - "-lm", - ], + linkopts = ["-lm"], linkshared = True, deps = [ "//library/common:envoy_main_interface_lib", From 4bc0fd90c9f7eccff139882ace6b9e9dc89d6f49 Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Fri, 15 Oct 2021 12:23:34 +0000 Subject: [PATCH 25/54] potential fix for mac timeouts Signed-off-by: Chidera Olibie --- test/common/jni/BUILD | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index 20c085658c..af81e437bf 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -1,10 +1,17 @@ +load("//bazel:kotlin_lib.bzl", "envoy_mobile_so_to_jni_lib") load("@envoy//bazel:envoy_build_system.bzl", "envoy_package") licenses(["notice"]) # Apache 2 envoy_package() -# dynamic library for the Envoy Mobile aar +# OS X binary (.jnilib) for Quic Test Server +envoy_mobile_so_to_jni_lib( + name = "quic_test_server_jni.jnilib", + native_dep = "libquic_test_server_jni.so", +) + +# Binary for Quic Test Server cc_binary( name = "libquic_test_server_jni.so", testonly = True, From f6e5b72ad8638a63adb19e737cdb3478a0f9af92 Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Fri, 15 Oct 2021 13:08:30 +0000 Subject: [PATCH 26/54] should fix failures Signed-off-by: Chidera Olibie --- bazel/kotlin_lib.bzl | 2 +- test/common/jni/BUILD | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/bazel/kotlin_lib.bzl b/bazel/kotlin_lib.bzl index 2a3de87274..38e97685d5 100644 --- a/bazel/kotlin_lib.bzl +++ b/bazel/kotlin_lib.bzl @@ -46,7 +46,7 @@ def envoy_mobile_kt_library(name, visibility = None, srcs = [], deps = []): # name = "java_jni_lib.jnilib", # native_dep = "libjava_jni_lib.so", # ) -def envoy_mobile_so_to_jni_lib(name, native_dep): +def envoy_mobile_so_to_jni_lib(name, native_dep, testonly = False): lib_name = native_lib_name(native_dep) output = "{}.jnilib".format(lib_name) diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index af81e437bf..17f98826d1 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -8,6 +8,7 @@ envoy_package() # OS X binary (.jnilib) for Quic Test Server envoy_mobile_so_to_jni_lib( name = "quic_test_server_jni.jnilib", + testonly = True, native_dep = "libquic_test_server_jni.so", ) From 34c70bedc5846949e27bf9a6d46befa6a8f0cd87 Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Fri, 15 Oct 2021 13:22:32 +0000 Subject: [PATCH 27/54] testonly field added to genrule Signed-off-by: Chidera Olibie --- bazel/kotlin_lib.bzl | 1 + 1 file changed, 1 insertion(+) diff --git a/bazel/kotlin_lib.bzl b/bazel/kotlin_lib.bzl index 38e97685d5..e21a360b37 100644 --- a/bazel/kotlin_lib.bzl +++ b/bazel/kotlin_lib.bzl @@ -52,6 +52,7 @@ def envoy_mobile_so_to_jni_lib(name, native_dep, testonly = False): return native.genrule( name = name, + testonly = testonly, outs = [output], srcs = [native_dep], cmd = """ From 5b6dd439a7db435d5ebe7bb5847956a8b41ecd63 Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Fri, 15 Oct 2021 15:29:25 +0000 Subject: [PATCH 28/54] add binary jnilib to dep Signed-off-by: Chidera Olibie --- library/java/org/chromium/net/impl/CronetUrlRequest.java | 3 +-- test/common/jni/BUILD | 2 +- test/java/io/envoyproxy/envoymobile/engine/testing/BUILD | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/java/org/chromium/net/impl/CronetUrlRequest.java b/library/java/org/chromium/net/impl/CronetUrlRequest.java index 1fd5f0d9cf..7e063760fd 100644 --- a/library/java/org/chromium/net/impl/CronetUrlRequest.java +++ b/library/java/org/chromium/net/impl/CronetUrlRequest.java @@ -563,8 +563,7 @@ public void onCancel(EnvoyStreamIntel streamIntel) { headers.computeIfAbsent(":authority", unused -> new ArrayList<>()).add(url.getAuthority()); headers.computeIfAbsent(":method", unused -> new ArrayList<>()).add(initialMethod); - headers.computeIfAbsent(":path", unused -> new ArrayList<>()) - .add(url.getFile().isEmpty() ? "/" : url.getFile()); + headers.computeIfAbsent(":path", unused -> new ArrayList<>()).add(url.getFile()); headers.computeIfAbsent(":scheme", unused -> new ArrayList<>()).add(url.getProtocol()); boolean hasUserAgent = false; diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index 17f98826d1..78a80052fd 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -7,7 +7,7 @@ envoy_package() # OS X binary (.jnilib) for Quic Test Server envoy_mobile_so_to_jni_lib( - name = "quic_test_server_jni.jnilib", + name = "libquic_test_server_jni.jnilib", testonly = True, native_dep = "libquic_test_server_jni.so", ) diff --git a/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD b/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD index eea644e0ca..12f8f3943b 100644 --- a/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD @@ -32,6 +32,7 @@ envoy_mobile_android_test( "//library/common/jni:libndk_envoy_jni.so", "//library/common/jni:libndk_envoy_jni.jnilib", "//test/common/jni:libquic_test_server_jni.so", + "//test/common/jni:libquic_test_server_jni.jnilib", ], deps = [ ":testing", From 02fd58f047275c135fe1acc7d30d9a19ca5eca15 Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Fri, 15 Oct 2021 15:56:52 +0000 Subject: [PATCH 29/54] Kick CI Signed-off-by: Chidera Olibie From 701395b5d89fa0cfb60b1b948807dc64bf7e7250 Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Fri, 15 Oct 2021 16:46:52 +0000 Subject: [PATCH 30/54] remove redundancies Signed-off-by: Chidera Olibie --- test/common/integration/BUILD | 3 +-- test/common/jni/BUILD | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/test/common/integration/BUILD b/test/common/integration/BUILD index 980de26aab..b090969d83 100644 --- a/test/common/integration/BUILD +++ b/test/common/integration/BUILD @@ -20,7 +20,7 @@ envoy_cc_test( ], ) -# interface libs for jni implementation +# interface libs for quic test server's jni implementation envoy_cc_test_library( name = "quic_test_server_interface_lib", repository = "@envoy", @@ -48,7 +48,6 @@ envoy_cc_test_library( "@envoy//source/common/stats:isolated_store_lib", "@envoy//test:test_pch", "@envoy//source/exe:process_wide_lib", - "@envoy//source/common/common:logger_lib", "@envoy//test/integration:autonomous_upstream_lib", "@envoy//test/test_common:network_utility_lib", "@envoy_api//envoy/extensions/filters/common/matcher/action/v3:pkg_cc_proto", diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index 78a80052fd..843f051aaa 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -28,6 +28,5 @@ cc_binary( "//library/common/api:c_types", "//library/common/jni:base_java_jni_lib", "//test/common/integration:quic_test_server_interface_lib", - "@envoy_mobile_extra_jni_deps//:extra_jni_dep", ], ) From f1a9a7534f56e8612faddbd3976d72df391d3403 Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Mon, 18 Oct 2021 19:39:10 +0000 Subject: [PATCH 31/54] some more cleanup Signed-off-by: Chidera Olibie --- test/common/integration/BUILD | 10 ---------- test/common/integration/quic_test_server.h | 4 ---- test/common/jni/BUILD | 2 -- .../io/envoyproxy/envoymobile/engine/testing/BUILD | 8 -------- 4 files changed, 24 deletions(-) diff --git a/test/common/integration/BUILD b/test/common/integration/BUILD index b090969d83..13c522b3f5 100644 --- a/test/common/integration/BUILD +++ b/test/common/integration/BUILD @@ -37,21 +37,11 @@ envoy_cc_test_library( "quic_test_server_interface.cc", ], hdrs = ["quic_test_server_interface.h"], - data = [ - "@envoy//test/config/integration/certs", - ], repository = "@envoy", deps = [ - "@envoy//source/common/quic:active_quic_listener_lib", - "@envoy//source/common/quic:quic_factory_lib", - "@envoy//source/common/quic:quic_stat_names_lib", - "@envoy//source/common/stats:isolated_store_lib", "@envoy//test:test_pch", "@envoy//source/exe:process_wide_lib", "@envoy//test/integration:autonomous_upstream_lib", - "@envoy//test/test_common:network_utility_lib", - "@envoy_api//envoy/extensions/filters/common/matcher/action/v3:pkg_cc_proto", - "@envoy_api//envoy/extensions/transport_sockets/quic/v3:pkg_cc_proto", ] + select({ "@envoy//bazel:disable_signal_trace": [], "//conditions:default": [ diff --git a/test/common/integration/quic_test_server.h b/test/common/integration/quic_test_server.h index cf84ebf42c..85a7ac634d 100644 --- a/test/common/integration/quic_test_server.h +++ b/test/common/integration/quic_test_server.h @@ -1,17 +1,13 @@ #pragma once -#include "source/common/stats/isolated_store_impl.h" #include "source/extensions/transport_sockets/tls/ssl_socket.h" // test_runner setups -#include "source/common/common/logger.h" #include "source/exe/process_wide.h" -#include "absl/strings/str_format.h" #include "envoy/extensions/transport_sockets/quic/v3/quic_transport.pb.h" #include "test/mocks/server/transport_socket_factory_context.h" #include "test/integration/autonomous_upstream.h" -#include "test/test_common/network_utility.h" namespace Envoy { class QuicTestServer { diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index 843f051aaa..2ca17c0cfc 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -24,8 +24,6 @@ cc_binary( linkopts = ["-lm"], linkshared = True, deps = [ - "//library/common:envoy_main_interface_lib", - "//library/common/api:c_types", "//library/common/jni:base_java_jni_lib", "//test/common/integration:quic_test_server_interface_lib", ], diff --git a/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD b/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD index 12f8f3943b..65fdd30c06 100644 --- a/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD @@ -13,12 +13,7 @@ android_library( data = glob(["data/*"]), visibility = ["//test:__subpackages__"], deps = [ - "//library/java/io/envoyproxy/envoymobile/engine:envoy_base_engine_lib", - "//library/java/io/envoyproxy/envoymobile/engine:envoy_engine_lib", - "//library/kotlin/io/envoyproxy/envoymobile:envoy_interfaces_lib", - "//library/kotlin/io/envoyproxy/envoymobile:envoy_lib", "//test/java/org/chromium/net/testing", - "@maven//:junit_junit", ], ) @@ -36,9 +31,6 @@ envoy_mobile_android_test( ], deps = [ ":testing", - "//library/java/io/envoyproxy/envoymobile/engine:envoy_base_engine_lib", - "//library/java/io/envoyproxy/envoymobile/engine:envoy_engine_lib", - "//library/kotlin/io/envoyproxy/envoymobile:envoy_interfaces_lib", "//library/kotlin/io/envoyproxy/envoymobile:envoy_lib", "//test/java/org/chromium/net/testing", ], From 1fae837775fd4ee7397d1e6ca5301d80b4e9b2a1 Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Tue, 19 Oct 2021 17:09:11 +0000 Subject: [PATCH 32/54] Kick CI Signed-off-by: Chidera Olibie From 71748ef2634f79173a948bd5aa827c6421d871b8 Mon Sep 17 00:00:00 2001 From: Chidera Olibie Date: Mon, 25 Oct 2021 11:37:15 +0000 Subject: [PATCH 33/54] [WIP] mac not working yet Signed-off-by: Chidera Olibie --- test/common/integration/BUILD | 8 +++++--- test/common/integration/quic_test_server.cc | 3 --- test/common/integration/quic_test_server.h | 4 ++++ test/common/jni/BUILD | 4 ++++ test/common/jni/quic_test_server_jni_interface.cc | 3 --- test/java/io/envoyproxy/envoymobile/engine/testing/BUILD | 8 +++++--- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/test/common/integration/BUILD b/test/common/integration/BUILD index 13c522b3f5..04dab0a117 100644 --- a/test/common/integration/BUILD +++ b/test/common/integration/BUILD @@ -33,13 +33,15 @@ envoy_cc_test_library( name = "quic_test_server_interface_lib_no_stamp", srcs = [ "quic_test_server.cc", - "quic_test_server.h", "quic_test_server_interface.cc", ], - hdrs = ["quic_test_server_interface.h"], + hdrs = [ + "quic_test_server.h", + "quic_test_server_interface.h", + ], repository = "@envoy", deps = [ - "@envoy//test:test_pch", + "@envoy//test/mocks/server:transport_socket_factory_context_mocks", "@envoy//source/exe:process_wide_lib", "@envoy//test/integration:autonomous_upstream_lib", ] + select({ diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc index 26d20f0e6c..a6386e0eae 100644 --- a/test/common/integration/quic_test_server.cc +++ b/test/common/integration/quic_test_server.cc @@ -90,9 +90,6 @@ QuicTestServer::QuicTestServer() void QuicTestServer::startQuicTestServer() { // pre-setup: see https://github.com/envoyproxy/envoy/blob/main/test/test_runner.cc - Thread::TestThread test_thread; - ProcessWide process_wide; - Thread::MutexBasicLockable lock; Logger::Context logging_state(spdlog::level::level_enum::err, "[%Y-%m-%d %T.%e][%t][%l][%n] [%g:%#] %v", lock, false, false); // end pre-setup diff --git a/test/common/integration/quic_test_server.h b/test/common/integration/quic_test_server.h index 85a7ac634d..cea8a3e1fd 100644 --- a/test/common/integration/quic_test_server.h +++ b/test/common/integration/quic_test_server.h @@ -8,6 +8,7 @@ #include "envoy/extensions/transport_sockets/quic/v3/quic_transport.pb.h" #include "test/mocks/server/transport_socket_factory_context.h" #include "test/integration/autonomous_upstream.h" +#include "test/config/utility.h" namespace Envoy { class QuicTestServer { @@ -20,6 +21,9 @@ class QuicTestServer { std::unique_ptr upstream_; FakeUpstreamConfig upstream_config_; int port_; + Thread::TestThread test_thread_; + ProcessWide process_wide; + Thread::MutexBasicLockable lock; Network::TransportSocketFactoryPtr createUpstreamTlsContext( testing::NiceMock&); diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index 2ca17c0cfc..57588a9c12 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -18,6 +18,10 @@ cc_binary( testonly = True, srcs = [ "quic_test_server_jni_interface.cc", + # Currently works only on Linux system but not on mac(issue: double registration of factories). + # Uncomment srcs below to trigger tls_ thread error for both linux and mac. + # "//library/common/jni:android_test_jni_interface.cc", + # "//library/common/jni:jni_interface.cc", "@local_jdk//:jni_header", ], copts = ["-std=c++17"], diff --git a/test/common/jni/quic_test_server_jni_interface.cc b/test/common/jni/quic_test_server_jni_interface.cc index 37c38db4f0..c2f44636e2 100644 --- a/test/common/jni/quic_test_server_jni_interface.cc +++ b/test/common/jni/quic_test_server_jni_interface.cc @@ -1,7 +1,4 @@ #include - -#include - #include "test/common/integration/quic_test_server_interface.h" #include "library/common/jni/jni_support.h" diff --git a/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD b/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD index 65fdd30c06..0c464c7e90 100644 --- a/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD @@ -7,10 +7,14 @@ envoy_package() android_library( name = "testing", + testonly = True, srcs = [ "QuicTestServer.java", ], - data = glob(["data/*"]), + data = glob(["data/*"]) + [ + "//test/common/jni:libquic_test_server_jni.jnilib", + "//test/common/jni:libquic_test_server_jni.so", + ], visibility = ["//test:__subpackages__"], deps = [ "//test/java/org/chromium/net/testing", @@ -26,8 +30,6 @@ envoy_mobile_android_test( native_deps = [ "//library/common/jni:libndk_envoy_jni.so", "//library/common/jni:libndk_envoy_jni.jnilib", - "//test/common/jni:libquic_test_server_jni.so", - "//test/common/jni:libquic_test_server_jni.jnilib", ], deps = [ ":testing", From ea28dc4d24a7c74a83f689a7e9010921f4cd021e Mon Sep 17 00:00:00 2001 From: Charles Le Borgne Date: Mon, 27 Dec 2021 21:03:05 +0000 Subject: [PATCH 34/54] Adjust dependencies Signed-off-by: Charles Le Borgne --- test/common/integration/BUILD | 4 +++- test/common/integration/quic_test_server.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/common/integration/BUILD b/test/common/integration/BUILD index 04dab0a117..3559e80d0b 100644 --- a/test/common/integration/BUILD +++ b/test/common/integration/BUILD @@ -41,9 +41,11 @@ envoy_cc_test_library( ], repository = "@envoy", deps = [ - "@envoy//test/mocks/server:transport_socket_factory_context_mocks", "@envoy//source/exe:process_wide_lib", + "@envoy//test/config:utility_lib", "@envoy//test/integration:autonomous_upstream_lib", + "@envoy//test/mocks/server:transport_socket_factory_context_mocks", + "@envoy//test/test_common:environment_lib", ] + select({ "@envoy//bazel:disable_signal_trace": [], "//conditions:default": [ diff --git a/test/common/integration/quic_test_server.h b/test/common/integration/quic_test_server.h index cea8a3e1fd..f2af589c66 100644 --- a/test/common/integration/quic_test_server.h +++ b/test/common/integration/quic_test_server.h @@ -21,7 +21,7 @@ class QuicTestServer { std::unique_ptr upstream_; FakeUpstreamConfig upstream_config_; int port_; - Thread::TestThread test_thread_; + // Thread::TestThread test_thread_; ProcessWide process_wide; Thread::MutexBasicLockable lock; From ba0d57c6cbb1fdc8fcbdbb7ecbe29e3f0c7bb820 Mon Sep 17 00:00:00 2001 From: Charles Le Borgne Date: Sat, 1 Jan 2022 21:35:50 +0000 Subject: [PATCH 35/54] Fix for Thread issue. Signed-off-by: Charles Le Borgne --- bazel/kotlin_test.bzl | 1 + test/common/integration/quic_test_server.h | 2 +- test/common/jni/BUILD | 8 +-- .../envoymobile/engine/testing/BUILD | 10 +--- .../engine/testing/QuicTestServer.java | 6 +- .../engine/testing/QuicTestServerTest.java | 55 +++++++++---------- 6 files changed, 33 insertions(+), 49 deletions(-) diff --git a/bazel/kotlin_test.bzl b/bazel/kotlin_test.bzl index edfb79c3cd..3a2f909649 100644 --- a/bazel/kotlin_test.bzl +++ b/bazel/kotlin_test.bzl @@ -74,6 +74,7 @@ def envoy_mobile_android_test(name, srcs, deps = [], native_deps = [], repositor visibility = ["//visibility:public"], data = native_deps, exports = deps, + testonly = True, ) native.android_local_test( diff --git a/test/common/integration/quic_test_server.h b/test/common/integration/quic_test_server.h index f2af589c66..6d8f9374db 100644 --- a/test/common/integration/quic_test_server.h +++ b/test/common/integration/quic_test_server.h @@ -21,7 +21,7 @@ class QuicTestServer { std::unique_ptr upstream_; FakeUpstreamConfig upstream_config_; int port_; - // Thread::TestThread test_thread_; + Thread::SkipAsserts skip_asserts_; ProcessWide process_wide; Thread::MutexBasicLockable lock; diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index 57588a9c12..31d1af0abe 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -18,14 +18,12 @@ cc_binary( testonly = True, srcs = [ "quic_test_server_jni_interface.cc", - # Currently works only on Linux system but not on mac(issue: double registration of factories). - # Uncomment srcs below to trigger tls_ thread error for both linux and mac. - # "//library/common/jni:android_test_jni_interface.cc", - # "//library/common/jni:jni_interface.cc", + "//library/common/jni:android_test_jni_interface.cc", + "//library/common/jni:jni_interface.cc", "@local_jdk//:jni_header", ], copts = ["-std=c++17"], - linkopts = ["-lm"], + linkopts = [], linkshared = True, deps = [ "//library/common/jni:base_java_jni_lib", diff --git a/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD b/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD index 0c464c7e90..2274d70405 100644 --- a/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD @@ -11,13 +11,8 @@ android_library( srcs = [ "QuicTestServer.java", ], - data = glob(["data/*"]) + [ - "//test/common/jni:libquic_test_server_jni.jnilib", - "//test/common/jni:libquic_test_server_jni.so", - ], visibility = ["//test:__subpackages__"], deps = [ - "//test/java/org/chromium/net/testing", ], ) @@ -28,12 +23,11 @@ envoy_mobile_android_test( ], library_path = "library/common/jni:test/common/jni", native_deps = [ - "//library/common/jni:libndk_envoy_jni.so", - "//library/common/jni:libndk_envoy_jni.jnilib", + "//test/common/jni:libquic_test_server_jni.so", + "//test/common/jni:libquic_test_server_jni.jnilib", ], deps = [ ":testing", "//library/kotlin/io/envoyproxy/envoymobile:envoy_lib", - "//test/java/org/chromium/net/testing", ], ) diff --git a/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServer.java b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServer.java index d80d7b5544..970790b5b3 100644 --- a/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServer.java +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServer.java @@ -3,8 +3,6 @@ import android.content.Context; import android.os.ConditionVariable; import android.util.Log; -import org.chromium.net.testing.UrlUtils; -import org.chromium.net.testing.TestFilesInstaller; /** * Wrapper class to start a Quic test server. @@ -27,9 +25,7 @@ public static void startQuicTestServer(Context context) { if (sServerRunning) { throw new IllegalStateException("Quic server is already running"); } - TestFilesInstaller.installIfNeeded(context); - nativeStartQuicTestServer(TestFilesInstaller.getInstalledPath(context), - UrlUtils.getIsolatedTestRoot()); + nativeStartQuicTestServer("path", "file"); sBlock.block(); sBlock.close(); sServerRunning = true; diff --git a/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java index 58507a2be6..ece6a89e03 100644 --- a/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java @@ -1,22 +1,22 @@ package io.envoyproxy.envoymobile.engine.testing; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; -import static org.chromium.net.testing.CronetTestRule.getContext; -import io.envoyproxy.envoymobile.LogLevel; +import android.content.Context; +import androidx.test.core.app.ApplicationProvider; import io.envoyproxy.envoymobile.AndroidEngineBuilder; import io.envoyproxy.envoymobile.Custom; import io.envoyproxy.envoymobile.Engine; import io.envoyproxy.envoymobile.EnvoyError; +import io.envoyproxy.envoymobile.LogLevel; import io.envoyproxy.envoymobile.RequestHeaders; import io.envoyproxy.envoymobile.RequestHeadersBuilder; import io.envoyproxy.envoymobile.RequestMethod; import io.envoyproxy.envoymobile.ResponseHeaders; import io.envoyproxy.envoymobile.ResponseTrailers; import io.envoyproxy.envoymobile.Stream; -import io.envoyproxy.envoymobile.UpstreamHttpProtocol; import io.envoyproxy.envoymobile.engine.AndroidJniLibrary; +import io.envoyproxy.envoymobile.engine.JniLibrary; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; @@ -24,7 +24,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.Optional; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executors; @@ -32,7 +31,6 @@ import java.util.concurrent.atomic.AtomicReference; import org.junit.After; import org.junit.AfterClass; -import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -41,6 +39,7 @@ @RunWith(RobolectricTestRunner.class) public class QuicTestServerTest { + private static final String hcmType = "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager"; @@ -100,44 +99,37 @@ public class QuicTestServerTest { + " upstream_tls_context:\n" + " sni: www.lyft.com"; - private static Engine engine; + private final Context appContext = ApplicationProvider.getApplicationContext(); + private Engine engine; @BeforeClass public static void loadJniLibrary() { AndroidJniLibrary.loadTestLibrary(); - System.loadLibrary("quic_test_server_jni"); - } - - @AfterClass - public static void shutdownEngine() { - if (engine != null) { - engine.terminate(); - } + JniLibrary.load(); } @Before public void setUpEngine() throws Exception { - if (engine == null) { - CountDownLatch latch = new CountDownLatch(1); - engine = new AndroidEngineBuilder(getContext().getApplicationContext(), new Custom(config)) - .addLogLevel(LogLevel.TRACE) - .setOnEngineRunning(() -> { - latch.countDown(); - return null; - }) - .build(); - latch.await(); // Don't launch a request before initialization has completed. - } + QuicTestServer.startQuicTestServer(appContext); + CountDownLatch latch = new CountDownLatch(1); + engine = new AndroidEngineBuilder(appContext, new Custom(config)) + .addLogLevel(LogLevel.TRACE) + .setOnEngineRunning(() -> { + latch.countDown(); + return null; + }) + .build(); + latch.await(); // Don't launch a request before initialization has completed. } @After - public void shutdownMockWebServer() throws IOException { + public void shutdownEngine() { + engine.terminate(); QuicTestServer.shutdownQuicTestServer(); } @Test public void get_simple() throws Exception { - QuicTestServer.startQuicTestServer(getContext()); QuicTestServerTest.RequestScenario requestScenario = new QuicTestServerTest.RequestScenario() .setHttpMethod(RequestMethod.GET) .setUrl(QuicTestServer.getServerURL()); @@ -161,6 +153,7 @@ public void get_simple() throws Exception { if (endStream) { latch.countDown(); } + System.err.println("EEE"); return null; }) .setOnResponseData((data, endStream, ignored) -> { @@ -175,12 +168,12 @@ public void get_simple() throws Exception { latch.countDown(); return null; }) - .setOnError((error, ignored) -> { + .setOnError((error, ignored1, ignored2) -> { response.get().setEnvoyError(error); latch.countDown(); return null; }) - .setOnCancel((ignored) -> { + .setOnCancel((ignored1, ignored2) -> { response.get().setCancelled(); latch.countDown(); return null; @@ -196,6 +189,7 @@ public void get_simple() throws Exception { } private static class RequestScenario { + private URL url; private RequestMethod method = null; private final List bodyChunks = new ArrayList<>(); @@ -233,6 +227,7 @@ QuicTestServerTest.RequestScenario setUrl(String url) throws MalformedURLExcepti } private static class Response { + private final AtomicReference headers = new AtomicReference<>(); private final AtomicReference trailers = new AtomicReference<>(); private final AtomicReference envoyError = new AtomicReference<>(); From 1c65b1c25f59a419d89680c1b8cbc6b492923cd8 Mon Sep 17 00:00:00 2001 From: Charles Le Borgne Date: Tue, 4 Jan 2022 12:27:18 +0000 Subject: [PATCH 36/54] Load Cert/Key from original file Signed-off-by: Charles Le Borgne --- test/common/integration/BUILD | 4 ++ test/common/integration/quic_test_server.cc | 63 +++---------------- .../jni/quic_test_server_jni_interface.cc | 6 +- .../envoymobile/engine/testing/BUILD | 4 +- .../engine/testing/QuicTestServer.java | 30 +++------ .../engine/testing/QuicTestServerTest.java | 21 +++---- 6 files changed, 30 insertions(+), 98 deletions(-) diff --git a/test/common/integration/BUILD b/test/common/integration/BUILD index 3559e80d0b..8e5d33cd43 100644 --- a/test/common/integration/BUILD +++ b/test/common/integration/BUILD @@ -17,6 +17,7 @@ envoy_cc_test( "@envoy//test/common/http:common_lib", "@envoy//test/integration:http_integration_lib", "@envoy//test/server:utility_lib", + "@envoy//test/test_common:environment_lib", ], ) @@ -39,6 +40,9 @@ envoy_cc_test_library( "quic_test_server.h", "quic_test_server_interface.h", ], + data = [ + "@envoy//test/config/integration/certs", + ], repository = "@envoy", deps = [ "@envoy//source/exe:process_wide_lib", diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc index a6386e0eae..c8f59a941a 100644 --- a/test/common/integration/quic_test_server.cc +++ b/test/common/integration/quic_test_server.cc @@ -1,74 +1,25 @@ #include "quic_test_server.h" +#include "test/test_common/environment.h" + namespace Envoy { Network::TransportSocketFactoryPtr QuicTestServer::createUpstreamTlsContext( testing::NiceMock& factory_context) { envoy::extensions::transport_sockets::tls::v3::DownstreamTlsContext tls_context; Extensions::TransportSockets::Tls::ContextManagerImpl context_manager{time_system_}; - const std::string yaml = absl::StrFormat( R"EOF( common_tls_context: alpn_protocols: h3 tls_certificates: - certificate_chain: - inline_string: | - -----BEGIN CERTIFICATE----- - MIIEPjCCAyagAwIBAgIUEuy1WgSCzX6mojPirk7Th6uhNHowDQYJKoZIhvcNAQEL - BQAwfzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcM - DVNhbiBGcmFuY2lzY28xDTALBgNVBAoMBEx5ZnQxGTAXBgNVBAsMEEx5ZnQgRW5n - aW5lZXJpbmcxGTAXBgNVBAMMEFRlc3QgVXBzdHJlYW0gQ0EwHhcNMjAwODA1MTkx - NjAyWhcNMjIwODA1MTkxNjAyWjCBgzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNh - bGlmb3JuaWExFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xDTALBgNVBAoMBEx5ZnQx - GTAXBgNVBAsMEEx5ZnQgRW5naW5lZXJpbmcxHTAbBgNVBAMMFFRlc3QgVXBzdHJl - YW0gU2VydmVyMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtpiYA4/I - NuflkPe4L/GTslmngNQUCo8TzPXG0gt7uoxr4FeuVy7AaD28S2/hwhbl+bDtHTQY - mvBUwNMsYzpND2eQ3sSIumdeLzBEKP2mnnZ9gE/Zd2TIuZl686RpDq0B6ZdZSpCu - bqQmmPFLiRNH8JViJZMN5yqMt7T5oq+DnCYQZllqmpAwd6NnhKALrYmZ87oqc0zh - kf+5amP7zMYKkwQuRwcx4QPZkEp3+qhszolpAJ52dFGJ+pLuUVDg0Gf0cnxLjFKc - 6vcTlj4tsymR4ci58MHRt4EdGdhShw0oaj67gRRfU4Vj61I2ZAVH07kL0mjO2TZT - EKrOEJJ7/dtxdwIDAQABo4GsMIGpMAwGA1UdEwEB/wQCMAAwCwYDVR0PBAQDAgXg - MB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDATAtBgNVHREEJjAkggoqLmx5 - ZnQuY29thwR/AAABhxAAAAAAAAAAAAAAAAAAAAABMB0GA1UdDgQWBBQeoC5wxwX5 - k3ggIN/844/6jKx9czAfBgNVHSMEGDAWgBQ7Zh1TopMm7SY1RCOEO8L1G8IAZDAN - BgkqhkiG9w0BAQsFAAOCAQEA18wEg8LnPm99cIouFUFMAO+BpiY2KVa9Bu6x07m9 - quNFv7/4mLt87sk/umD3LH/tDjqW0D84vhG9a+0yDq7ZrD/P5eK3R+yBINwhe4/x - obJlThEsbcZF1FkMnq1rt53izukyQLLQwoVxidQl3HCg3hosWmpH1VBPgwoize6V - aAhKLW0n+JSfIE1d80nvZdYlHuCnS6UhLmAbTBCnwT0aGTfzT0Dd4KlYiY8vGZRu - tXOw4MzKtJcOL3t7Zpz2mhqN25dyiuyvKEhLXdx48aemwa2t6ISfFKsd0/glnNe/ - PFZMakzKv1G0xLGURjsInCZ0kePAmerfZN6CBZDo4laYEg== - -----END CERTIFICATE----- + filename: %s private_key: - inline_string: | - -----BEGIN RSA PRIVATE KEY----- - MIIEpAIBAAKCAQEAtpiYA4/INuflkPe4L/GTslmngNQUCo8TzPXG0gt7uoxr4Feu - Vy7AaD28S2/hwhbl+bDtHTQYmvBUwNMsYzpND2eQ3sSIumdeLzBEKP2mnnZ9gE/Z - d2TIuZl686RpDq0B6ZdZSpCubqQmmPFLiRNH8JViJZMN5yqMt7T5oq+DnCYQZllq - mpAwd6NnhKALrYmZ87oqc0zhkf+5amP7zMYKkwQuRwcx4QPZkEp3+qhszolpAJ52 - dFGJ+pLuUVDg0Gf0cnxLjFKc6vcTlj4tsymR4ci58MHRt4EdGdhShw0oaj67gRRf - U4Vj61I2ZAVH07kL0mjO2TZTEKrOEJJ7/dtxdwIDAQABAoIBACz6E1+1N/0GTA7U - ZgMxP09MNC1QkAs1yQvQcoPknjqKQjxFfMUu1+gVZN80FOjpGQbTJOTvoyvvDQFe - Qu3CO58SxKWKxZ8cvR9khTWPnU4lI67KfGejZKoK+zUuh049IV53kGAEmWLZfkRo - E1IVdL/3G/DjcyZA3d6WbnM7RnDcqORPnig4lq5HxN76eBdssbxtrAi3Sjy3ChMy - BLInnryF4UtaT5xqR26YjgtFmYkunrgXTe1i/ewQgBBkSPXcNr7or69hCCv0SG9e - vRsv1r+Uug3/iRZDjEhKBmXWNAZJ/IsDF37ywiyeBdUY+klDX+mWz+0BB0us8b4u - LxoZQTECgYEA2Gu9EVC0RMrQ9FF5AgKKJWmZKkOn346RkPrtbl5lbuUgnVdBXJjr - wfMZVTD/8E/tMN4EMSGmC9bxCpRRzhrphrm7SHGD6b9O30DH9q0TV0r0A8IG/bMO - xJLYjrYVxtEE+KckzvyvfIefbDG7wYkI3u+ObmjBg9t6jcErKlI/PdkCgYEA1/1E - T+cpR16iOPz1mz+f/GU4YmPkdSDj/PrjMv0c1OTDvdPiZPpLkhLUKiICnKSKbYjX - Ko8fdZc3cmakgD1dXtAfR7Tf/hXQIR5+iHD48I5e9DVlkqMNDObfj82ohTFKVe/P - ZSwgDiAPTMFxWr26u/GzY5D3adCQYJyKE2wTh88CgYEAu7vpzGVnmu0ciXNLNvUh - BQcvODxsGT9BArTI1Z7I+oOD4TjZmAuHJz1L0lypB7stk+BjXoND2K1hdr3moJUz - 0gy3a0YdGd07++nkDBVi26xHNCNRkS2MN/TyKgnFpiuW1mOXSH5lc+7p2h7iMiY/ - LbQ8p4Xzp//xtZnFafbiqTECgYEAwDN5KZ1r5z24H/xCVv+cT46HSU7ZCr3VA9cC - fOouUOitouu9J9xviTJGKKQRLPFi2awOxKmN9ic1SRE7y35P60JKw5WaSdGBXydy - s9nMPMyEhM5Lb9y2jUeZo68ACl5dZvG63a4RbGBtHQF67KOvWvXvi2eCM2BMShyi - 5jujeZMCgYAjewq1hVqL1FOD8sIFpmndsH3+Dfc7BJ/erqGOX9bQYGvJO4nCe+7K - 4o8qFQf4jwdxu0iNxYJIMdn+l4/pz2e7GUFHjgMduUclf27Qj1p+8EyYqp6cmkzM - 8mcwRkYo3aM70EmUu0Xxi3d5O5F1bIJ5MkgXaX/zSF2N02B3jXroxQ== - -----END RSA PRIVATE KEY----- -)EOF"); + filename: %s +)EOF", + "../envoy/test/config/integration/certs/upstreamcert.pem", + "../envoy/test/config/integration/certs/upstreamkey.pem"); TestUtility::loadFromYaml(yaml, tls_context); envoy::extensions::transport_sockets::quic::v3::QuicDownstreamTransport quic_config; quic_config.mutable_downstream_tls_context()->MergeFrom(tls_context); diff --git a/test/common/jni/quic_test_server_jni_interface.cc b/test/common/jni/quic_test_server_jni_interface.cc index c2f44636e2..f1c5581f2f 100644 --- a/test/common/jni/quic_test_server_jni_interface.cc +++ b/test/common/jni/quic_test_server_jni_interface.cc @@ -1,4 +1,5 @@ #include + #include "test/common/integration/quic_test_server_interface.h" #include "library/common/jni/jni_support.h" @@ -11,12 +12,9 @@ extern "C" JNIEXPORT void JNICALL Java_io_envoyproxy_envoymobile_engine_testing_QuicTestServer_nativeStartQuicTestServer( - JNIEnv* env, jclass clazz, jstring file_path, jstring test_data_dir) { + JNIEnv* env, jclass clazz) { jni_log("[QTS]", "starting server"); start_server(); - - // Call java method to open block - env->CallStaticVoidMethod(clazz, env->GetStaticMethodID(clazz, "onServerStarted", "()V")); } extern "C" JNIEXPORT jint JNICALL diff --git a/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD b/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD index 2274d70405..fd56bb9c74 100644 --- a/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD @@ -12,8 +12,6 @@ android_library( "QuicTestServer.java", ], visibility = ["//test:__subpackages__"], - deps = [ - ], ) envoy_mobile_android_test( @@ -21,7 +19,7 @@ envoy_mobile_android_test( srcs = [ "QuicTestServerTest.java", ], - library_path = "library/common/jni:test/common/jni", + library_path = "test/common/jni", native_deps = [ "//test/common/jni:libquic_test_server_jni.so", "//test/common/jni:libquic_test_server_jni.jnilib", diff --git a/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServer.java b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServer.java index 970790b5b3..3c68db31e9 100644 --- a/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServer.java +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServer.java @@ -1,45 +1,35 @@ package io.envoyproxy.envoymobile.engine.testing; -import android.content.Context; -import android.os.ConditionVariable; -import android.util.Log; +import java.util.concurrent.atomic.AtomicBoolean; /** * Wrapper class to start a Quic test server. */ - public final class QuicTestServer { - private static final ConditionVariable sBlock = new ConditionVariable(); - private static final String TAG = QuicTestServer.class.getSimpleName(); private static final String CERT_USED = "upstreamcert.pem"; private static final String KEY_USED = "upstreamkey.pem"; - private static final String[] CERTS_USED = {CERT_USED}; - private static boolean sServerRunning; + private static final AtomicBoolean sServerRunning = new AtomicBoolean(); /* * Starts the server. */ - public static void startQuicTestServer(Context context) { - if (sServerRunning) { + public static void startQuicTestServer() { + if (!sServerRunning.compareAndSet(false, true)) { throw new IllegalStateException("Quic server is already running"); } - nativeStartQuicTestServer("path", "file"); - sBlock.block(); - sBlock.close(); - sServerRunning = true; + nativeStartQuicTestServer(); } /** * Shuts down the server. No-op if the server is already shut down. */ public static void shutdownQuicTestServer() { - if (!sServerRunning) { + if (!sServerRunning.compareAndSet(true, false)) { return; } nativeShutdownQuicTestServer(); - sServerRunning = false; } public static String getServerURL() { @@ -59,14 +49,10 @@ public static long createMockCertVerifier() { return 0L; } - // @CalledByNative - private static void onServerStarted() { - Log.i(TAG, "Quic server started."); - sBlock.open(); - } + private static native void nativeStartQuicTestServer(); - private static native void nativeStartQuicTestServer(String filePath, String testDataDir); private static native void nativeShutdownQuicTestServer(); + private static native int nativeGetServerPort(); private QuicTestServer() {} diff --git a/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java index ece6a89e03..621da515e5 100644 --- a/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java @@ -17,7 +17,6 @@ import io.envoyproxy.envoymobile.Stream; import io.envoyproxy.envoymobile.engine.AndroidJniLibrary; import io.envoyproxy.envoymobile.engine.JniLibrary; -import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.nio.ByteBuffer; @@ -30,7 +29,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import org.junit.After; -import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -110,7 +108,7 @@ public static void loadJniLibrary() { @Before public void setUpEngine() throws Exception { - QuicTestServer.startQuicTestServer(appContext); + QuicTestServer.startQuicTestServer(); CountDownLatch latch = new CountDownLatch(1); engine = new AndroidEngineBuilder(appContext, new Custom(config)) .addLogLevel(LogLevel.TRACE) @@ -135,13 +133,14 @@ public void get_simple() throws Exception { .setUrl(QuicTestServer.getServerURL()); QuicTestServerTest.Response response = sendRequest(requestScenario); + assertThat(response.getHeaders().getHttpStatus()).isEqualTo(200); assertThat(response.getBodyAsString()).isEqualTo("aaaaaaaaaa"); assertThat(response.getEnvoyError()).isNull(); } - private QuicTestServerTest.Response - sendRequest(QuicTestServerTest.RequestScenario requestScenario) throws Exception { + private QuicTestServerTest.Response sendRequest(RequestScenario requestScenario) + throws Exception { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference response = new AtomicReference<>(new QuicTestServerTest.Response()); @@ -150,22 +149,14 @@ public void get_simple() throws Exception { .newStreamPrototype() .setOnResponseHeaders((responseHeaders, endStream, ignored) -> { response.get().setHeaders(responseHeaders); - if (endStream) { - latch.countDown(); - } - System.err.println("EEE"); return null; }) .setOnResponseData((data, endStream, ignored) -> { response.get().addBody(data); - if (endStream) { - latch.countDown(); - } return null; }) .setOnResponseTrailers((trailers, ignored) -> { response.get().setTrailers(trailers); - latch.countDown(); return null; }) .setOnError((error, ignored1, ignored2) -> { @@ -178,6 +169,10 @@ public void get_simple() throws Exception { latch.countDown(); return null; }) + .setOnComplete((ignored1, ignored2) -> { + latch.countDown(); + return null; + }) .start(Executors.newSingleThreadExecutor()) .sendHeaders(requestScenario.getHeaders(), !requestScenario.hasBody()); requestScenario.getBodyChunks().forEach(stream::sendData); From 3b279a80654936f6280182903c717344f92451c0 Mon Sep 17 00:00:00 2001 From: Charles Le Borgne Date: Tue, 4 Jan 2022 12:32:38 +0000 Subject: [PATCH 37/54] Fix BUILD format Signed-off-by: Charles Le Borgne --- test/common/jni/BUILD | 1 - 1 file changed, 1 deletion(-) diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index 31d1af0abe..3a1356e44c 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -23,7 +23,6 @@ cc_binary( "@local_jdk//:jni_header", ], copts = ["-std=c++17"], - linkopts = [], linkshared = True, deps = [ "//library/common/jni:base_java_jni_lib", From b4ed90dad3f8365aaa93e7f891c89b2b6fe0d66e Mon Sep 17 00:00:00 2001 From: Charles Le Borgne Date: Tue, 4 Jan 2022 12:51:23 +0000 Subject: [PATCH 38/54] BUILD fix Signed-off-by: Charles Le Borgne --- test/common/integration/BUILD | 8 -------- test/common/jni/BUILD | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/test/common/integration/BUILD b/test/common/integration/BUILD index 8e5d33cd43..1610f7ff6c 100644 --- a/test/common/integration/BUILD +++ b/test/common/integration/BUILD @@ -24,14 +24,6 @@ envoy_cc_test( # interface libs for quic test server's jni implementation envoy_cc_test_library( name = "quic_test_server_interface_lib", - repository = "@envoy", - deps = [ - ":quic_test_server_interface_lib_no_stamp", - ], -) - -envoy_cc_test_library( - name = "quic_test_server_interface_lib_no_stamp", srcs = [ "quic_test_server.cc", "quic_test_server_interface.cc", diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index 3a1356e44c..8de058294d 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -1,5 +1,5 @@ -load("//bazel:kotlin_lib.bzl", "envoy_mobile_so_to_jni_lib") load("@envoy//bazel:envoy_build_system.bzl", "envoy_package") +load("//bazel:kotlin_lib.bzl", "envoy_mobile_so_to_jni_lib") licenses(["notice"]) # Apache 2 From 4f4c9304005e2ca73248d1e4c222ca23ce038cbf Mon Sep 17 00:00:00 2001 From: Charles Le Borgne Date: Tue, 4 Jan 2022 13:10:26 +0000 Subject: [PATCH 39/54] Attempt to fix BUILD format Signed-off-by: Charles Le Borgne --- test/common/jni/BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index 8de058294d..f630ceec15 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -1,3 +1,4 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary") load("@envoy//bazel:envoy_build_system.bzl", "envoy_package") load("//bazel:kotlin_lib.bzl", "envoy_mobile_so_to_jni_lib") From 8109c4ea84f1001e049aef1a67eaa6c35e9f4d61 Mon Sep 17 00:00:00 2001 From: Charles Le Borgne Date: Tue, 4 Jan 2022 13:33:02 +0000 Subject: [PATCH 40/54] Kick CI Signed-off-by: Charles Le Borgne --- test/common/jni/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index f630ceec15..3a167db040 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -1,5 +1,5 @@ -load("@rules_cc//cc:defs.bzl", "cc_binary") load("@envoy//bazel:envoy_build_system.bzl", "envoy_package") +load("@rules_cc//cc:defs.bzl", "cc_binary") load("//bazel:kotlin_lib.bzl", "envoy_mobile_so_to_jni_lib") licenses(["notice"]) # Apache 2 From 8f846be4fa0abab2fdac936ea6c8560f1647e7ef Mon Sep 17 00:00:00 2001 From: Charles Le Borgne Date: Tue, 4 Jan 2022 14:56:34 +0000 Subject: [PATCH 41/54] Kick CI Signed-off-by: Charles Le Borgne --- test/common/jni/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index 3a167db040..f630ceec15 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -1,5 +1,5 @@ -load("@envoy//bazel:envoy_build_system.bzl", "envoy_package") load("@rules_cc//cc:defs.bzl", "cc_binary") +load("@envoy//bazel:envoy_build_system.bzl", "envoy_package") load("//bazel:kotlin_lib.bzl", "envoy_mobile_so_to_jni_lib") licenses(["notice"]) # Apache 2 From 8a0accbf355f6f14fea3443adbe24c76b68d16a6 Mon Sep 17 00:00:00 2001 From: Charles Le Borgne Date: Tue, 4 Jan 2022 15:38:15 +0000 Subject: [PATCH 42/54] Kick CI Signed-off-by: Charles Le Borgne --- test/common/jni/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common/jni/BUILD b/test/common/jni/BUILD index f630ceec15..3a167db040 100644 --- a/test/common/jni/BUILD +++ b/test/common/jni/BUILD @@ -1,5 +1,5 @@ -load("@rules_cc//cc:defs.bzl", "cc_binary") load("@envoy//bazel:envoy_build_system.bzl", "envoy_package") +load("@rules_cc//cc:defs.bzl", "cc_binary") load("//bazel:kotlin_lib.bzl", "envoy_mobile_so_to_jni_lib") licenses(["notice"]) # Apache 2 From 29aabd1cbc963472dac0590e53695a01e3e7980c Mon Sep 17 00:00:00 2001 From: Charles Le Borgne Date: Tue, 11 Jan 2022 14:39:00 +0000 Subject: [PATCH 43/54] Kick CI Signed-off-by: Charles Le Borgne --- test/java/io/envoyproxy/envoymobile/engine/testing/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD b/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD index fd56bb9c74..8e84dfb32f 100644 --- a/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD @@ -1,5 +1,5 @@ -load("@envoy//bazel:envoy_build_system.bzl", "envoy_package") load("@envoy_mobile//bazel:kotlin_test.bzl", "envoy_mobile_android_test") +load("@envoy//bazel:envoy_build_system.bzl", "envoy_package") licenses(["notice"]) # Apache 2 From 1b0ffc9c9bb223a61d18374dbbd2211907d54507 Mon Sep 17 00:00:00 2001 From: Charles Le Borgne Date: Tue, 11 Jan 2022 15:40:06 +0000 Subject: [PATCH 44/54] Remove logs Signed-off-by: Charles Le Borgne --- .../envoymobile/engine/testing/QuicTestServerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java index 621da515e5..e139a25755 100644 --- a/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java @@ -111,7 +111,7 @@ public void setUpEngine() throws Exception { QuicTestServer.startQuicTestServer(); CountDownLatch latch = new CountDownLatch(1); engine = new AndroidEngineBuilder(appContext, new Custom(config)) - .addLogLevel(LogLevel.TRACE) + .addLogLevel(LogLevel.OFF) .setOnEngineRunning(() -> { latch.countDown(); return null; From 16f14c9c5915081a78ba9e2763f48efde399880a Mon Sep 17 00:00:00 2001 From: Charles Le Borgne Date: Tue, 11 Jan 2022 16:50:16 +0000 Subject: [PATCH 45/54] Use port zero to avoid conflicts Signed-off-by: Charles Le Borgne --- test/common/integration/quic_test_server.cc | 2 +- .../envoymobile/engine/testing/QuicTestServerTest.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc index c8f59a941a..a67a1fde47 100644 --- a/test/common/integration/quic_test_server.cc +++ b/test/common/integration/quic_test_server.cc @@ -34,7 +34,7 @@ Network::TransportSocketFactoryPtr QuicTestServer::createUpstreamTlsContext( QuicTestServer::QuicTestServer() : api_(Api::createApiForTest(stats_store_, time_system_)), - version_(Network::Address::IpVersion::v4), upstream_config_(time_system_), port_(34210) { + version_(Network::Address::IpVersion::v4), upstream_config_(time_system_), port_(0) { ON_CALL(factory_context_, api()).WillByDefault(testing::ReturnRef(*api_)); ON_CALL(factory_context_, scope()).WillByDefault(testing::ReturnRef(stats_store_)); } diff --git a/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java index e139a25755..e73bbdd824 100644 --- a/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java @@ -81,7 +81,7 @@ public class QuicTestServerTest { + " - lb_endpoints:\n" + " - endpoint:\n" + " address:\n" - + " socket_address: { address: 127.0.0.1, port_value: 34210 }\n" + + " socket_address: { address: 127.0.0.1, port_value: %s }\n" + " typed_extension_protocol_options:\n" + " envoy.extensions.upstreams.http.v3.HttpProtocolOptions:\n" + @@ -110,7 +110,8 @@ public static void loadJniLibrary() { public void setUpEngine() throws Exception { QuicTestServer.startQuicTestServer(); CountDownLatch latch = new CountDownLatch(1); - engine = new AndroidEngineBuilder(appContext, new Custom(config)) + engine = new AndroidEngineBuilder( + appContext, new Custom(String.format(config, QuicTestServer.getServerPort()))) .addLogLevel(LogLevel.OFF) .setOnEngineRunning(() -> { latch.countDown(); From fbfa612d85edf32f158fd4fd3b467a9d071c5845 Mon Sep 17 00:00:00 2001 From: Charles Le Borgne Date: Wed, 12 Jan 2022 12:30:15 +0000 Subject: [PATCH 46/54] Try another port Signed-off-by: Charles Le Borgne --- test/common/integration/quic_test_server.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc index a67a1fde47..31e2ab75e6 100644 --- a/test/common/integration/quic_test_server.cc +++ b/test/common/integration/quic_test_server.cc @@ -34,7 +34,7 @@ Network::TransportSocketFactoryPtr QuicTestServer::createUpstreamTlsContext( QuicTestServer::QuicTestServer() : api_(Api::createApiForTest(stats_store_, time_system_)), - version_(Network::Address::IpVersion::v4), upstream_config_(time_system_), port_(0) { + version_(Network::Address::IpVersion::v4), upstream_config_(time_system_), port_(13545) { ON_CALL(factory_context_, api()).WillByDefault(testing::ReturnRef(*api_)); ON_CALL(factory_context_, scope()).WillByDefault(testing::ReturnRef(stats_store_)); } From 9ccb763877b30a22c6a6230162b3aa6198ec3899 Mon Sep 17 00:00:00 2001 From: Charles Le Borgne Date: Wed, 12 Jan 2022 16:38:33 +0000 Subject: [PATCH 47/54] Desperate attempt with Manifest Signed-off-by: Charles Le Borgne --- test/common/integration/quic_test_server.cc | 2 +- .../envoyproxy/envoymobile/engine/testing/Manifest.xml | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 test/java/io/envoyproxy/envoymobile/engine/testing/Manifest.xml diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc index 31e2ab75e6..a67a1fde47 100644 --- a/test/common/integration/quic_test_server.cc +++ b/test/common/integration/quic_test_server.cc @@ -34,7 +34,7 @@ Network::TransportSocketFactoryPtr QuicTestServer::createUpstreamTlsContext( QuicTestServer::QuicTestServer() : api_(Api::createApiForTest(stats_store_, time_system_)), - version_(Network::Address::IpVersion::v4), upstream_config_(time_system_), port_(13545) { + version_(Network::Address::IpVersion::v4), upstream_config_(time_system_), port_(0) { ON_CALL(factory_context_, api()).WillByDefault(testing::ReturnRef(*api_)); ON_CALL(factory_context_, scope()).WillByDefault(testing::ReturnRef(stats_store_)); } diff --git a/test/java/io/envoyproxy/envoymobile/engine/testing/Manifest.xml b/test/java/io/envoyproxy/envoymobile/engine/testing/Manifest.xml new file mode 100644 index 0000000000..ade0d8dde2 --- /dev/null +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/Manifest.xml @@ -0,0 +1,9 @@ + + + + + + From 2e8cdcf8b47959c2c65df0c34b8d638db530bb5e Mon Sep 17 00:00:00 2001 From: Charles Le Borgne Date: Wed, 12 Jan 2022 17:53:37 +0000 Subject: [PATCH 48/54] Update QuicTestServer BUILD file Signed-off-by: Charles Le Borgne --- test/java/io/envoyproxy/envoymobile/engine/testing/BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD b/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD index 8e84dfb32f..6ebe4919c7 100644 --- a/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD @@ -8,6 +8,7 @@ envoy_package() android_library( name = "testing", testonly = True, + manifest = "Manifest.xml", srcs = [ "QuicTestServer.java", ], From 097f6f4f3dbc0e2f488a190ceb666566873a53a1 Mon Sep 17 00:00:00 2001 From: Charles Le Borgne Date: Thu, 13 Jan 2022 22:56:21 +0000 Subject: [PATCH 49/54] Enable networking for CI Signed-off-by: Charles Le Borgne --- test/java/io/envoyproxy/envoymobile/engine/testing/BUILD | 5 ++++- .../envoyproxy/envoymobile/engine/testing/Manifest.xml | 9 --------- 2 files changed, 4 insertions(+), 10 deletions(-) delete mode 100644 test/java/io/envoyproxy/envoymobile/engine/testing/Manifest.xml diff --git a/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD b/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD index 6ebe4919c7..15eb8e9454 100644 --- a/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD @@ -8,7 +8,6 @@ envoy_package() android_library( name = "testing", testonly = True, - manifest = "Manifest.xml", srcs = [ "QuicTestServer.java", ], @@ -20,6 +19,10 @@ envoy_mobile_android_test( srcs = [ "QuicTestServerTest.java", ], + exec_properties = { + # TODO(lfpino): Remove this once the sandboxNetwork=off works for ipv4 localhost addresses. + "sandboxNetwork": "standard", + }, library_path = "test/common/jni", native_deps = [ "//test/common/jni:libquic_test_server_jni.so", diff --git a/test/java/io/envoyproxy/envoymobile/engine/testing/Manifest.xml b/test/java/io/envoyproxy/envoymobile/engine/testing/Manifest.xml deleted file mode 100644 index ade0d8dde2..0000000000 --- a/test/java/io/envoyproxy/envoymobile/engine/testing/Manifest.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - From 3373d94beecb1531628d23cd5d8d91983a974835 Mon Sep 17 00:00:00 2001 From: Charles Le Borgne Date: Thu, 13 Jan 2022 23:47:12 +0000 Subject: [PATCH 50/54] Revert unwanted file Signed-off-by: Charles Le Borgne --- library/java/org/chromium/net/impl/CronetUrlRequest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/library/java/org/chromium/net/impl/CronetUrlRequest.java b/library/java/org/chromium/net/impl/CronetUrlRequest.java index b0a7b0e8d9..4190214389 100644 --- a/library/java/org/chromium/net/impl/CronetUrlRequest.java +++ b/library/java/org/chromium/net/impl/CronetUrlRequest.java @@ -499,12 +499,10 @@ private void fireOpenConnection() { } catch (MalformedURLException e) { throw new IllegalArgumentException("Invalid URL", e); } - headers.computeIfAbsent(":authority", unused -> new ArrayList<>()).add(url.getAuthority()); headers.computeIfAbsent(":method", unused -> new ArrayList<>()).add(initialMethod); headers.computeIfAbsent(":path", unused -> new ArrayList<>()).add(url.getFile()); headers.computeIfAbsent(":scheme", unused -> new ArrayList<>()).add(url.getProtocol()); - boolean hasUserAgent = false; boolean hasContentType = false; for (Map.Entry header : headersList) { From 8b6e8f2729ae10b180e09e091a09e1b77b4ce9fa Mon Sep 17 00:00:00 2001 From: Charles Le Borgne Date: Fri, 14 Jan 2022 00:02:44 +0000 Subject: [PATCH 51/54] Kick CI Signed-off-by: Charles Le Borgne --- test/java/io/envoyproxy/envoymobile/engine/testing/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD b/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD index 15eb8e9454..fcdd93891c 100644 --- a/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/BUILD @@ -1,5 +1,5 @@ -load("@envoy_mobile//bazel:kotlin_test.bzl", "envoy_mobile_android_test") load("@envoy//bazel:envoy_build_system.bzl", "envoy_package") +load("@envoy_mobile//bazel:kotlin_test.bzl", "envoy_mobile_android_test") licenses(["notice"]) # Apache 2 From 1b4321eac31cc7a0d333a537677fb349d18bfc8a Mon Sep 17 00:00:00 2001 From: Charles Le Borgne Date: Wed, 19 Jan 2022 17:56:35 +0000 Subject: [PATCH 52/54] Addressed Ryan's comments. Signed-off-by: Charles Le Borgne --- test/common/integration/quic_test_server.cc | 21 +++++++++------- test/common/integration/quic_test_server.h | 11 +++++++++ .../engine/testing/QuicTestServer.java | 24 ++++++++----------- .../engine/testing/QuicTestServerTest.java | 11 ++++----- 4 files changed, 38 insertions(+), 29 deletions(-) diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc index a67a1fde47..84b0c2664e 100644 --- a/test/common/integration/quic_test_server.cc +++ b/test/common/integration/quic_test_server.cc @@ -14,12 +14,10 @@ Network::TransportSocketFactoryPtr QuicTestServer::createUpstreamTlsContext( alpn_protocols: h3 tls_certificates: - certificate_chain: - filename: %s + filename: ../envoy/test/config/integration/certs/upstreamcert.pem private_key: - filename: %s -)EOF", - "../envoy/test/config/integration/certs/upstreamcert.pem", - "../envoy/test/config/integration/certs/upstreamkey.pem"); + filename: ../envoy/test/config/integration/certs/upstreamkey.pem +)EOF"); TestUtility::loadFromYaml(yaml, tls_context); envoy::extensions::transport_sockets::quic::v3::QuicDownstreamTransport quic_config; quic_config.mutable_downstream_tls_context()->MergeFrom(tls_context); @@ -35,8 +33,10 @@ Network::TransportSocketFactoryPtr QuicTestServer::createUpstreamTlsContext( QuicTestServer::QuicTestServer() : api_(Api::createApiForTest(stats_store_, time_system_)), version_(Network::Address::IpVersion::v4), upstream_config_(time_system_), port_(0) { + ASSERT(!upstream_); ON_CALL(factory_context_, api()).WillByDefault(testing::ReturnRef(*api_)); ON_CALL(factory_context_, scope()).WillByDefault(testing::ReturnRef(stats_store_)); + upstream_config_.udp_fake_upstream_ = FakeUpstreamConfig::UdpConfig(); } void QuicTestServer::startQuicTestServer() { @@ -46,7 +46,6 @@ void QuicTestServer::startQuicTestServer() { // end pre-setup upstream_config_.upstream_protocol_ = Http::CodecType::HTTP3; - upstream_config_.udp_fake_upstream_ = FakeUpstreamConfig::UdpConfig(); Network::TransportSocketFactoryPtr factory = createUpstreamTlsContext(factory_context_); @@ -57,7 +56,13 @@ void QuicTestServer::startQuicTestServer() { ENVOY_LOG_MISC(debug, "Upstream now listening on {}", upstream_->localAddress()->asString()); } -void QuicTestServer::shutdownQuicTestServer() { upstream_.reset(); } +void QuicTestServer::shutdownQuicTestServer() { + ASSERT(upstream_); + upstream_.reset(); +} -int QuicTestServer::getServerPort() { return upstream_->localAddress()->ip()->port(); } +int QuicTestServer::getServerPort() { + ASSERT(upstream_); + return upstream_->localAddress()->ip()->port(); +} } // namespace Envoy diff --git a/test/common/integration/quic_test_server.h b/test/common/integration/quic_test_server.h index 6d8f9374db..261624a68b 100644 --- a/test/common/integration/quic_test_server.h +++ b/test/common/integration/quic_test_server.h @@ -31,10 +31,21 @@ class QuicTestServer { public: QuicTestServer(); + /** + * Starts the server. Can only have one server active per JVM. This is blocking until the port can + * start accepting requests. + */ void startQuicTestServer(); + /** + * Shutdowns the server. Can be restarted later. This is blocking until the server has freed all + * resources. + */ void shutdownQuicTestServer(); + /** + * Returns the port that got attributed. Can only be called once the server has been started. + */ int getServerPort(); }; diff --git a/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServer.java b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServer.java index 3c68db31e9..db57b7f28b 100644 --- a/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServer.java +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServer.java @@ -7,13 +7,10 @@ */ public final class QuicTestServer { - private static final String CERT_USED = "upstreamcert.pem"; - private static final String KEY_USED = "upstreamkey.pem"; - private static final AtomicBoolean sServerRunning = new AtomicBoolean(); /* - * Starts the server. + * Starts the server. Throws an {@link IllegalStateException} if already started. */ public static void startQuicTestServer() { if (!sServerRunning.compareAndSet(false, true)) { @@ -23,7 +20,7 @@ public static void startQuicTestServer() { } /** - * Shuts down the server. No-op if the server is already shut down. + * Shutdowns the server. No-op if the server is already shutdown. */ public static void shutdownQuicTestServer() { if (!sServerRunning.compareAndSet(true, false)) { @@ -38,15 +35,14 @@ public static String getServerURL() { public static String getServerHost() { return "test.example.com"; } - public static int getServerPort() { return nativeGetServerPort(); } - - public static final String getServerCert() { return CERT_USED; } - - public static final String getServerCertKey() { return KEY_USED; } - - public static long createMockCertVerifier() { - // to be implemented - return 0L; + /** + * Returns the server attributed port. Throws an {@link IllegalStateException} if not started. + */ + public static int getServerPort() { + if (!sServerRunning.get()) { + throw new IllegalStateException("Quic server not started."); + } + return nativeGetServerPort(); } private static native void nativeStartQuicTestServer(); diff --git a/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java index e73bbdd824..982b4f5a21 100644 --- a/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java +++ b/test/java/io/envoyproxy/envoymobile/engine/testing/QuicTestServerTest.java @@ -38,13 +38,10 @@ @RunWith(RobolectricTestRunner.class) public class QuicTestServerTest { - private static final String hcmType = + private static final String HCM_TYPE = "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager"; - private static final String quicDownstreamType = - "type.googleapis.com/envoy.extensions.transport_sockets.quic.v3.QuicDownstreamTransport"; - - private static final String quicUpstreamType = + private static final String QUIC_UPSTREAM_TYPE = "type.googleapis.com/envoy.extensions.transport_sockets.quic.v3.QuicUpstreamTransport"; private static final String config = @@ -55,7 +52,7 @@ public class QuicTestServerTest { + " socket_address: { protocol: TCP, address: 0.0.0.0, port_value: 10000 }\n" + " api_listener:\n" + " api_listener:\n" - + " \"@type\": " + hcmType + "\n" + + " \"@type\": " + HCM_TYPE + "\n" + " stat_prefix: api_hcm\n" + " route_config:\n" + " name: api_router\n" @@ -93,7 +90,7 @@ public class QuicTestServerTest { + " transport_socket:\n" + " name: envoy.transport_sockets.quic\n" + " typed_config:\n" - + " \"@type\": " + quicUpstreamType + "\n" + + " \"@type\": " + QUIC_UPSTREAM_TYPE + "\n" + " upstream_tls_context:\n" + " sni: www.lyft.com"; From 6e998daf58f0a4f208d8ad14f65d483857bd2039 Mon Sep 17 00:00:00 2001 From: Charles Le Borgne Date: Wed, 19 Jan 2022 18:00:46 +0000 Subject: [PATCH 53/54] Fix ASSERT put at the wrong place Signed-off-by: Charles Le Borgne --- test/common/integration/quic_test_server.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common/integration/quic_test_server.cc b/test/common/integration/quic_test_server.cc index 84b0c2664e..c145501ffe 100644 --- a/test/common/integration/quic_test_server.cc +++ b/test/common/integration/quic_test_server.cc @@ -33,13 +33,13 @@ Network::TransportSocketFactoryPtr QuicTestServer::createUpstreamTlsContext( QuicTestServer::QuicTestServer() : api_(Api::createApiForTest(stats_store_, time_system_)), version_(Network::Address::IpVersion::v4), upstream_config_(time_system_), port_(0) { - ASSERT(!upstream_); ON_CALL(factory_context_, api()).WillByDefault(testing::ReturnRef(*api_)); ON_CALL(factory_context_, scope()).WillByDefault(testing::ReturnRef(stats_store_)); upstream_config_.udp_fake_upstream_ = FakeUpstreamConfig::UdpConfig(); } void QuicTestServer::startQuicTestServer() { + ASSERT(!upstream_); // pre-setup: see https://github.com/envoyproxy/envoy/blob/main/test/test_runner.cc Logger::Context logging_state(spdlog::level::level_enum::err, "[%Y-%m-%d %T.%e][%t][%l][%n] [%g:%#] %v", lock, false, false); From e6d6b26bbd3ba7c471c2f193eac57a8c7f70cff0 Mon Sep 17 00:00:00 2001 From: Charles Le Borgne Date: Wed, 19 Jan 2022 18:06:53 +0000 Subject: [PATCH 54/54] Add comments to JNI interface Signed-off-by: Charles Le Borgne --- test/common/integration/quic_test_server_interface.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/common/integration/quic_test_server_interface.h b/test/common/integration/quic_test_server_interface.h index decb3e3d4d..2691caff24 100644 --- a/test/common/integration/quic_test_server_interface.h +++ b/test/common/integration/quic_test_server_interface.h @@ -8,10 +8,21 @@ extern "C" { // functions #endif +/** + * Starts the server. Can only have one server active per JVM. This is blocking until the port can + * start accepting requests. + */ void start_server(); +/** + * Shutdowns the server. Can be restarted later. This is blocking until the server has freed all + * resources. + */ void shutdown_server(); +/** + * Returns the port that got attributed. Can only be called once the server has been started. + */ int get_server_port(); #ifdef __cplusplus