Skip to content
Closed
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6e5fca3
Fix url 404 not found error
colibie Sep 7, 2021
51bab1c
Working version of quicTestServer
colibie Sep 7, 2021
15cfb05
remove traces of argc and argv
colibie Sep 7, 2021
91e1af8
[WIP] create quicTestServerTest
colibie Sep 7, 2021
a49baf9
[WIP] quicTestServerTest
colibie Sep 7, 2021
c608e2e
[WIP] checkpoint
colibie Sep 22, 2021
22bc6bb
Merge branch 'main' of github.com:colibie/envoy-mobile into java/quic…
colibie Sep 22, 2021
cec798e
Merge branch 'main' of github.com:colibie/envoy-mobile into java/quic…
colibie Sep 23, 2021
1e98c4d
move submodule to latest commit in main
colibie Sep 23, 2021
8a6208f
added direct response to test engine
colibie Sep 23, 2021
bc01022
Merge branch 'main' of github.com:colibie/envoy-mobile into java/quic…
colibie Sep 29, 2021
189e3e9
WIP
colibie Sep 30, 2021
7511986
[wip]
colibie Oct 4, 2021
2b61716
add JVM test for the QuicTestServer
colibie Oct 4, 2021
75f52ef
wip
colibie Oct 7, 2021
9004b8c
add QuicTestServer and its associated test
colibie Oct 8, 2021
32401c4
Merge branch 'main' of github.com:colibie/envoy-mobile into java/quic…
colibie Oct 8, 2021
4864676
checkout to correct envoy version
colibie Oct 8, 2021
69983dd
Fix thread issue
colibie Oct 11, 2021
0789bec
Fix thread issue
colibie Oct 11, 2021
c6ef82a
nit fixes
colibie Oct 11, 2021
7aca613
add linux jni header and nit changes
colibie Oct 12, 2021
79819e2
add linux jni header and nit changes
colibie Oct 12, 2021
ad9170b
testing
colibie Oct 12, 2021
d09958c
fix PR comments and check test asan build
colibie Oct 12, 2021
4123d56
ci test
colibie Oct 12, 2021
cb3e22b
ci testing
colibie Oct 12, 2021
9836d38
reverting cc_binary changes
colibie Oct 12, 2021
05c30c8
Merge branch 'main' of github.com:colibie/envoy-mobile into java/quic…
colibie Oct 15, 2021
03c2053
pull in updates
colibie Oct 15, 2021
274aae7
fix format issues
colibie Oct 15, 2021
4bc0fd9
potential fix for mac timeouts
colibie Oct 15, 2021
f6e5b72
should fix failures
colibie Oct 15, 2021
34c70be
testonly field added to genrule
colibie Oct 15, 2021
5b6dd43
add binary jnilib to dep
colibie Oct 15, 2021
02fd58f
Kick CI
colibie Oct 15, 2021
701395b
remove redundancies
colibie Oct 15, 2021
f1a9a75
some more cleanup
colibie Oct 18, 2021
3b40d92
Merge remote-tracking branch 'origin' into java/quicTestServer
colibie Oct 18, 2021
1fae837
Kick CI
colibie Oct 19, 2021
71748ef
[WIP] mac not working yet
colibie Oct 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion library/java/org/chromium/net/impl/CronetUrlRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,13 @@ public void onCancel(EnvoyStreamIntel streamIntel) {
} 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(":path", unused -> new ArrayList<>())
Comment thread
colibie marked this conversation as resolved.
Outdated
.add(url.getFile().isEmpty() ? "/" : url.getFile());
headers.computeIfAbsent(":scheme", unused -> new ArrayList<>()).add(url.getProtocol());

boolean hasUserAgent = false;
boolean hasContentType = false;
for (Map.Entry<String, String> header : headersList) {
Expand Down
43 changes: 42 additions & 1 deletion test/common/integration/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@envoy//bazel:envoy_build_system.bzl", "envoy_cc_test", "envoy_package")
load("@envoy//bazel:envoy_build_system.bzl", "envoy_cc_test", "envoy_cc_test_library", "envoy_package")

licenses(["notice"]) # Apache 2

Expand All @@ -19,3 +19,44 @@ envoy_cc_test(
"@envoy//test/server:utility_lib",
],
)

