-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add integration tests for static secrets #3910
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
#include <memory> | ||
#include <string> | ||
|
||
#include "common/event/dispatcher_impl.h" | ||
#include "common/network/connection_impl.h" | ||
#include "common/network/utility.h" | ||
#include "common/ssl/context_config_impl.h" | ||
#include "common/ssl/context_manager_impl.h" | ||
|
||
#include "test/integration/http_integration.h" | ||
#include "test/integration/server.h" | ||
#include "test/integration/ssl_utility.h" | ||
#include "test/mocks/init/mocks.h" | ||
#include "test/mocks/runtime/mocks.h" | ||
#include "test/mocks/secret/mocks.h" | ||
#include "test/test_common/network_utility.h" | ||
#include "test/test_common/utility.h" | ||
|
||
#include "absl/strings/match.h" | ||
#include "gmock/gmock.h" | ||
#include "gtest/gtest.h" | ||
#include "integration.h" | ||
#include "utility.h" | ||
|
||
using testing::NiceMock; | ||
using testing::Return; | ||
|
||
namespace Envoy { | ||
namespace Ssl { | ||
|
||
class SdsStaticDownstreamIntegrationTest | ||
: public HttpIntegrationTest, | ||
public testing::TestWithParam<Network::Address::IpVersion> { | ||
public: | ||
SdsStaticDownstreamIntegrationTest() | ||
: HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam()) {} | ||
|
||
void initialize() override { | ||
config_helper_.addConfigModifier([](envoy::config::bootstrap::v2::Bootstrap& bootstrap) { | ||
auto* filter_chain = | ||
bootstrap.mutable_static_resources()->mutable_listeners(0)->mutable_filter_chains(0); | ||
|
||
auto* common_tls_context = filter_chain->mutable_tls_context()->mutable_common_tls_context(); | ||
common_tls_context->add_alpn_protocols("h2"); | ||
common_tls_context->add_alpn_protocols("http/1.1"); | ||
common_tls_context->mutable_deprecated_v1()->set_alt_alpn_protocols("http/1.1"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: do you need this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
auto* validation_context = common_tls_context->mutable_validation_context(); | ||
validation_context->mutable_trusted_ca()->set_filename( | ||
TestEnvironment::runfilesPath("test/config/integration/certs/cacert.pem")); | ||
validation_context->add_verify_certificate_hash( | ||
"E0:F3:C8:CE:5E:2E:A3:05:F0:70:1F:F5:12:E3:6E:2E:" | ||
"97:92:82:84:A2:28:BC:F7:73:32:D3:39:30:A1:B6:FD"); | ||
|
||
common_tls_context->add_tls_certificate_sds_secret_configs()->set_name("server_cert"); | ||
|
||
auto* secret = bootstrap.mutable_static_resources()->add_secrets(); | ||
secret->set_name("server_cert"); | ||
auto* tls_certificate = secret->mutable_tls_certificate(); | ||
tls_certificate->mutable_certificate_chain()->set_filename( | ||
TestEnvironment::runfilesPath("/test/config/integration/certs/servercert.pem")); | ||
tls_certificate->mutable_private_key()->set_filename( | ||
TestEnvironment::runfilesPath("/test/config/integration/certs/serverkey.pem")); | ||
}); | ||
|
||
HttpIntegrationTest::initialize(); | ||
|
||
registerTestServerPorts({"http"}); | ||
|
||
client_ssl_ctx_ = | ||
createClientSslTransportSocketFactory(false, false, context_manager_, secret_manager_); | ||
} | ||
|
||
void TearDown() override { | ||
client_ssl_ctx_.reset(); | ||
cleanupUpstreamAndDownstream(); | ||
fake_upstream_connection_.reset(); | ||
codec_client_.reset(); | ||
} | ||
|
||
Network::ClientConnectionPtr makeSslClientConnection() { | ||
Network::Address::InstanceConstSharedPtr address = getSslAddress(version_, lookupPort("http")); | ||
return dispatcher_->createClientConnection(address, Network::Address::InstanceConstSharedPtr(), | ||
client_ssl_ctx_->createTransportSocket(), nullptr); | ||
} | ||
|
||
private: | ||
Runtime::MockLoader runtime_; | ||
Ssl::ContextManagerImpl context_manager_{runtime_}; | ||
Secret::MockSecretManager secret_manager_; | ||
|
||
Network::TransportSocketFactoryPtr client_ssl_ctx_; | ||
}; | ||
|
||
INSTANTIATE_TEST_CASE_P(IpVersions, SdsStaticDownstreamIntegrationTest, | ||
testing::ValuesIn(TestEnvironment::getIpVersionsForTest()), | ||
TestUtility::ipTestParamsToString); | ||
|
||
TEST_P(SdsStaticDownstreamIntegrationTest, RouterRequestAndResponseWithGiantBodyBuffer) { | ||
ConnectionCreationFunction creator = [&]() -> Network::ClientConnectionPtr { | ||
return makeSslClientConnection(); | ||
}; | ||
testRouterRequestAndResponseWithBody(16 * 1024 * 1024, 16 * 1024 * 1024, false, &creator); | ||
} | ||
|
||
class SdsStaticUpstreamIntegrationTest | ||
: public HttpIntegrationTest, | ||
public testing::TestWithParam<Network::Address::IpVersion> { | ||
public: | ||
SdsStaticUpstreamIntegrationTest() | ||
: HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam()) {} | ||
|
||
void initialize() override { | ||
config_helper_.addConfigModifier([](envoy::config::bootstrap::v2::Bootstrap& bootstrap) { | ||
auto* static_resources = bootstrap.mutable_static_resources(); | ||
auto* cluster = static_resources->mutable_clusters(0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: you don't need this line, can be combined with the line below without variable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
cluster->mutable_tls_context() | ||
->mutable_common_tls_context() | ||
->add_tls_certificate_sds_secret_configs() | ||
->set_name("client_cert"); | ||
|
||
auto* secret = static_resources->add_secrets(); | ||
secret->set_name("client_cert"); | ||
auto* tls_certificate = secret->mutable_tls_certificate(); | ||
tls_certificate->mutable_certificate_chain()->set_filename( | ||
TestEnvironment::runfilesPath("/test/config/integration/certs/clientcert.pem")); | ||
tls_certificate->mutable_private_key()->set_filename( | ||
TestEnvironment::runfilesPath("/test/config/integration/certs/clientkey.pem")); | ||
}); | ||
|
||
HttpIntegrationTest::initialize(); | ||
|
||
registerTestServerPorts({"http"}); | ||
} | ||
|
||
void TearDown() override { | ||
cleanupUpstreamAndDownstream(); | ||
fake_upstream_connection_.reset(); | ||
codec_client_.reset(); | ||
|
||
test_server_.reset(); | ||
fake_upstreams_.clear(); | ||
} | ||
|
||
void createUpstreams() override { | ||
fake_upstreams_.emplace_back( | ||
new FakeUpstream(createUpstreamSslContext(), 0, FakeHttpConnection::Type::HTTP1, version_)); | ||
} | ||
|
||
Network::TransportSocketFactoryPtr createUpstreamSslContext() { | ||
envoy::api::v2::auth::DownstreamTlsContext tls_context; | ||
auto* common_tls_context = tls_context.mutable_common_tls_context(); | ||
common_tls_context->add_alpn_protocols("h2"); | ||
common_tls_context->add_alpn_protocols("http/1.1"); | ||
common_tls_context->mutable_deprecated_v1()->set_alt_alpn_protocols("http/1.1"); | ||
|
||
auto* validation_context = common_tls_context->mutable_validation_context(); | ||
validation_context->mutable_trusted_ca()->set_filename( | ||
TestEnvironment::runfilesPath("test/config/integration/certs/cacert.pem")); | ||
validation_context->add_verify_certificate_hash( | ||
"E0:F3:C8:CE:5E:2E:A3:05:F0:70:1F:F5:12:E3:6E:2E:" | ||
"97:92:82:84:A2:28:BC:F7:73:32:D3:39:30:A1:B6:FD"); | ||
|
||
auto* tls_certificate = common_tls_context->add_tls_certificates(); | ||
tls_certificate->mutable_certificate_chain()->set_filename( | ||
TestEnvironment::runfilesPath("/test/config/integration/certs/servercert.pem")); | ||
tls_certificate->mutable_private_key()->set_filename( | ||
TestEnvironment::runfilesPath("/test/config/integration/certs/serverkey.pem")); | ||
|
||
Ssl::ServerContextConfigImpl cfg(tls_context, secret_manager_); | ||
|
||
static Stats::Scope* upstream_stats_store = new Stats::TestIsolatedStoreImpl(); | ||
return std::make_unique<Ssl::ServerSslSocketFactory>( | ||
cfg, context_manager_, *upstream_stats_store, std::vector<std::string>{}); | ||
} | ||
|
||
private: | ||
Runtime::MockLoader runtime_; | ||
Ssl::ContextManagerImpl context_manager_{runtime_}; | ||
Secret::MockSecretManager secret_manager_; | ||
}; | ||
|
||
INSTANTIATE_TEST_CASE_P(IpVersions, SdsStaticUpstreamIntegrationTest, | ||
testing::ValuesIn(TestEnvironment::getIpVersionsForTest()), | ||
TestUtility::ipTestParamsToString); | ||
|
||
TEST_P(SdsStaticUpstreamIntegrationTest, RouterRequestAndResponseWithGiantBodyBuffer) { | ||
testRouterRequestAndResponseWithBody(16 * 1024 * 1024, 16 * 1024 * 1024, false, nullptr); | ||
} | ||
|
||
} // namespace Ssl | ||
} // namespace Envoy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you don't need filter_chain, can be combined with the line below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done