Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 3 deletions test/integration/alpn_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ class AlpnIntegrationTest : public testing::TestWithParam<Network::Address::IpVe
}
void createUpstreams() override {
for (uint32_t i = 0; i < fake_upstreams_count_; ++i) {
setUpstreamProtocol(protocols_[i]);
Network::TransportSocketFactoryPtr factory = createUpstreamTlsContext();
auto endpoint = upstream_address_fn_(i);
auto config = upstreamConfig();
config.upstream_protocol_ = protocols_[i];
Network::TransportSocketFactoryPtr factory = createUpstreamTlsContext(config);
auto endpoint = upstream_address_fn_(i);
fake_upstreams_.emplace_back(new AutonomousUpstream(std::move(factory), endpoint, config,
autonomous_allow_incomplete_streams_));
}
Expand Down
12 changes: 7 additions & 5 deletions test/integration/base_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ void BaseIntegrationTest::initialize() {
createEnvoy();
}

Network::TransportSocketFactoryPtr BaseIntegrationTest::createUpstreamTlsContext() {
Network::TransportSocketFactoryPtr
BaseIntegrationTest::createUpstreamTlsContext(const FakeUpstreamConfig& upstream_config) {
envoy::extensions::transport_sockets::tls::v3::DownstreamTlsContext tls_context;
const std::string yaml = absl::StrFormat(
R"EOF(
Expand All @@ -120,12 +121,12 @@ Network::TransportSocketFactoryPtr BaseIntegrationTest::createUpstreamTlsContext
TestEnvironment::runfilesPath("test/config/integration/certs/upstreamkey.pem"),
TestEnvironment::runfilesPath("test/config/integration/certs/cacert.pem"));
TestUtility::loadFromYaml(yaml, tls_context);
if (upstream_config_.upstream_protocol_ == FakeHttpConnection::Type::HTTP2) {
if (upstream_config.upstream_protocol_ == FakeHttpConnection::Type::HTTP2) {
tls_context.mutable_common_tls_context()->add_alpn_protocols("h2");
} else if (upstream_config_.upstream_protocol_ == FakeHttpConnection::Type::HTTP1) {
} else if (upstream_config.upstream_protocol_ == FakeHttpConnection::Type::HTTP1) {
tls_context.mutable_common_tls_context()->add_alpn_protocols("http/1.1");
}
if (upstream_config_.upstream_protocol_ != FakeHttpConnection::Type::HTTP3) {
if (upstream_config.upstream_protocol_ != FakeHttpConnection::Type::HTTP3) {
auto cfg = std::make_unique<Extensions::TransportSockets::Tls::ServerContextConfigImpl>(
tls_context, factory_context_);
static Stats::Scope* upstream_stats_store = new Stats::IsolatedStoreImpl();
Expand All @@ -146,7 +147,8 @@ Network::TransportSocketFactoryPtr BaseIntegrationTest::createUpstreamTlsContext
void BaseIntegrationTest::createUpstreams() {
for (uint32_t i = 0; i < fake_upstreams_count_; ++i) {
Network::TransportSocketFactoryPtr factory =
upstream_tls_ ? createUpstreamTlsContext() : Network::Test::createRawBufferSocketFactory();
upstream_tls_ ? createUpstreamTlsContext(upstreamConfig())
: Network::Test::createRawBufferSocketFactory();
auto endpoint = upstream_address_fn_(i);
if (autonomous_upstream_) {
fake_upstreams_.emplace_back(new AutonomousUpstream(
Expand Down
20 changes: 13 additions & 7 deletions test/integration/base_integration_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,24 @@ class BaseIntegrationTest : protected Logger::Loggable<Logger::Id::testing> {
*dispatcher_, std::move(transport_socket));
}

// Add a fake upstream bound to INADDR_ANY and there is no specified port.
FakeUpstream& addFakeUpstream(FakeHttpConnection::Type type) {
FakeUpstreamConfig configWithType(FakeHttpConnection::Type type) const {
FakeUpstreamConfig config = upstream_config_;
config.upstream_protocol_ = type;
if (type != FakeHttpConnection::Type::HTTP3) {
config.udp_fake_upstream_ = absl::nullopt;
}
return config;
}

FakeUpstream& addFakeUpstream(FakeHttpConnection::Type type) {
auto config = configWithType(type);
fake_upstreams_.emplace_back(std::make_unique<FakeUpstream>(0, version_, config));
return *fake_upstreams_.back();
}

FakeUpstream& addFakeUpstream(Network::TransportSocketFactoryPtr&& transport_socket_factory,
FakeHttpConnection::Type type) {
FakeUpstreamConfig config = upstream_config_;
config.upstream_protocol_ = type;
auto config = configWithType(type);
fake_upstreams_.emplace_back(
std::make_unique<FakeUpstream>(std::move(transport_socket_factory), 0, version_, config));
return *fake_upstreams_.back();
Expand Down Expand Up @@ -394,7 +401,8 @@ class BaseIntegrationTest : protected Logger::Loggable<Logger::Id::testing> {
bool use_lds_{true}; // Use the integration framework's LDS set up.
bool upstream_tls_{false};

Network::TransportSocketFactoryPtr createUpstreamTlsContext();
Network::TransportSocketFactoryPtr
createUpstreamTlsContext(const FakeUpstreamConfig& upstream_config);
testing::NiceMock<Server::Configuration::MockTransportSocketFactoryContext> factory_context_;
Extensions::TransportSockets::Tls::ContextManagerImpl context_manager_{timeSystem()};

Expand Down Expand Up @@ -437,8 +445,6 @@ class BaseIntegrationTest : protected Logger::Loggable<Logger::Id::testing> {
bool v2_bootstrap_{false};

private:
friend class MixedUpstreamIntegrationTest;

// Configuration for the fake upstream.
FakeUpstreamConfig upstream_config_{time_system_};
// True if initialized() has been called.
Expand Down
31 changes: 10 additions & 21 deletions test/integration/fake_upstream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -448,18 +448,17 @@ FakeUpstream::FakeUpstream(const std::string& uds_path, const FakeUpstreamConfig
: FakeUpstream(Network::Test::createRawBufferSocketFactory(),
Network::SocketPtr{new Network::UdsListenSocket(
std::make_shared<Network::Address::PipeInstance>(uds_path))},
config) {
ENVOY_LOG(info, "starting fake server on unix domain socket {}", uds_path);
}
config) {}

@antoniovicente antoniovicente May 12, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The coverage run seems to have crashed around this line. Could you take a look?

fastbuild/bin/test/integration/uds_integration_test.runfiles/envoy/test/integration/uds_integration_test --gmock_default_mock_behavior=2 '-l trace'
2021-05-12T20:59:56.9789337Z Turning perftools heap leak checking off
2021-05-12T20:59:56.9790321Z [==========] Running 28 tests from 3 test suites.
2021-05-12T20:59:56.9791307Z [----------] Global test environment set-up.
2021-05-12T20:59:56.9792257Z [----------] 10 tests from TestParameters/UdsUpstreamIntegrationTest
2021-05-12T20:59:56.9793085Z [ RUN      ] TestParameters/UdsUpstreamIntegrationTest.RouterRequestAndResponseWithBodyNoBuffer/0
2021-05-12T20:59:56.9794618Z [2021-05-12 20:59:56.357][5547][debug][runtime] [source/common/runtime/runtime_features.cc:31] Unable to use runtime singleton for feature envoy.http.headermap.lazy_map_min_size
2021-05-12T20:59:56.9796679Z [2021-05-12 20:59:56.358][5547][debug][runtime] [source/common/runtime/runtime_features.cc:20] Unable to use runtime singleton for feature envoy.reloadable_features.header_map_correctly_coalesce_cookies
2021-05-12T20:59:56.9798389Z [2021-05-12 20:59:56.362][5547][debug][runtime] [source/common/runtime/runtime_features.cc:31] Unable to use runtime singleton for feature envoy.http.headermap.lazy_map_min_size
2021-05-12T20:59:56.9800154Z [2021-05-12 20:59:56.362][5547][debug][runtime] [source/common/runtime/runtime_features.cc:20] Unable to use runtime singleton for feature envoy.reloadable_features.header_map_correctly_coalesce_cookies
2021-05-12T20:59:56.9801933Z [2021-05-12 20:59:56.363][5547][critical][backtrace] [bazel-out/k8-fastbuild/bin/source/server/_virtual_includes/backtrace_lib/server/backtrace.h:104] Caught Segmentation fault, suspect faulting address 0x0
2021-05-12T20:59:56.9802970Z #0 Envoy::SignalAction::sigHandler() [0x7fcae2c35c94]
2021-05-12T20:59:56.9803623Z #1 __restore_rt [0x7fcad1b20980]
2021-05-12T20:59:56.9804227Z #2 Envoy::FakeUpstream::FakeUpstream() [0x7fcb3f7e953e]
2021-05-12T20:59:56.9804849Z #3 [0x46eab6]
2021-05-12T20:59:56.9805354Z #4 [0x41c56e]
2021-05-12T20:59:56.9805902Z #5 Envoy::BaseIntegrationTest::initialize() [0x7fcb400ebd0e]
2021-05-12T20:59:56.9806574Z #6 Envoy::HttpIntegrationTest::initialize() [0x7fcb406260f5]
2021-05-12T20:59:56.9848246Z #7 Envoy::HttpIntegrationTest::testRouterRequestAndResponseWithBody() [0x7fcb40629d0a]
2021-05-12T20:59:56.9849230Z #8 [0x41180c]
2021-05-12T20:59:56.9849858Z #9 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x7fcad299b146]
2021-05-12T20:59:56.9850585Z #10 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x7fcad297fb01]
2021-05-12T20:59:56.9851228Z #11 testing::Test::Run() [0x7fcad2967442]
2021-05-12T20:59:56.9851778Z #12 testing::TestInfo::Run() [0x7fcad2967f58]
2021-05-12T20:59:56.9852278Z #13 testing::TestSuite::Run() [0x7fcad2968839]
2021-05-12T20:59:56.9852852Z #14 testing::internal::UnitTestImpl::RunAllTests() [0x7fcad29765e6]
2021-05-12T20:59:56.9853518Z #15 testing::internal::HandleSehExceptionsInMethodIfSupported<>() [0x7fcad29a2a56]
2021-05-12T20:59:56.9854200Z #16 testing::internal::HandleExceptionsInMethodIfSupported<>() [0x7fcad2982c51]
2021-05-12T20:59:56.9854804Z #17 testing::UnitTest::Run() [0x7fcad2976030]
2021-05-12T20:59:56.9855281Z #18 RUN_ALL_TESTS() [0x7fcaefb86885]
2021-05-12T20:59:56.9855782Z #19 Envoy::TestRunner::RunTests() [0x7fcaefb85abf]
2021-05-12T20:59:56.9856380Z #20 main [0x7fcaefb19b47]
2021-05-12T20:59:56.9857117Z #21 __libc_start_main [0x7fcad173ebf7]
2021-05-12T20:59:56.9857898Z external/bazel_tools/tools/test/collect_coverage.sh: line 131:  5547 Segmentation fault      (core dumped) "$@"


static Network::SocketPtr
makeTcpListenSocket(const Network::Address::InstanceConstSharedPtr& address) {
return std::make_unique<Network::TcpListenSocket>(address, nullptr, true);
}

static Network::SocketPtr makeTcpListenSocket(uint32_t port, Network::Address::IpVersion version) {
return makeTcpListenSocket(Network::Utility::parseInternetAddress(
Network::Test::getLoopbackAddressString(version), port));
static Network::Address::InstanceConstSharedPtr makeAddress(uint32_t port,
Network::Address::IpVersion version) {
return Network::Utility::parseInternetAddress(Network::Test::getLoopbackAddressString(version),
port);
}

static Network::SocketPtr
Expand All @@ -482,31 +481,19 @@ makeListenSocket(const FakeUpstreamConfig& config,
FakeUpstream::FakeUpstream(uint32_t port, Network::Address::IpVersion version,
const FakeUpstreamConfig& config)
: FakeUpstream(Network::Test::createRawBufferSocketFactory(),
makeTcpListenSocket(port, version), config) {
ASSERT(!config.udp_fake_upstream_.has_value());
ENVOY_LOG(info, "starting fake server on port {}. Address version is {}",
localAddress()->ip()->port(), Network::Test::addressVersionAsString(version));
}
makeListenSocket(config, makeAddress(port, version)), config) {}

FakeUpstream::FakeUpstream(Network::TransportSocketFactoryPtr&& transport_socket_factory,
const Network::Address::InstanceConstSharedPtr& address,
const FakeUpstreamConfig& config)
: FakeUpstream(std::move(transport_socket_factory), makeListenSocket(config, address), config) {
ENVOY_LOG(info, "starting fake server on socket {}:{}. Address version is {}. UDP={}",
address->ip()->addressAsString(), address->ip()->port(),
Network::Test::addressVersionAsString(address->ip()->version()),
config.udp_fake_upstream_.has_value());
}

FakeUpstream::FakeUpstream(Network::TransportSocketFactoryPtr&& transport_socket_factory,
uint32_t port, Network::Address::IpVersion version,
const FakeUpstreamConfig& config)
: FakeUpstream(std::move(transport_socket_factory), makeTcpListenSocket(port, version),
config) {
ASSERT(!config.udp_fake_upstream_.has_value());
ENVOY_LOG(info, "starting fake server on port {}. Address version is {}",
localAddress()->ip()->port(), Network::Test::addressVersionAsString(version));
}
: FakeUpstream(std::move(transport_socket_factory),
makeListenSocket(config, makeAddress(port, version)), config) {}

FakeUpstream::FakeUpstream(Network::TransportSocketFactoryPtr&& transport_socket_factory,
Network::SocketPtr&& listen_socket, const FakeUpstreamConfig& config)
Expand All @@ -520,6 +507,8 @@ FakeUpstream::FakeUpstream(Network::TransportSocketFactoryPtr&& transport_socket
read_disable_on_new_connection_(true), enable_half_close_(config.enable_half_close_),
listener_(*this, http_type_ == FakeHttpConnection::Type::HTTP3),
filter_chain_(Network::Test::createEmptyFilterChain(std::move(transport_socket_factory))) {
ENVOY_LOG(info, "starting fake server at {}. UDP={} codec={}", localAddress()->asString(),
config.udp_fake_upstream_.has_value(), FakeHttpConnection::typeToString(http_type_));
if (config.udp_fake_upstream_.has_value() &&
config.udp_fake_upstream_->max_rx_datagram_size_.has_value()) {
listener_.udp_listener_config_.config_.mutable_downstream_socket_config()
Expand Down
11 changes: 11 additions & 0 deletions test/integration/fake_upstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,17 @@ class FakeConnectionBase : public Logger::Loggable<Logger::Id::testing> {
class FakeHttpConnection : public Http::ServerConnectionCallbacks, public FakeConnectionBase {
public:
enum class Type { HTTP1, HTTP2, HTTP3 };
static absl::string_view typeToString(Type type) {
switch (type) {
case Type::HTTP1:
return "http1";
case Type::HTTP2:
return "http2";
case Type::HTTP3:
return "http3";
}
return "invalid";
}

FakeHttpConnection(FakeUpstream& fake_upstream, SharedConnectionWrapper& shared_connection,
Type type, Event::TestTimeSystem& time_system, uint32_t max_request_headers_kb,
Expand Down
8 changes: 4 additions & 4 deletions test/integration/hds_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ class HdsIntegrationTest : public Grpc::VersionedGrpcClientIntegrationParamTest,

// Endpoint connections
if (tls_hosts_) {
host_upstream_ =
&addFakeUpstream(HttpIntegrationTest::createUpstreamTlsContext(), http_conn_type_);
host2_upstream_ =
&addFakeUpstream(HttpIntegrationTest::createUpstreamTlsContext(), http_conn_type_);
host_upstream_ = &addFakeUpstream(
HttpIntegrationTest::createUpstreamTlsContext(upstreamConfig()), http_conn_type_);
host2_upstream_ = &addFakeUpstream(
HttpIntegrationTest::createUpstreamTlsContext(upstreamConfig()), http_conn_type_);
} else {
host_upstream_ = &addFakeUpstream(http_conn_type_);
host2_upstream_ = &addFakeUpstream(http_conn_type_);
Expand Down
18 changes: 10 additions & 8 deletions test/integration/multiplexed_upstream_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -610,16 +610,18 @@ class MixedUpstreamIntegrationTest : public Http2UpstreamIntegrationTest {
}
void createUpstreams() override {
ASSERT_EQ(upstreamProtocol(), FakeHttpConnection::Type::HTTP3);
ASSERT_EQ(fake_upstreams_count_, 1);
ASSERT_FALSE(autonomous_upstream_);

if (use_http2_) {
// Generally we always want to set these fields via accessors, which
// changes both the upstreams and Envoy's configuration at the same time.
// In this particular case, we want to change the upstreams without
// touching config, so edit the raw members directly.
upstream_config_.udp_fake_upstream_ = absl::nullopt;
upstream_config_.upstream_protocol_ = FakeHttpConnection::Type::HTTP2;
auto config = configWithType(FakeHttpConnection::Type::HTTP2);
Network::TransportSocketFactoryPtr factory = createUpstreamTlsContext(config);
addFakeUpstream(std::move(factory), FakeHttpConnection::Type::HTTP2);
} else {
auto config = configWithType(FakeHttpConnection::Type::HTTP3);
Network::TransportSocketFactoryPtr factory = createUpstreamTlsContext(config);
addFakeUpstream(std::move(factory), FakeHttpConnection::Type::HTTP3);
}
Http2UpstreamIntegrationTest::createUpstreams();
upstream_config_.upstream_protocol_ = FakeHttpConnection::Type::HTTP3;
}

bool use_http2_{false};
Expand Down
18 changes: 15 additions & 3 deletions test/integration/ssl_utility.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "test/integration/ssl_utility.h"

#include "envoy/extensions/transport_sockets/quic/v3/quic_transport.pb.h"

#include "common/http/utility.h"
#include "common/json/json_loader.h"
#include "common/network/utility.h"
Expand Down Expand Up @@ -96,7 +98,7 @@ createClientSslTransportSocketFactory(const ClientSslTransportOptions& options,
}

Network::TransportSocketFactoryPtr createUpstreamSslContext(ContextManager& context_manager,
Api::Api& api) {
Api::Api& api, bool use_http3) {
envoy::extensions::transport_sockets::tls::v3::DownstreamTlsContext tls_context;
ConfigHelper::initializeTls({}, *tls_context.mutable_common_tls_context());

Expand All @@ -106,8 +108,18 @@ Network::TransportSocketFactoryPtr createUpstreamSslContext(ContextManager& cont
tls_context, mock_factory_ctx);

static Stats::Scope* upstream_stats_store = new Stats::TestIsolatedStoreImpl();
return std::make_unique<Extensions::TransportSockets::Tls::ServerSslSocketFactory>(
std::move(cfg), context_manager, *upstream_stats_store, std::vector<std::string>{});
if (!use_http3) {
return std::make_unique<Extensions::TransportSockets::Tls::ServerSslSocketFactory>(
std::move(cfg), context_manager, *upstream_stats_store, std::vector<std::string>{});
}
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, mock_factory_ctx, server_names);
}

Network::TransportSocketFactoryPtr createFakeUpstreamSslContext(
Expand Down
2 changes: 1 addition & 1 deletion test/integration/ssl_utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ createClientSslTransportSocketFactory(const ClientSslTransportOptions& options,
ContextManager& context_manager, Api::Api& api);

Network::TransportSocketFactoryPtr createUpstreamSslContext(ContextManager& context_manager,
Api::Api& api);
Api::Api& api, bool use_http3 = false);

Network::TransportSocketFactoryPtr
createFakeUpstreamSslContext(const std::string& upstream_cert_name, ContextManager& context_manager,
Expand Down
2 changes: 1 addition & 1 deletion test/integration/tcp_proxy_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ class MysqlIntegrationTest : public TcpProxyIntegrationTest {
void createUpstreams() override {
for (uint32_t i = 0; i < fake_upstreams_count_; ++i) {
Network::TransportSocketFactoryPtr factory =
upstream_tls_ ? createUpstreamTlsContext()
upstream_tls_ ? createUpstreamTlsContext(upstreamConfig())
: Network::Test::createRawBufferSocketFactory();
auto endpoint = upstream_address_fn_(i);
fake_upstreams_.emplace_back(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ name: "tls_socket"
auto endpoint = upstream_address_fn_(i);
if (isTLSUpstream(i)) {
fake_upstreams_.emplace_back(new AutonomousUpstream(
HttpIntegrationTest::createUpstreamTlsContext(), endpoint->ip()->port(),
HttpIntegrationTest::createUpstreamTlsContext(upstreamConfig()), endpoint->ip()->port(),
endpoint->ip()->version(), upstreamConfig(), false));
} else {
fake_upstreams_.emplace_back(new AutonomousUpstream(
Expand Down