# 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//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",
"@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",
],
}),
)
117 changes: 117 additions & 0 deletions test/common/integration/quic_test_server.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#include "quic_test_server.h"

namespace Envoy {

Network::TransportSocketFactoryPtr QuicTestServer::createUpstreamTlsContext(
testing::NiceMock<Server::Configuration::MockTransportSocketFactoryContext>& 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
BQ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WNAZJ/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");
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<std::string> 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) {
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
Thread::TestThread test_thread;
ProcessWide process_wide;
Thread::MutexBasicLockable lock;
Logger::Context logging_state(spdlog::level::level_enum::err,
Comment thread
colibie marked this conversation as resolved.
"[%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;
Comment thread
colibie marked this conversation as resolved.
Outdated
upstream_config.udp_fake_upstream_ = FakeUpstreamConfig::UdpConfig();

Network::TransportSocketFactoryPtr factory = createUpstreamTlsContext(factory_context_);

int port = 34210;
aupstream_ = std::make_unique<AutonomousUpstream>(std::move(factory), port, version_,
upstream_config, false);

// see upstream address
std::cerr << "Upstream now listening on " << aupstream_->localAddress()->asString() << "\n";
Comment thread
colibie marked this conversation as resolved.
Outdated
}

void QuicTestServer::shutdownQuicTestServer() { aupstream_.reset(); }

int QuicTestServer::getServerPort() { return aupstream_->localAddress()->ip()->port(); }
} // namespace Envoy
40 changes: 40 additions & 0 deletions test/common/integration/quic_test_server.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#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 {
private:
testing::NiceMock<Server::Configuration::MockTransportSocketFactoryContext> factory_context_;
Stats::IsolatedStoreImpl stats_store_;
Event::GlobalTimeSystem time_system_;
Api::ApiPtr api_;
Network::Address::IpVersion version_;
std::unique_ptr<AutonomousUpstream> aupstream_;
Comment thread
colibie marked this conversation as resolved.
Outdated

void setup();
Comment thread
colibie marked this conversation as resolved.
Outdated
Network::TransportSocketFactoryPtr createUpstreamTlsContext(
testing::NiceMock<Server::Configuration::MockTransportSocketFactoryContext>&);

public:
QuicTestServer();

void startQuicTestServer();

void shutdownQuicTestServer();

int getServerPort();
};

} // namespace Envoy
33 changes: 33 additions & 0 deletions test/common/integration/quic_test_server_interface.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "test/common/integration/quic_test_server_interface.h"

// NOLINT(namespace-envoy)

static std::shared_ptr<Envoy::QuicTestServer> strong_quic_test_server_;
Comment thread
colibie marked this conversation as resolved.
static std::weak_ptr<Envoy::QuicTestServer> quic_test_server_;

static std::shared_ptr<Envoy::QuicTestServer> quic_test_server() {
return quic_test_server_.lock();
}

void start_server() {
// start server
Comment thread
colibie marked this conversation as resolved.
Outdated
strong_quic_test_server_ = std::make_shared<Envoy::QuicTestServer>();
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();
}
return -1; // failure
}
19 changes: 19 additions & 0 deletions test/common/integration/quic_test_server_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#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
28 changes: 28 additions & 0 deletions test/common/jni/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
load("@envoy//bazel:envoy_build_system.bzl", "envoy_package")

licenses(["notice"]) # Apache 2

envoy_package()

# 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",
"@local_jdk//:jni_md_header-linux",
],
copts = ["-std=c++17"],
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",
"@envoy_mobile_extra_jni_deps//:extra_jni_dep",
],
)
37 changes: 37 additions & 0 deletions test/common/jni/quic_test_server_jni_interface.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <jni.h>

#include <iostream>

#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"

// NOLINT(namespace-envoy)

// Quic Test ServerJniLibrary

extern "C" JNIEXPORT void JNICALL
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_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_io_envoyproxy_envoymobile_engine_testing_QuicTestServer_nativeShutdownQuicTestServer(
JNIEnv* env, jclass clazz) {
jni_log("[QTS]", "shutting down server");
shutdown_server();
}
44 changes: 44 additions & 0 deletions test/java/io/envoyproxy/envoymobile/engine/testing/BUILD
Original file line number Diff line number Diff line change
@@ -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",
],
)
Loading