forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquic_http_integration_test.cc
597 lines (518 loc) · 26.6 KB
/
quic_http_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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
#include <openssl/x509_vfy.h>
#include <cstddef>
#include "envoy/config/bootstrap/v3/bootstrap.pb.h"
#include "envoy/config/overload/v3/overload.pb.h"
#include "envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.pb.h"
#include "envoy/extensions/transport_sockets/quic/v3/quic_transport.pb.h"
#include "test/config/utility.h"
#include "test/integration/http_integration.h"
#include "test/test_common/test_runtime.h"
#include "test/test_common/utility.h"
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
#endif
#include "quiche/quic/core/http/quic_client_push_promise_index.h"
#include "quiche/quic/core/quic_utils.h"
#include "quiche/quic/test_tools/quic_test_utils.h"
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
#include "common/quic/client_connection_factory_impl.h"
#include "common/quic/envoy_quic_client_session.h"
#include "common/quic/envoy_quic_client_connection.h"
#include "common/quic/envoy_quic_proof_verifier.h"
#include "common/quic/envoy_quic_connection_helper.h"
#include "common/quic/envoy_quic_alarm_factory.h"
#include "common/quic/envoy_quic_packet_writer.h"
#include "common/quic/envoy_quic_utils.h"
#include "common/quic/quic_transport_socket_factory.h"
#include "test/common/quic/test_utils.h"
#include "extensions/transport_sockets/tls/context_config_impl.h"
namespace Envoy {
namespace Quic {
class CodecClientCallbacksForTest : public Http::CodecClientCallbacks {
public:
void onStreamDestroy() override {}
void onStreamReset(Http::StreamResetReason reason) override {
last_stream_reset_reason_ = reason;
}
Http::StreamResetReason last_stream_reset_reason_{Http::StreamResetReason::LocalReset};
};
void updateResource(AtomicFileUpdater& updater, double pressure) {
updater.update(absl::StrCat(pressure));
}
void setUpstreamTimeout(
envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager& hcm) {
auto* route =
hcm.mutable_route_config()->mutable_virtual_hosts(0)->mutable_routes(0)->mutable_route();
uint64_t timeout_ms = PROTOBUF_GET_MS_OR_DEFAULT(*route, timeout, 15000u);
auto* timeout = route->mutable_timeout();
// QUIC stream processing is slow under TSAN. Use larger timeout to prevent
// upstream_response_timeout.
timeout->set_seconds(TSAN_TIMEOUT_FACTOR * timeout_ms / 1000);
}
// A test that sets up its own client connection with customized quic version and connection ID.
class QuicHttpIntegrationTest : public HttpIntegrationTest, public QuicMultiVersionTest {
public:
QuicHttpIntegrationTest()
: HttpIntegrationTest(Http::CodecClient::Type::HTTP3, GetParam().first,
ConfigHelper::quicHttpProxyConfig()),
supported_versions_([]() {
if (GetParam().second == QuicVersionType::GquicQuicCrypto) {
return quic::CurrentSupportedVersionsWithQuicCrypto();
}
bool use_http3 = GetParam().second == QuicVersionType::Iquic;
SetQuicReloadableFlag(quic_disable_version_draft_29, !use_http3);
return quic::CurrentSupportedVersions();
}()),
conn_helper_(*dispatcher_), alarm_factory_(*dispatcher_, *conn_helper_.GetClock()),
injected_resource_filename_1_(TestEnvironment::temporaryPath("injected_resource_1")),
injected_resource_filename_2_(TestEnvironment::temporaryPath("injected_resource_2")),
file_updater_1_(injected_resource_filename_1_),
file_updater_2_(injected_resource_filename_2_) {}
~QuicHttpIntegrationTest() override {
cleanupUpstreamAndDownstream();
// Release the client before destroying |conn_helper_|. No such need once |conn_helper_| is
// moved into a client connection factory in the base test class.
codec_client_.reset();
}
Network::ClientConnectionPtr makeClientConnectionWithOptions(
uint32_t port, const Network::ConnectionSocket::OptionsSharedPtr& options) override {
// Setting socket options is not supported.
ASSERT(!options);
server_addr_ = Network::Utility::resolveUrl(
fmt::format("udp://{}:{}", Network::Test::getLoopbackAddressUrlString(version_), port));
Network::Address::InstanceConstSharedPtr local_addr =
Network::Test::getCanonicalLoopbackAddress(version_);
// Initiate a QUIC connection with the highest supported version. If not
// supported by server, this connection will fail.
// TODO(danzh) Implement retry upon version mismatch and modify test frame work to specify a
// different version set on server side to test that.
auto connection = std::make_unique<EnvoyQuicClientConnection>(
getNextConnectionId(), server_addr_, conn_helper_, alarm_factory_,
quic::ParsedQuicVersionVector{supported_versions_[0]}, local_addr, *dispatcher_, nullptr);
quic_connection_ = connection.get();
// TODO(danzh) defer setting flow control window till getting http3 options. This requires
// QUICHE support to set the session's flow controller after instantiation.
quic_config_.SetInitialStreamFlowControlWindowToSend(
Http2::Utility::OptionsLimits::MIN_INITIAL_STREAM_WINDOW_SIZE);
quic_config_.SetInitialSessionFlowControlWindowToSend(
1.5 * Http2::Utility::OptionsLimits::MIN_INITIAL_STREAM_WINDOW_SIZE);
ASSERT(quic_connection_persistent_info_ != nullptr);
auto& persistent_info = static_cast<PersistentQuicInfoImpl&>(*quic_connection_persistent_info_);
auto session = std::make_unique<EnvoyQuicClientSession>(
quic_config_, supported_versions_, std::move(connection), persistent_info.server_id_,
persistent_info.crypto_config_.get(), &push_promise_index_, *dispatcher_,
/*send_buffer_limit=*/2 * Http2::Utility::OptionsLimits::MIN_INITIAL_STREAM_WINDOW_SIZE);
session->Initialize();
return session;
}
IntegrationCodecClientPtr makeRawHttpConnection(
Network::ClientConnectionPtr&& conn,
absl::optional<envoy::config::core::v3::Http2ProtocolOptions> http2_options) override {
IntegrationCodecClientPtr codec =
HttpIntegrationTest::makeRawHttpConnection(std::move(conn), http2_options);
if (!codec->disconnected()) {
codec->setCodecClientCallbacks(client_codec_callback_);
EXPECT_EQ(transport_socket_factory_->clientContextConfig().serverNameIndication(),
codec->connection()->requestedServerName());
}
return codec;
}
quic::QuicConnectionId getNextConnectionId() {
if (designated_connection_ids_.empty()) {
return quic::QuicUtils::CreateRandomConnectionId();
}
quic::QuicConnectionId cid = designated_connection_ids_.front();
designated_connection_ids_.pop_front();
return cid;
}
void initialize() override {
config_helper_.addConfigModifier([this](envoy::config::bootstrap::v3::Bootstrap& bootstrap) {
const std::string overload_config =
fmt::format(R"EOF(
refresh_interval:
seconds: 0
nanos: 1000000
resource_monitors:
- name: "envoy.resource_monitors.injected_resource_1"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.injected_resource.v3.InjectedResourceConfig
filename: "{}"
- name: "envoy.resource_monitors.injected_resource_2"
typed_config:
"@type": type.googleapis.com/envoy.extensions.resource_monitors.injected_resource.v3.InjectedResourceConfig
filename: "{}"
actions:
- name: "envoy.overload_actions.stop_accepting_requests"
triggers:
- name: "envoy.resource_monitors.injected_resource_1"
threshold:
value: 0.95
- name: "envoy.overload_actions.stop_accepting_connections"
triggers:
- name: "envoy.resource_monitors.injected_resource_1"
threshold:
value: 0.9
- name: "envoy.overload_actions.disable_http_keepalive"
triggers:
- name: "envoy.resource_monitors.injected_resource_2"
threshold:
value: 0.8
)EOF",
injected_resource_filename_1_, injected_resource_filename_2_);
*bootstrap.mutable_overload_manager() =
TestUtility::parseYaml<envoy::config::overload::v3::OverloadManager>(overload_config);
});
config_helper_.addConfigModifier(
[](envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
hcm) {
hcm.mutable_drain_timeout()->clear_seconds();
hcm.mutable_drain_timeout()->set_nanos(500 * 1000 * 1000);
EXPECT_EQ(hcm.codec_type(), envoy::extensions::filters::network::http_connection_manager::
v3::HttpConnectionManager::HTTP3);
});
updateResource(file_updater_1_, 0);
updateResource(file_updater_2_, 0);
HttpIntegrationTest::initialize();
// Latch quic_transport_socket_factory_ which is instantiated in initialize().
transport_socket_factory_ =
static_cast<QuicClientTransportSocketFactory*>(quic_transport_socket_factory_.get());
registerTestServerPorts({"http"});
ASSERT(&transport_socket_factory_->clientContextConfig());
}
void testMultipleQuicConnections() {
concurrency_ = 8;
set_reuse_port_ = true;
initialize();
std::vector<IntegrationCodecClientPtr> codec_clients;
for (size_t i = 1; i <= concurrency_; ++i) {
// The BPF filter and ActiveQuicListener::destination() look at the 1st word of connection id
// in the packet header. And currently all QUIC versions support 8 bytes connection id. So
// create connections with the first 4 bytes of connection id different from each
// other so they should be evenly distributed.
designated_connection_ids_.push_back(quic::test::TestConnectionId(i << 32));
// TODO(sunjayBhatia,wrowe): deserialize this, establishing all connections in parallel
// (Expected to save ~14s each across 6 tests on Windows)
codec_clients.push_back(makeHttpConnection(lookupPort("http")));
}
constexpr auto timeout_first = std::chrono::seconds(15);
constexpr auto timeout_subsequent = std::chrono::milliseconds(10);
if (GetParam().first == Network::Address::IpVersion::v4) {
test_server_->waitForCounterEq("listener.0.0.0.0_0.downstream_cx_total", 8u, timeout_first);
} else {
test_server_->waitForCounterEq("listener.[__]_0.downstream_cx_total", 8u, timeout_first);
}
for (size_t i = 0; i < concurrency_; ++i) {
if (GetParam().first == Network::Address::IpVersion::v4) {
test_server_->waitForGaugeEq(
fmt::format("listener.0.0.0.0_0.worker_{}.downstream_cx_active", i), 1u,
timeout_subsequent);
test_server_->waitForCounterEq(
fmt::format("listener.0.0.0.0_0.worker_{}.downstream_cx_total", i), 1u,
timeout_subsequent);
} else {
test_server_->waitForGaugeEq(
fmt::format("listener.[__]_0.worker_{}.downstream_cx_active", i), 1u,
timeout_subsequent);
test_server_->waitForCounterEq(
fmt::format("listener.[__]_0.worker_{}.downstream_cx_total", i), 1u,
timeout_subsequent);
}
}
for (size_t i = 0; i < concurrency_; ++i) {
codec_clients[i]->close();
}
}
protected:
quic::QuicConfig quic_config_;
quic::QuicClientPushPromiseIndex push_promise_index_;
quic::ParsedQuicVersionVector supported_versions_;
EnvoyQuicConnectionHelper conn_helper_;
EnvoyQuicAlarmFactory alarm_factory_;
CodecClientCallbacksForTest client_codec_callback_;
Network::Address::InstanceConstSharedPtr server_addr_;
EnvoyQuicClientConnection* quic_connection_{nullptr};
const std::string injected_resource_filename_1_;
const std::string injected_resource_filename_2_;
AtomicFileUpdater file_updater_1_;
AtomicFileUpdater file_updater_2_;
std::list<quic::QuicConnectionId> designated_connection_ids_;
Quic::QuicClientTransportSocketFactory* transport_socket_factory_{nullptr};
};
INSTANTIATE_TEST_SUITE_P(QuicHttpIntegrationTests, QuicHttpIntegrationTest,
testing::ValuesIn(generateTestParam()), testParamsToString);
TEST_P(QuicHttpIntegrationTest, GetRequestAndEmptyResponse) {
testRouterHeaderOnlyRequestAndResponse();
}
TEST_P(QuicHttpIntegrationTest, GetRequestAndResponseWithBody) {
initialize();
sendRequestAndVerifyResponse(default_request_headers_, /*request_size=*/0,
default_response_headers_, /*response_size=*/1024,
/*backend_index*/ 0);
}
TEST_P(QuicHttpIntegrationTest, PostRequestAndResponseWithBody) {
testRouterRequestAndResponseWithBody(1024, 512, false);
}
TEST_P(QuicHttpIntegrationTest, PostRequestWithBigHeadersAndResponseWithBody) {
testRouterRequestAndResponseWithBody(1024, 512, true);
}
TEST_P(QuicHttpIntegrationTest, RouterUpstreamDisconnectBeforeRequestcomplete) {
testRouterUpstreamDisconnectBeforeRequestComplete();
}
TEST_P(QuicHttpIntegrationTest, RouterUpstreamDisconnectBeforeResponseComplete) {
testRouterUpstreamDisconnectBeforeResponseComplete();
EXPECT_EQ(Http::StreamResetReason::RemoteReset, client_codec_callback_.last_stream_reset_reason_);
}
TEST_P(QuicHttpIntegrationTest, RouterDownstreamDisconnectBeforeRequestComplete) {
testRouterDownstreamDisconnectBeforeRequestComplete();
}
TEST_P(QuicHttpIntegrationTest, RouterDownstreamDisconnectBeforeResponseComplete) {
testRouterDownstreamDisconnectBeforeResponseComplete();
}
TEST_P(QuicHttpIntegrationTest, RouterUpstreamResponseBeforeRequestComplete) {
testRouterUpstreamResponseBeforeRequestComplete();
}
TEST_P(QuicHttpIntegrationTest, Retry) { testRetry(); }
TEST_P(QuicHttpIntegrationTest, UpstreamReadDisabledOnGiantResponseBody) {
config_helper_.addConfigModifier(setUpstreamTimeout);
config_helper_.setBufferLimits(/*upstream_buffer_limit=*/1024, /*downstream_buffer_limit=*/1024);
testRouterRequestAndResponseWithBody(/*request_size=*/512, /*response_size=*/10 * 1024 * 1024,
false);
}
TEST_P(QuicHttpIntegrationTest, DownstreamReadDisabledOnGiantPost) {
config_helper_.setBufferLimits(/*upstream_buffer_limit=*/1024, /*downstream_buffer_limit=*/1024);
testRouterRequestAndResponseWithBody(/*request_size=*/10 * 1024 * 1024, /*response_size=*/1024,
false);
}
TEST_P(QuicHttpIntegrationTest, LargeFlowControlOnAndGiantBody) {
config_helper_.addConfigModifier(setUpstreamTimeout);
config_helper_.setBufferLimits(/*upstream_buffer_limit=*/128 * 1024,
/*downstream_buffer_limit=*/128 * 1024);
testRouterRequestAndResponseWithBody(/*request_size=*/10 * 1024 * 1024,
/*response_size=*/10 * 1024 * 1024, false, false);
}
// Tests that a connection idle times out after 1s and starts delayed close.
TEST_P(QuicHttpIntegrationTest, TestDelayedConnectionTeardownTimeoutTrigger) {
config_helper_.setBufferLimits(1024, 1024);
config_helper_.addConfigModifier(
[](envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
hcm) {
// 200ms.
hcm.mutable_delayed_close_timeout()->set_nanos(200000000);
hcm.mutable_drain_timeout()->set_seconds(1);
hcm.mutable_common_http_protocol_options()->mutable_idle_timeout()->set_seconds(1);
});
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto encoder_decoder =
codec_client_->startRequest(Http::TestRequestHeaderMapImpl{{":method", "POST"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "host"}});
request_encoder_ = &encoder_decoder.first;
auto response = std::move(encoder_decoder.second);
codec_client_->sendData(*request_encoder_, 1024 * 65, false);
response->waitForEndStream();
// The delayed close timeout should trigger since client is not closing the connection.
EXPECT_TRUE(codec_client_->waitForDisconnect(std::chrono::milliseconds(5000)));
EXPECT_EQ(codec_client_->lastConnectionEvent(), Network::ConnectionEvent::RemoteClose);
EXPECT_EQ(test_server_->counter("http.config_test.downstream_cx_delayed_close_timeout")->value(),
1);
}
// Ensure multiple quic connections work, regardless of platform BPF support
TEST_P(QuicHttpIntegrationTest, MultipleQuicConnectionsDefaultMode) {
testMultipleQuicConnections();
}
TEST_P(QuicHttpIntegrationTest, MultipleQuicConnectionsNoBPF) {
// Note: This runtime override is a no-op on platforms without BPF
config_helper_.addRuntimeOverride(
"envoy.reloadable_features.prefer_quic_kernel_bpf_packet_routing", "false");
testMultipleQuicConnections();
}
TEST_P(QuicHttpIntegrationTest, ConnectionMigration) {
concurrency_ = 2;
set_reuse_port_ = true;
initialize();
uint32_t old_port = lookupPort("http");
codec_client_ = makeHttpConnection(old_port);
auto encoder_decoder =
codec_client_->startRequest(Http::TestRequestHeaderMapImpl{{":method", "POST"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "host"}});
request_encoder_ = &encoder_decoder.first;
auto response = std::move(encoder_decoder.second);
codec_client_->sendData(*request_encoder_, 1024u, false);
// Change to a new port by switching socket, and connection should still continue.
Network::Address::InstanceConstSharedPtr local_addr =
Network::Test::getCanonicalLoopbackAddress(version_);
quic_connection_->switchConnectionSocket(
createConnectionSocket(server_addr_, local_addr, nullptr));
EXPECT_NE(old_port, local_addr->ip()->port());
// Send the rest data.
codec_client_->sendData(*request_encoder_, 1024u, true);
waitForNextUpstreamRequest(0, TestUtility::DefaultTimeout);
// Send response headers, and end_stream if there is no response body.
const Http::TestResponseHeaderMapImpl response_headers{{":status", "200"}};
size_t response_size{5u};
upstream_request_->encodeHeaders(response_headers, false);
upstream_request_->encodeData(response_size, true);
response->waitForEndStream();
verifyResponse(std::move(response), "200", response_headers, std::string(response_size, 'a'));
EXPECT_TRUE(upstream_request_->complete());
EXPECT_EQ(1024u * 2, upstream_request_->bodyLength());
cleanupUpstreamAndDownstream();
}
TEST_P(QuicHttpIntegrationTest, StopAcceptingConnectionsWhenOverloaded) {
initialize();
// Put envoy in overloaded state and check that it doesn't accept the new client connection.
updateResource(file_updater_1_, 0.9);
test_server_->waitForGaugeEq("overload.envoy.overload_actions.stop_accepting_connections.active",
1);
codec_client_ = makeRawHttpConnection(makeClientConnection((lookupPort("http"))), absl::nullopt);
EXPECT_TRUE(codec_client_->disconnected());
// Reduce load a little to allow the connection to be accepted connection.
updateResource(file_updater_1_, 0.8);
test_server_->waitForGaugeEq("overload.envoy.overload_actions.stop_accepting_connections.active",
0);
codec_client_ = makeHttpConnection(makeClientConnection((lookupPort("http"))));
auto response = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
waitForNextUpstreamRequest(0);
// Send response headers, but hold response body for now.
upstream_request_->encodeHeaders(default_response_headers_, /*end_stream=*/false);
updateResource(file_updater_1_, 0.95);
test_server_->waitForGaugeEq("overload.envoy.overload_actions.stop_accepting_requests.active", 1);
// Existing request should be able to finish.
upstream_request_->encodeData(10, true);
response->waitForEndStream();
EXPECT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().getStatusValue());
// New request should be rejected.
auto response2 = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
response2->waitForEndStream();
EXPECT_EQ("503", response2->headers().getStatusValue());
EXPECT_EQ("envoy overloaded", response2->body());
codec_client_->close();
EXPECT_TRUE(makeRawHttpConnection(makeClientConnection((lookupPort("http"))), absl::nullopt)
->disconnected());
}
TEST_P(QuicHttpIntegrationTest, NoNewStreamsWhenOverloaded) {
initialize();
updateResource(file_updater_1_, 0.7);
codec_client_ = makeHttpConnection(makeClientConnection((lookupPort("http"))));
// Send a complete request and start a second.
auto response = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
waitForNextUpstreamRequest(0);
upstream_request_->encodeHeaders(default_response_headers_, true);
response->waitForEndStream();
auto response2 = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
waitForNextUpstreamRequest(0);
// Enable the disable-keepalive overload action. This should send a shutdown notice before
// encoding the headers.
updateResource(file_updater_2_, 0.9);
test_server_->waitForGaugeEq("overload.envoy.overload_actions.disable_http_keepalive.active", 1);
upstream_request_->encodeHeaders(default_response_headers_, /*end_stream=*/false);
upstream_request_->encodeData(10, true);
response2->waitForHeaders();
EXPECT_TRUE(codec_client_->waitForDisconnect());
EXPECT_TRUE(codec_client_->sawGoAway());
codec_client_->close();
}
TEST_P(QuicHttpIntegrationTest, AdminDrainDrainsListeners) {
testAdminDrain(Http::CodecClient::Type::HTTP1);
}
TEST_P(QuicHttpIntegrationTest, CertVerificationFailure) {
san_to_match_ = "www.random_domain.com";
initialize();
codec_client_ = makeRawHttpConnection(makeClientConnection((lookupPort("http"))), absl::nullopt);
EXPECT_FALSE(codec_client_->connected());
std::string failure_reason =
GetParam().second == QuicVersionType::GquicQuicCrypto
? "QUIC_PROOF_INVALID with details: Proof invalid: X509_verify_cert: certificate "
"verification error at depth 0: ok"
: "QUIC_TLS_CERTIFICATE_UNKNOWN with details: TLS handshake failure "
"(ENCRYPTION_HANDSHAKE) 46: "
"certificate unknown";
EXPECT_EQ(failure_reason, codec_client_->connection()->transportFailureReason());
}
TEST_P(QuicHttpIntegrationTest, RequestResponseWithTrailers) {
config_helper_.addConfigModifier(setEnableUpstreamTrailersHttp1());
testTrailers(/*request_size=*/10, /*response_size=*/10, /*request_trailers_present=*/true,
/*response_trailers_present=*/true);
}
// Multiple 1xx before the request completes.
TEST_P(QuicHttpIntegrationTest, EnvoyProxyingEarlyMultiple1xx) {
testEnvoyProxying1xx(/*continue_before_upstream_complete=*/true, /*with_encoder_filter=*/false,
/*with_multiple_1xx_headers=*/true);
}
// HTTP3 doesn't support 101 SwitchProtocol response code, the client should
// reset the request.
TEST_P(QuicHttpIntegrationTest, Reset101SwitchProtocolResponse) {
config_helper_.addConfigModifier(
[&](envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
hcm) -> void { hcm.set_proxy_100_continue(true); });
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto encoder_decoder =
codec_client_->startRequest(Http::TestRequestHeaderMapImpl{{":method", "GET"},
{":path", "/dynamo/url"},
{":scheme", "http"},
{":authority", "host"},
{"expect", "100-continue"}});
request_encoder_ = &encoder_decoder.first;
auto response = std::move(encoder_decoder.second);
// Wait for the request headers to be received upstream.
ASSERT_TRUE(fake_upstreams_[0]->waitForHttpConnection(*dispatcher_, fake_upstream_connection_));
ASSERT_TRUE(fake_upstream_connection_->waitForNewStream(*dispatcher_, upstream_request_));
upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "101"}}, false);
response->waitForReset();
codec_client_->close();
EXPECT_FALSE(response->complete());
}
TEST_P(QuicHttpIntegrationTest, ResetRequestWithoutAuthorityHeader) {
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto encoder_decoder = codec_client_->startRequest(Http::TestRequestHeaderMapImpl{
{":method", "GET"}, {":path", "/dynamo/url"}, {":scheme", "http"}});
request_encoder_ = &encoder_decoder.first;
auto response = std::move(encoder_decoder.second);
response->waitForEndStream();
codec_client_->close();
ASSERT_TRUE(response->complete());
EXPECT_EQ("400", response->headers().getStatusValue());
}
TEST_P(QuicHttpIntegrationTest, MultipleSetCookieAndCookieHeaders) {
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto encoder_decoder =
codec_client_->startRequest(Http::TestRequestHeaderMapImpl{{":method", "GET"},
{":path", "/dynamo/url"},
{":scheme", "http"},
{":authority", "host"},
{"cookie", "a=b"},
{"cookie", "c=d"}});
request_encoder_ = &encoder_decoder.first;
auto response = std::move(encoder_decoder.second);
codec_client_->sendData(*request_encoder_, 0, true);
waitForNextUpstreamRequest();
if (Runtime::runtimeFeatureEnabled(
"envoy.reloadable_features.header_map_correctly_coalesce_cookies")) {
EXPECT_EQ(upstream_request_->headers().get(Http::Headers::get().Cookie)[0]->value(),
"a=b; c=d");
}
upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "200"},
{"set-cookie", "foo"},
{"set-cookie", "bar"}},
true);
response->waitForEndStream();
EXPECT_TRUE(response->complete());
const auto out = response->headers().get(Http::LowerCaseString("set-cookie"));
ASSERT_EQ(out.size(), 2);
ASSERT_EQ(out[0]->value().getStringView(), "foo");
ASSERT_EQ(out[1]->value().getStringView(), "bar");
}
} // namespace Quic
} // namespace Envoy