forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xds_integration_test.cc
130 lines (107 loc) · 5.45 KB
/
xds_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
#include "envoy/config/bootstrap/v3/bootstrap.pb.h"
#include "envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.pb.h"
#include "test/integration/http_integration.h"
#include "test/integration/http_protocol_integration.h"
#include "test/test_common/environment.h"
#include "test/test_common/utility.h"
#include "gtest/gtest.h"
namespace Envoy {
namespace {
using testing::HasSubstr;
// This is a minimal litmus test for the v2 xDS APIs.
class XdsIntegrationTest : public testing::TestWithParam<Network::Address::IpVersion>,
public HttpIntegrationTest {
public:
XdsIntegrationTest() : HttpIntegrationTest(Http::CodecClient::Type::HTTP2, GetParam()) {
setUpstreamProtocol(FakeHttpConnection::Type::HTTP2);
}
void createEnvoy() override {
createEnvoyServer({
"test/config/integration/server_xds.bootstrap.yaml",
"test/config/integration/server_xds.cds.yaml",
"test/config/integration/server_xds.eds.yaml",
"test/config/integration/server_xds.lds.yaml",
"test/config/integration/server_xds.rds.yaml",
});
}
void createEnvoyServer(const ApiFilesystemConfig& api_filesystem_config) {
registerPort("upstream_0", fake_upstreams_.back()->localAddress()->ip()->port());
createApiTestServer(api_filesystem_config, {"http"}, false, false, false);
EXPECT_EQ(1, test_server_->counter("listener_manager.lds.update_success")->value());
EXPECT_EQ(1, test_server_->counter("http.router.rds.route_config_0.update_success")->value());
EXPECT_EQ(1, test_server_->counter("cluster_manager.cds.update_success")->value());
EXPECT_EQ(1, test_server_->counter("cluster.cluster_1.update_success")->value());
}
};
INSTANTIATE_TEST_SUITE_P(IpVersions, XdsIntegrationTest,
testing::ValuesIn(TestEnvironment::getIpVersionsForTest()),
TestUtility::ipTestParamsToString);
TEST_P(XdsIntegrationTest, RouterRequestAndResponseWithBodyNoBuffer) {
testRouterRequestAndResponseWithBody(1024, 512, false);
}
class XdsIntegrationTestTypedStruct : public XdsIntegrationTest {
public:
XdsIntegrationTestTypedStruct() = default;
void createEnvoy() override {
createEnvoyServer({
"test/config/integration/server_xds.bootstrap.yaml",
"test/config/integration/server_xds.cds.yaml",
"test/config/integration/server_xds.eds.yaml",
"test/config/integration/server_xds.lds.typed_struct.yaml",
"test/config/integration/server_xds.rds.yaml",
});
}
};
INSTANTIATE_TEST_SUITE_P(IpVersions, XdsIntegrationTestTypedStruct,
testing::ValuesIn(TestEnvironment::getIpVersionsForTest()),
TestUtility::ipTestParamsToString);
TEST_P(XdsIntegrationTestTypedStruct, RouterRequestAndResponseWithBodyNoBuffer) {
testRouterRequestAndResponseWithBody(1024, 512, false);
}
using LdsIntegrationTest = HttpProtocolIntegrationTest;
INSTANTIATE_TEST_SUITE_P(Protocols, LdsIntegrationTest,
testing::ValuesIn(HttpProtocolIntegrationTest::getProtocolTestParams(
{Http::CodecClient::Type::HTTP1}, {FakeHttpConnection::Type::HTTP1})),
HttpProtocolIntegrationTest::protocolTestParamsToString);
// Sample test making sure our config framework correctly reloads listeners.
TEST_P(LdsIntegrationTest, ReloadConfig) {
autonomous_upstream_ = true;
initialize();
// Given we're using LDS in this test, initialize() will not complete until
// the initial LDS file has loaded.
EXPECT_EQ(1, test_server_->counter("listener_manager.lds.update_success")->value());
fake_upstreams_[0]->set_allow_unexpected_disconnects(true);
// HTTP 1.0 is disabled by default.
std::string response;
sendRawHttpAndWaitForResponse(lookupPort("http"), "GET / HTTP/1.0\r\n\r\n", &response, true);
EXPECT_TRUE(response.find("HTTP/1.1 426 Upgrade Required\r\n") == 0);
// Create a new config with HTTP/1.0 proxying.
ConfigHelper new_config_helper(version_, *api_,
MessageUtil::getJsonStringFromMessage(config_helper_.bootstrap()));
new_config_helper.addConfigModifier(
[&](envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
hcm) {
hcm.mutable_http_protocol_options()->set_accept_http_10(true);
hcm.mutable_http_protocol_options()->set_default_host_for_http_10("default.com");
});
// Create an LDS response with the new config, and reload config.
new_config_helper.setLds("1");
test_server_->waitForCounterGe("listener_manager.lds.update_success", 2);
// HTTP 1.0 should now be enabled.
std::string response2;
sendRawHttpAndWaitForResponse(lookupPort("http"), "GET / HTTP/1.0\r\n\r\n", &response2, false);
EXPECT_THAT(response2, HasSubstr("HTTP/1.0 200 OK\r\n"));
}
// Sample test making sure our config framework informs on listener failure.
TEST_P(LdsIntegrationTest, FailConfigLoad) {
config_helper_.addConfigModifier([&](envoy::config::bootstrap::v3::Bootstrap& bootstrap) -> void {
auto* listener = bootstrap.mutable_static_resources()->mutable_listeners(0);
auto* filter_chain = listener->mutable_filter_chains(0);
filter_chain->mutable_filters(0)->clear_typed_config();
filter_chain->mutable_filters(0)->set_name("grewgragra");
});
EXPECT_DEATH_LOG_TO_STDERR(initialize(),
"Didn't find a registered implementation for name: 'grewgragra'");
}
} // namespace
} // namespace Envoy