forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsds_static_integration_test.cc
169 lines (137 loc) · 6.33 KB
/
sds_static_integration_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include <memory>
#include <string>
#include "envoy/stats/scope.h"
#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/mocks/server/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(), realTime()) {}
void initialize() override {
config_helper_.addConfigModifier([](envoy::config::bootstrap::v2::Bootstrap& bootstrap) {
auto* common_tls_context = bootstrap.mutable_static_resources()
->mutable_listeners(0)
->mutable_filter_chains(0)
->mutable_tls_context()
->mutable_common_tls_context();
common_tls_context->add_alpn_protocols("http/1.1");
common_tls_context->mutable_validation_context_sds_secret_config()->set_name(
"validation_context");
common_tls_context->add_tls_certificate_sds_secret_configs()->set_name("server_cert");
auto* secret = bootstrap.mutable_static_resources()->add_secrets();
secret->set_name("validation_context");
auto* validation_context = secret->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");
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_);
}
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_};
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(), realTime()) {}
void initialize() override {
config_helper_.addConfigModifier([](envoy::config::bootstrap::v2::Bootstrap& bootstrap) {
bootstrap.mutable_static_resources()
->mutable_clusters(0)
->mutable_tls_context()
->mutable_common_tls_context()
->add_tls_certificate_sds_secret_configs()
->set_name("client_cert");
auto* secret = bootstrap.mutable_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(context_manager_), 0,
FakeHttpConnection::Type::HTTP1, version_,
timeSystem()));
}
private:
Runtime::MockLoader runtime_;
Ssl::ContextManagerImpl context_manager_{runtime_};
};
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