forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
header_prefix_integration_test.cc
66 lines (55 loc) · 2.86 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
62
63
64
65
66
#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. We also register a custom header to make sure that registered headers interact well
// with the prefix override.
Http::RegisterCustomInlineHeader<Http::CustomInlineHeaderRegistry::Type::RequestHeaders>
cache_control_handle(Http::CustomHeaders::get().CacheControl);
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_FALSE(response->headers()
.get(Envoy::Http::LowerCaseString{"x-custom-upstream-service-time"})
.empty());
EXPECT_EQ("x-custom-upstream-service-time",
response->headers().EnvoyUpstreamServiceTime()->key().getStringView());
EXPECT_FALSE(upstream_request_->headers()
.get(Envoy::Http::LowerCaseString{"x-custom-expected-rq-timeout-ms"})
.empty());
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::CodecType::HTTP1, Http::CodecType::HTTP2},
{Http::CodecType::HTTP1})),
HttpProtocolIntegrationTest::protocolTestParamsToString);
} // namespace Envoy