forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
header_casing_integration_test.cc
78 lines (59 loc) · 2.86 KB
/
header_casing_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
#include "envoy/config/bootstrap/v3/bootstrap.pb.h"
#include "envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.pb.h"
#include "common/buffer/buffer_impl.h"
#include "test/integration/http_integration.h"
#include "fake_upstream.h"
#include "gtest/gtest.h"
namespace Envoy {
class HeaderCasingIntegrationTest : public testing::TestWithParam<Network::Address::IpVersion>,
public HttpIntegrationTest {
public:
HeaderCasingIntegrationTest() : HttpIntegrationTest(Http::CodecClient::Type::HTTP1, GetParam()) {}
void SetUp() override {
setDownstreamProtocol(Http::CodecClient::Type::HTTP1);
setUpstreamProtocol(FakeHttpConnection::Type::HTTP1);
}
void initialize() override {
config_helper_.addConfigModifier(
[](envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
hcm) {
hcm.mutable_http_protocol_options()
->mutable_header_key_format()
->mutable_proper_case_words();
});
config_helper_.addConfigModifier([](envoy::config::bootstrap::v3::Bootstrap& bootstrap) {
bootstrap.mutable_static_resources()
->mutable_clusters(0)
->mutable_http_protocol_options()
->mutable_header_key_format()
->mutable_proper_case_words();
});
HttpIntegrationTest::initialize();
}
};
INSTANTIATE_TEST_SUITE_P(IpVersions, HeaderCasingIntegrationTest,
testing::ValuesIn(TestEnvironment::getIpVersionsForTest()),
TestUtility::ipTestParamsToString);
TEST_P(HeaderCasingIntegrationTest, VerifyCasedHeaders) {
initialize();
IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("http"));
auto request = "GET / HTTP/1.1\r\nhost: host\r\nmy-header: foo\r\n\r\n";
tcp_client->write(request, false);
Envoy::FakeRawConnectionPtr upstream_connection;
ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(upstream_connection));
// Verify that the upstream request has proper cased headers.
std::string upstream_request;
EXPECT_TRUE(upstream_connection->waitForData(FakeRawConnection::waitForInexactMatch("GET /"),
&upstream_request));
EXPECT_TRUE(absl::StrContains(upstream_request, "My-Header: foo"));
EXPECT_TRUE(absl::StrContains(upstream_request, "Host: host"));
EXPECT_TRUE(absl::StrContains(upstream_request, "Content-Length: 0"));
// Verify that the downstream response has proper cased headers.
auto response =
"HTTP/1.1 503 Service Unavailable\r\ncontent-length: 0\r\nresponse-header: foo\r\n\r\n";
ASSERT_TRUE(upstream_connection->write(response));
// Verify that we're at least one proper cased header.
tcp_client->waitForData("HTTP/1.1 503 Service Unavailable\r\nContent-Length:", true);
tcp_client->close();
}
} // namespace Envoy