forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
header_prefix_integration_test.cc
61 lines (50 loc) · 2.58 KB
/
header_prefix_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
#include "envoy/config/bootstrap/v3/bootstrap.pb.h"
#include "test/integration/http_protocol_integration.h"
#include "test/integration/server.h"
#include "gtest/gtest.h"
namespace Envoy {
// Unfortunately in the Envoy test suite, the headers singleton is initialized
// well before server start-up, so by the time the server has parsed the
// bootstrap proto it's too late to set it.
//
// Instead, set the value early and regression test the bootstrap proto's validation of prefix
// injection.
static const char* custom_prefix_ = "x-custom";
class HeaderPrefixIntegrationTest : public HttpProtocolIntegrationTest {
public:
static void SetUpTestSuite() { // NOLINT(readability-identifier-naming)
ThreadSafeSingleton<Http::PrefixValue>::get().setPrefix(custom_prefix_);
}
};
TEST_P(HeaderPrefixIntegrationTest, CustomHeaderPrefix) {
config_helper_.addConfigModifier([](envoy::config::bootstrap::v3::Bootstrap& bootstrap) {
bootstrap.set_header_prefix("x-custom");
});
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response =
sendRequestAndWaitForResponse(default_request_headers_, 0, default_response_headers_, 0);
EXPECT_TRUE(response->headers().get(
Envoy::Http::LowerCaseString{"x-custom-upstream-service-time"}) != nullptr);
EXPECT_EQ("x-custom-upstream-service-time",
response->headers().EnvoyUpstreamServiceTime()->key().getStringView());
EXPECT_TRUE(upstream_request_->headers().get(
Envoy::Http::LowerCaseString{"x-custom-expected-rq-timeout-ms"}) != nullptr);
EXPECT_EQ("x-custom-expected-rq-timeout-ms",
upstream_request_->headers().EnvoyExpectedRequestTimeoutMs()->key().getStringView());
}
// In this case, the header prefix set in the bootstrap will not match the
// singleton header prefix in SetUpTestSuite, and Envoy will RELEASE_ASSERT on
// start-up.
TEST_P(HeaderPrefixIntegrationTest, FailedCustomHeaderPrefix) {
config_helper_.addConfigModifier([](envoy::config::bootstrap::v3::Bootstrap& bootstrap) {
bootstrap.set_header_prefix("x-custom-but-not-set");
});
EXPECT_DEATH(initialize(), "Attempting to change the header prefix after it has been used!");
}
INSTANTIATE_TEST_SUITE_P(Protocols, HeaderPrefixIntegrationTest,
testing::ValuesIn(HttpProtocolIntegrationTest::getProtocolTestParams(
{Http::CodecClient::Type::HTTP1, Http::CodecClient::Type::HTTP2},
{FakeHttpConnection::Type::HTTP1})),
HttpProtocolIntegrationTest::protocolTestParamsToString);
} // namespace Envoy