forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_protocol_integration.h
162 lines (143 loc) · 6.89 KB
/
http_protocol_integration.h
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
#pragma once
#include "test/integration/http_integration.h"
#include "test/test_common/utility.h"
#include "gtest/gtest.h"
namespace Envoy {
struct HttpProtocolTestParams {
Network::Address::IpVersion version;
Http::CodecType downstream_protocol;
Http::CodecType upstream_protocol;
Http1ParserImpl http1_implementation;
Http2Impl http2_implementation;
bool defer_processing_backedup_streams;
bool use_universal_header_validator;
};
absl::string_view http2ImplementationToString(Http2Impl impl);
// Allows easy testing of Envoy code for HTTP/HTTP2 upstream/downstream.
//
// Usage:
//
// using MyTest = HttpProtocolIntegrationTest;
//
// INSTANTIATE_TEST_SUITE_P(Protocols, MyTest,
// testing::ValuesIn(HttpProtocolIntegrationTest::getProtocolTestParams()),
// HttpProtocolIntegrationTest::protocolTestParamsToString);
//
//
// TEST_P(MyTest, TestInstance) {
// ....
// }
// TODO(#20996) consider switching to SimulatedTimeSystem instead of using real time.
class HttpProtocolIntegrationTest : public testing::TestWithParam<HttpProtocolTestParams>,
public HttpIntegrationTest {
public:
// By default returns 8 combinations of
// [HTTP upstream / HTTP downstream] x [Ipv4, IPv6]
// [HTTP upstream / HTTP2 downstream] x [IPv4, Ipv6]
// [HTTP2 upstream / HTTP downstream] x [Ipv4, IPv6]
// [HTTP2 upstream / HTTP2 downstream] x [IPv4, Ipv6]
//
// Upstream and downstream protocols may be changed via the input vectors.
// Address combinations are propagated from TestEnvironment::getIpVersionsForTest()
static std::vector<HttpProtocolTestParams>
getProtocolTestParams(const std::vector<Http::CodecType>& downstream_protocols =
{
Http::CodecType::HTTP1,
Http::CodecType::HTTP2,
Http::CodecType::HTTP3,
},
const std::vector<Http::CodecType>& upstream_protocols = {
Http::CodecType::HTTP1,
Http::CodecType::HTTP2,
Http::CodecType::HTTP3,
});
static std::vector<HttpProtocolTestParams> getProtocolTestParamsWithoutHTTP3() {
return getProtocolTestParams(
/*downstream_protocols = */ {Http::CodecType::HTTP1, Http::CodecType::HTTP2},
/*upstream_protocols = */ {Http::CodecType::HTTP1, Http::CodecType::HTTP2});
}
// Allows pretty printed test names of the form
// FooTestCase.BarInstance/IPv4_Http2Downstream_HttpUpstream
static std::string
protocolTestParamsToString(const ::testing::TestParamInfo<HttpProtocolTestParams>& p);
HttpProtocolIntegrationTest()
: HttpProtocolIntegrationTest(ConfigHelper::httpProxyConfig(
/*downstream_is_quic=*/GetParam().downstream_protocol == Http::CodecType::HTTP3)) {}
HttpProtocolIntegrationTest(const std::string config)
: HttpIntegrationTest(GetParam().downstream_protocol, GetParam().version, config),
use_universal_header_validator_(GetParam().use_universal_header_validator) {
setupHttp1ImplOverrides(GetParam().http1_implementation);
setupHttp2ImplOverrides(GetParam().http2_implementation);
config_helper_.addRuntimeOverride(Runtime::defer_processing_backedup_streams,
GetParam().defer_processing_backedup_streams ? "true"
: "false");
config_helper_.addRuntimeOverride("envoy.reloadable_features.enable_universal_header_validator",
GetParam().use_universal_header_validator ? "true" : "false");
}
void SetUp() override {
setDownstreamProtocol(GetParam().downstream_protocol);
setUpstreamProtocol(GetParam().upstream_protocol);
}
void setDownstreamOverrideStreamErrorOnInvalidHttpMessage();
void setUpstreamOverrideStreamErrorOnInvalidHttpMessage();
protected:
const bool use_universal_header_validator_{false};
};
class UpstreamDownstreamIntegrationTest
: public testing::TestWithParam<std::tuple<HttpProtocolTestParams, bool>>,
public HttpIntegrationTest {
public:
UpstreamDownstreamIntegrationTest()
: HttpIntegrationTest(
std::get<0>(GetParam()).downstream_protocol, std::get<0>(GetParam()).version,
ConfigHelper::httpProxyConfig(std::get<0>(GetParam()).downstream_protocol ==
Http::CodecType::HTTP3)) {
setupHttp1ImplOverrides(std::get<0>(GetParam()).http1_implementation);
setupHttp2ImplOverrides(std::get<0>(GetParam()).http2_implementation);
config_helper_.addRuntimeOverride(
Runtime::defer_processing_backedup_streams,
std::get<0>(GetParam()).defer_processing_backedup_streams ? "true" : "false");
config_helper_.addRuntimeOverride(
"envoy.reloadable_features.enable_universal_header_validator",
std::get<0>(GetParam()).use_universal_header_validator ? "true" : "false");
}
static std::string testParamsToString(
const ::testing::TestParamInfo<std::tuple<HttpProtocolTestParams, bool>>& params) {
return fmt::format(
"{}_{}",
HttpProtocolIntegrationTest::protocolTestParamsToString(
::testing::TestParamInfo<HttpProtocolTestParams>(std::get<0>(params.param), 0)),
std::get<1>(params.param) ? "DownstreamFilter" : "UpstreamFilter");
}
static std::vector<std::tuple<HttpProtocolTestParams, bool>>
getDefaultTestParams(const std::vector<Http::CodecType>& downstream_protocols =
{
Http::CodecType::HTTP1,
Http::CodecType::HTTP2,
Http::CodecType::HTTP3,
},
const std::vector<Http::CodecType>& upstream_protocols = {
Http::CodecType::HTTP1,
Http::CodecType::HTTP2,
Http::CodecType::HTTP3,
}) {
std::vector<std::tuple<HttpProtocolTestParams, bool>> ret;
std::vector<HttpProtocolTestParams> protocol_defaults =
HttpProtocolIntegrationTest::getProtocolTestParams(downstream_protocols,
upstream_protocols);
const std::vector<bool> testing_downstream_filter_values{true, false};
for (auto& param : protocol_defaults) {
for (bool testing_downstream_filter : testing_downstream_filter_values) {
ret.push_back(std::make_tuple(param, testing_downstream_filter));
}
}
return ret;
}
void SetUp() override {
setDownstreamProtocol(std::get<0>(GetParam()).downstream_protocol);
setUpstreamProtocol(std::get<0>(GetParam()).upstream_protocol);
testing_downstream_filter_ = std::get<1>(GetParam());
}
bool testing_downstream_filter_;
};
} // namespace Envoy