Skip to content

Commit

Permalink
mobile: Add support for HTTP1 with TLS in the TestServer (#35992)
Browse files Browse the repository at this point in the history
This is needed for tests that use HTTP1 with TLS.

Risk Level: low (test only)
Testing: n/a
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

Signed-off-by: Fredy Wijaya <[email protected]>
  • Loading branch information
fredyw authored Sep 6, 2024
1 parent 9386d34 commit a4058c3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
13 changes: 10 additions & 3 deletions mobile/test/common/integration/test_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,16 @@ void TestServer::start(TestServerType type, int port) {
break;
case TestServerType::HTTP2_WITH_TLS:
upstream_config_.upstream_protocol_ = Http::CodecType::HTTP2;
factory = createUpstreamTlsContext(factory_context_);
factory = createUpstreamTlsContext(factory_context_, /* add_alpn= */ true);
break;
case TestServerType::HTTP1_WITHOUT_TLS:
upstream_config_.upstream_protocol_ = Http::CodecType::HTTP1;
factory = Network::Test::createRawBufferDownstreamSocketFactory();
break;
case TestServerType::HTTP1_WITH_TLS:
upstream_config_.upstream_protocol_ = Http::CodecType::HTTP1;
factory = createUpstreamTlsContext(factory_context_, /* add_alpn= */ false);
break;
case TestServerType::HTTP_PROXY: {
Server::forceRegisterDefaultListenerManagerFactoryImpl();
Extensions::TransportSockets::RawBuffer::forceRegisterDownstreamRawBufferSocketFactory();
Expand Down Expand Up @@ -327,7 +331,8 @@ Network::DownstreamTransportSocketFactoryPtr TestServer::createQuicUpstreamTlsCo
}

Network::DownstreamTransportSocketFactoryPtr TestServer::createUpstreamTlsContext(
testing::NiceMock<Server::Configuration::MockTransportSocketFactoryContext>& factory_context) {
testing::NiceMock<Server::Configuration::MockTransportSocketFactoryContext>& factory_context,
bool add_alpn) {
envoy::extensions::transport_sockets::tls::v3::DownstreamTlsContext tls_context;
envoy::extensions::transport_sockets::tls::v3::TlsCertificate* certs =
tls_context.mutable_common_tls_context()->add_tls_certificates();
Expand All @@ -338,7 +343,9 @@ Network::DownstreamTransportSocketFactoryPtr TestServer::createUpstreamTlsContex
auto* ctx = tls_context.mutable_common_tls_context()->mutable_validation_context();
ctx->mutable_trusted_ca()->set_filename(
TestEnvironment::runfilesPath("test/config/integration/certs/upstreamcacert.pem"));
tls_context.mutable_common_tls_context()->add_alpn_protocols("h2");
if (add_alpn) {
tls_context.mutable_common_tls_context()->add_alpn_protocols("h2");
}
auto cfg = *Extensions::TransportSockets::Tls::ServerContextConfigImpl::create(
tls_context, factory_context, false);
static auto* upstream_stats_store = new Stats::TestIsolatedStoreImpl();
Expand Down
11 changes: 6 additions & 5 deletions mobile/test/common/integration/test_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ namespace Envoy {

enum class TestServerType : int {
HTTP1_WITHOUT_TLS = 0,
HTTP2_WITH_TLS = 1,
HTTP3 = 2,
HTTP_PROXY = 3,
HTTPS_PROXY = 4,
HTTP1_WITH_TLS = 1,
HTTP2_WITH_TLS = 2,
HTTP3 = 3,
HTTP_PROXY = 4,
HTTPS_PROXY = 5,
};

class TestServer : public ListenerHooks {
Expand Down Expand Up @@ -92,7 +93,7 @@ class TestServer : public ListenerHooks {
testing::NiceMock<Server::Configuration::MockTransportSocketFactoryContext>&);

Network::DownstreamTransportSocketFactoryPtr createUpstreamTlsContext(
testing::NiceMock<Server::Configuration::MockTransportSocketFactoryContext>&);
testing::NiceMock<Server::Configuration::MockTransportSocketFactoryContext>&, bool);
};

} // namespace Envoy
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
public final class HttpProxyTestServerFactory {
/** The supported {@link HttpProxyTestServer} types. */
public static class Type {
public static final int HTTP_PROXY = 3;
public static final int HTTPS_PROXY = 4;
public static final int HTTP_PROXY = 4;
public static final int HTTPS_PROXY = 5;

private Type() {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ public final class HttpTestServerFactory {
/** The supported {@link HttpTestServer} types. */
public static class Type {
public static final int HTTP1_WITHOUT_TLS = 0;
public static final int HTTP2_WITH_TLS = 1;
public static final int HTTP3 = 2;
public static final int HTTP1_WITH_TLS = 1;
public static final int HTTP2_WITH_TLS = 2;
public static final int HTTP3 = 3;

private Type() {}
}
Expand Down

0 comments on commit a4058c3

Please sign in to comment.