forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quic_http_integration_test.cc
1787 lines (1594 loc) · 85.5 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
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <openssl/ssl.h>
#include <openssl/x509_vfy.h>
#include <cstddef>
#include <memory>
#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/quic/server_preferred_address/v3/fixed_server_preferred_address_config.pb.h"
#include "envoy/extensions/transport_sockets/quic/v3/quic_transport.pb.h"
#include "source/common/quic/active_quic_listener.h"
#include "source/common/quic/client_connection_factory_impl.h"
#include "source/common/quic/envoy_quic_alarm_factory.h"
#include "source/common/quic/envoy_quic_client_session.h"
#include "source/common/quic/envoy_quic_connection_helper.h"
#include "source/common/quic/envoy_quic_packet_writer.h"
#include "source/common/quic/envoy_quic_proof_verifier.h"
#include "source/common/quic/envoy_quic_utils.h"
#include "source/common/quic/quic_transport_socket_factory.h"
#include "source/extensions/transport_sockets/tls/context_config_impl.h"
#include "test/common/config/dummy_config.pb.h"
#include "test/common/quic/test_utils.h"
#include "test/common/upstream/utility.h"
#include "test/config/integration/certs/clientcert_hash.h"
#include "test/config/utility.h"
#include "test/extensions/transport_sockets/tls/cert_validator/timed_cert_validator.h"
#include "test/integration/http_integration.h"
#include "test/integration/ssl_utility.h"
#include "test/test_common/registry.h"
#include "test/test_common/test_runtime.h"
#include "test/test_common/utility.h"
#include "quiche/quic/core/crypto/quic_client_session_cache.h"
#include "quiche/quic/core/http/quic_client_push_promise_index.h"
#include "quiche/quic/core/quic_utils.h"
#include "quiche/quic/test_tools/quic_sent_packet_manager_peer.h"
#include "quiche/quic/test_tools/quic_session_peer.h"
#include "quiche/quic/test_tools/quic_test_utils.h"
namespace Envoy {
using Extensions::TransportSockets::Tls::ContextImplPeer;
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};
};
// This class enables testing on QUIC path validation
class TestEnvoyQuicClientConnection : public EnvoyQuicClientConnection {
public:
TestEnvoyQuicClientConnection(const quic::QuicConnectionId& server_connection_id,
Network::Address::InstanceConstSharedPtr& initial_peer_address,
quic::QuicConnectionHelperInterface& helper,
quic::QuicAlarmFactory& alarm_factory,
const quic::ParsedQuicVersionVector& supported_versions,
Network::Address::InstanceConstSharedPtr local_addr,
Event::Dispatcher& dispatcher,
const Network::ConnectionSocket::OptionsSharedPtr& options,
bool validation_failure_on_path_response,
quic::ConnectionIdGeneratorInterface& generator)
: EnvoyQuicClientConnection(server_connection_id, initial_peer_address, helper, alarm_factory,
supported_versions, local_addr, dispatcher, options, generator),
dispatcher_(dispatcher),
validation_failure_on_path_response_(validation_failure_on_path_response) {}
AssertionResult
waitForPathResponse(std::chrono::milliseconds timeout = TestUtility::DefaultTimeout) {
bool timer_fired = false;
if (!saw_path_response_) {
Event::TimerPtr timer(dispatcher_.createTimer([this, &timer_fired]() -> void {
timer_fired = true;
dispatcher_.exit();
}));
timer->enableTimer(timeout);
waiting_for_path_response_ = true;
dispatcher_.run(Event::Dispatcher::RunType::Block);
if (timer_fired) {
return AssertionFailure() << "Timed out waiting for path response\n";
}
}
return AssertionSuccess();
}
bool OnPathResponseFrame(const quic::QuicPathResponseFrame& frame) override {
saw_path_response_ = true;
if (waiting_for_path_response_) {
dispatcher_.exit();
}
if (!validation_failure_on_path_response_) {
return EnvoyQuicClientConnection::OnPathResponseFrame(frame);
}
CancelPathValidation();
return connected();
}
AssertionResult
waitForHandshakeDone(std::chrono::milliseconds timeout = TestUtility::DefaultTimeout) {
bool timer_fired = false;
if (!saw_handshake_done_) {
Event::TimerPtr timer(dispatcher_.createTimer([this, &timer_fired]() -> void {
timer_fired = true;
dispatcher_.exit();
}));
timer->enableTimer(timeout);
waiting_for_handshake_done_ = true;
dispatcher_.run(Event::Dispatcher::RunType::Block);
if (timer_fired) {
return AssertionFailure() << "Timed out waiting for handshake done\n";
}
}
return AssertionSuccess();
}
bool OnHandshakeDoneFrame(const quic::QuicHandshakeDoneFrame& frame) override {
saw_handshake_done_ = true;
if (waiting_for_handshake_done_) {
dispatcher_.exit();
}
return EnvoyQuicClientConnection::OnHandshakeDoneFrame(frame);
}
private:
Event::Dispatcher& dispatcher_;
bool saw_path_response_{false};
bool saw_handshake_done_{false};
bool waiting_for_path_response_{false};
bool waiting_for_handshake_done_{false};
bool validation_failure_on_path_response_{false};
};
// A test that sets up its own client connection with customized quic version and connection ID.
class QuicHttpIntegrationTestBase : public HttpIntegrationTest {
public:
QuicHttpIntegrationTestBase(Network::Address::IpVersion version, std::string config)
: HttpIntegrationTest(Http::CodecType::HTTP3, version, config),
supported_versions_(quic::CurrentSupportedHttp3Versions()), conn_helper_(*dispatcher_),
alarm_factory_(*dispatcher_, *conn_helper_.GetClock()) {}
~QuicHttpIntegrationTestBase() 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.
return makeClientConnectionWithHost(port, "", options);
}
Network::ClientConnectionPtr makeClientConnectionWithHost(
uint32_t port, const std::string& host,
const Network::ConnectionSocket::OptionsSharedPtr& options = nullptr) {
// Setting socket options is not supported.
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<TestEnvoyQuicClientConnection>(
getNextConnectionId(), server_addr_, conn_helper_, alarm_factory_,
quic::ParsedQuicVersionVector{supported_versions_[0]}, local_addr, *dispatcher_, options,
validation_failure_on_path_response_, connection_id_generator_);
quic_connection_ = connection.get();
ASSERT(quic_connection_persistent_info_ != nullptr);
auto& persistent_info = static_cast<PersistentQuicInfoImpl&>(*quic_connection_persistent_info_);
OptRef<Http::HttpServerPropertiesCache> cache;
auto session = std::make_unique<EnvoyQuicClientSession>(
persistent_info.quic_config_, supported_versions_, std::move(connection),
quic::QuicServerId{
(host.empty() ? transport_socket_factory_->clientContextConfig()->serverNameIndication()
: host),
static_cast<uint16_t>(port), false},
transport_socket_factory_->getCryptoConfig(), &push_promise_index_, *dispatcher_,
// Use smaller window than the default one to have test coverage of client codec buffer
// exceeding high watermark.
/*send_buffer_limit=*/2 * Http2::Utility::OptionsLimits::MIN_INITIAL_STREAM_WINDOW_SIZE,
persistent_info.crypto_stream_factory_, quic_stat_names_, cache, *stats_store_.rootScope(),
nullptr);
return session;
}
IntegrationCodecClientPtr makeRawHttpConnection(
Network::ClientConnectionPtr&& conn,
absl::optional<envoy::config::core::v3::Http2ProtocolOptions> http2_options) override {
ENVOY_LOG(debug, "Creating a new client {}",
conn->connectionInfoProvider().localAddress()->asStringView());
return makeRawHttp3Connection(std::move(conn), http2_options, true);
}
// Create Http3 codec client with the option not to wait for 1-RTT key establishment.
IntegrationCodecClientPtr makeRawHttp3Connection(
Network::ClientConnectionPtr&& conn,
absl::optional<envoy::config::core::v3::Http2ProtocolOptions> http2_options,
bool wait_for_1rtt_key) {
std::shared_ptr<Upstream::MockClusterInfo> cluster{new NiceMock<Upstream::MockClusterInfo>()};
cluster->max_response_headers_count_ = 200;
if (http2_options.has_value()) {
cluster->http3_options_ = ConfigHelper::http2ToHttp3ProtocolOptions(
http2_options.value(), quic::kStreamReceiveWindowLimit);
}
*cluster->http3_options_.mutable_quic_protocol_options() = client_quic_options_;
Upstream::HostDescriptionConstSharedPtr host_description{Upstream::makeTestHostDescription(
cluster, fmt::format("tcp://{}:80", Network::Test::getLoopbackAddressUrlString(version_)),
timeSystem())};
// This call may fail in QUICHE because of INVALID_VERSION. QUIC connection doesn't support
// in-connection version negotiation.
auto codec = std::make_unique<IntegrationCodecClient>(*dispatcher_, random_, std::move(conn),
host_description, downstream_protocol_,
wait_for_1rtt_key);
if (codec->disconnected()) {
// Connection may get closed during version negotiation or handshake.
// TODO(#8479) QUIC connection doesn't support in-connection version negotiationPropagate
// INVALID_VERSION error to caller and let caller to use server advertised version list to
// create a new connection with mutually supported version and make client codec again.
ENVOY_LOG(error, "Fail to connect to server with error: {}",
codec->connection()->transportFailureReason());
return codec;
}
codec->setCodecClientCallbacks(client_codec_callback_);
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(
[](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);
});
HttpIntegrationTest::initialize();
registerTestServerPorts({"http"});
// Initialize the transport socket factory using a customized ssl option.
ssl_client_option_.setAlpn(true).setSan(san_to_match_).setSni("lyft.com");
NiceMock<Server::Configuration::MockTransportSocketFactoryContext> context;
ON_CALL(context, api()).WillByDefault(testing::ReturnRef(*api_));
ON_CALL(context, scope()).WillByDefault(testing::ReturnRef(stats_scope_));
ON_CALL(context, sslContextManager()).WillByDefault(testing::ReturnRef(context_manager_));
envoy::extensions::transport_sockets::quic::v3::QuicUpstreamTransport
quic_transport_socket_config;
auto* tls_context = quic_transport_socket_config.mutable_upstream_tls_context();
initializeUpstreamTlsContextConfig(ssl_client_option_, *tls_context);
envoy::config::core::v3::TransportSocket message;
message.mutable_typed_config()->PackFrom(quic_transport_socket_config);
auto& config_factory = Config::Utility::getAndCheckFactory<
Server::Configuration::UpstreamTransportSocketConfigFactory>(message);
transport_socket_factory_.reset(static_cast<QuicClientTransportSocketFactory*>(
config_factory.createTransportSocketFactory(quic_transport_socket_config, context)
.release()));
ASSERT(transport_socket_factory_->clientContextConfig());
}
void setConcurrency(size_t concurrency) {
concurrency_ = concurrency;
if (concurrency > 1) {
config_helper_.addConfigModifier(
[=](envoy::config::bootstrap::v3::Bootstrap& bootstrap) -> void {
// SO_REUSEPORT is needed because concurrency > 1.
bootstrap.mutable_static_resources()
->mutable_listeners(0)
->mutable_enable_reuse_port()
->set_value(true);
});
}
}
void testMultipleQuicConnections() {
// Enabling SO_REUSEPORT with 8 workers. Unfortunately this setting makes the test rarely flaky
// if it is configured to run with --runs_per_test=N where N > 1 but without --jobs=1.
setConcurrency(8);
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 (version_ == Network::Address::IpVersion::v4) {
test_server_->waitForCounterEq("listener.127.0.0.1_0.downstream_cx_total", 8u, timeout_first);
} else {
test_server_->waitForCounterEq("listener.[__1]_0.downstream_cx_total", 8u, timeout_first);
}
for (size_t i = 0; i < concurrency_; ++i) {
if (version_ == Network::Address::IpVersion::v4) {
test_server_->waitForGaugeEq(
fmt::format("listener.127.0.0.1_0.worker_{}.downstream_cx_active", i), 1u,
timeout_subsequent);
test_server_->waitForCounterEq(
fmt::format("listener.127.0.0.1_0.worker_{}.downstream_cx_total", i), 1u,
timeout_subsequent);
} else {
test_server_->waitForGaugeEq(
fmt::format("listener.[__1]_0.worker_{}.downstream_cx_active", i), 1u,
timeout_subsequent);
test_server_->waitForCounterEq(
fmt::format("listener.[__1]_0.worker_{}.downstream_cx_total", i), 1u,
timeout_subsequent);
}
}
for (size_t i = 0; i < concurrency_; ++i) {
fake_upstream_connection_ = nullptr;
upstream_request_ = nullptr;
auto encoder_decoder =
codec_clients[i]->startRequest(Http::TestRequestHeaderMapImpl{{":method", "GET"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "host"}});
auto& request_encoder = encoder_decoder.first;
auto response = std::move(encoder_decoder.second);
codec_clients[i]->sendData(request_encoder, 1000, true);
waitForNextUpstreamRequest();
upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "200"},
{"set-cookie", "foo"},
{"set-cookie", "bar"}},
true);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(response->complete());
codec_clients[i]->close();
}
}
protected:
quic::QuicClientPushPromiseIndex push_promise_index_;
quic::ParsedQuicVersionVector supported_versions_;
EnvoyQuicConnectionHelper conn_helper_;
EnvoyQuicAlarmFactory alarm_factory_;
CodecClientCallbacksForTest client_codec_callback_;
Network::Address::InstanceConstSharedPtr server_addr_;
envoy::config::core::v3::QuicProtocolOptions client_quic_options_;
TestEnvoyQuicClientConnection* quic_connection_{nullptr};
std::list<quic::QuicConnectionId> designated_connection_ids_;
Ssl::ClientSslTransportOptions ssl_client_option_;
std::unique_ptr<Quic::QuicClientTransportSocketFactory> transport_socket_factory_;
bool validation_failure_on_path_response_{false};
quic::DeterministicConnectionIdGenerator connection_id_generator_{
quic::kQuicDefaultConnectionIdLength};
};
class QuicHttpIntegrationTest : public QuicHttpIntegrationTestBase,
public testing::TestWithParam<Network::Address::IpVersion> {
public:
QuicHttpIntegrationTest()
: QuicHttpIntegrationTestBase(GetParam(), ConfigHelper::quicHttpProxyConfig()) {}
};
class QuicHttpMultiAddressesIntegrationTest
: public QuicHttpIntegrationTestBase,
public testing::TestWithParam<Network::Address::IpVersion> {
public:
QuicHttpMultiAddressesIntegrationTest()
: QuicHttpIntegrationTestBase(GetParam(), ConfigHelper::quicHttpProxyConfig(true)) {}
void testMultipleQuicConnections() {
// Enabling SO_REUSEPORT with 8 workers. Unfortunately this setting makes the test rarely flaky
// if it is configured to run with --runs_per_test=N where N > 1 but without --jobs=1.
setConcurrency(8);
initialize();
std::vector<std::string> addresses({"address1", "address2"});
registerTestServerPorts(addresses);
std::vector<IntegrationCodecClientPtr> codec_clients1;
std::vector<IntegrationCodecClientPtr> codec_clients2;
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_clients1.push_back(makeHttpConnection(lookupPort("address1")));
// Using the same connection id for the address1 and address2 here. Since the multiple
// addresses listener are expected to create separated `ActiveQuicListener` instance for each
// address, then expects the `UdpWorkerRouter` will route the connection to the correct
// `ActiveQuicListener` instance. If the two connections with same connection id are going to
// the same `ActiveQuicListener`, the test will fail.
// For the case of the packets from the different addresses in the same listener wants to be
// the same QUIC connection,(Which mentioned at
// https://github.com/envoyproxy/envoy/issues/11184#issuecomment-679214885) it doesn't support
// for now. When someday that case supported by envoy, we can change this testcase.
designated_connection_ids_.push_back(quic::test::TestConnectionId(i << 32));
codec_clients2.push_back(makeHttpConnection(lookupPort("address2")));
}
constexpr auto timeout_first = std::chrono::seconds(15);
constexpr auto timeout_subsequent = std::chrono::milliseconds(10);
if (version_ == Network::Address::IpVersion::v4) {
test_server_->waitForCounterEq("listener.127.0.0.1_0.downstream_cx_total", 16u,
timeout_first);
} else {
test_server_->waitForCounterEq("listener.[__1]_0.downstream_cx_total", 16u, timeout_first);
}
for (size_t i = 0; i < concurrency_; ++i) {
if (version_ == Network::Address::IpVersion::v4) {
test_server_->waitForGaugeEq(
fmt::format("listener.127.0.0.1_0.worker_{}.downstream_cx_active", i), 2u,
timeout_subsequent);
test_server_->waitForCounterEq(
fmt::format("listener.127.0.0.1_0.worker_{}.downstream_cx_total", i), 2u,
timeout_subsequent);
} else {
test_server_->waitForGaugeEq(
fmt::format("listener.[__1]_0.worker_{}.downstream_cx_active", i), 2u,
timeout_subsequent);
test_server_->waitForCounterEq(
fmt::format("listener.[__1]_0.worker_{}.downstream_cx_total", i), 2u,
timeout_subsequent);
}
}
for (size_t i = 0; i < concurrency_; ++i) {
fake_upstream_connection_ = nullptr;
upstream_request_ = nullptr;
auto encoder_decoder = codec_clients1[i]->startRequest(
Http::TestRequestHeaderMapImpl{{":method", "GET"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "host"}});
auto& request_encoder = encoder_decoder.first;
auto response = std::move(encoder_decoder.second);
codec_clients1[i]->sendData(request_encoder, 1000, true);
waitForNextUpstreamRequest();
upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "200"},
{"set-cookie", "foo"},
{"set-cookie", "bar"}},
true);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_TRUE(response->complete());
codec_clients1[i]->close();
auto encoder_decoder2 = codec_clients2[i]->startRequest(
Http::TestRequestHeaderMapImpl{{":method", "GET"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "host"}});
auto& request_encoder2 = encoder_decoder2.first;
auto response2 = std::move(encoder_decoder2.second);
codec_clients2[i]->sendData(request_encoder2, 1000, true);
waitForNextUpstreamRequest();
upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "200"},
{"set-cookie", "foo"},
{"set-cookie", "bar"}},
true);
ASSERT_TRUE(response2->waitForEndStream());
EXPECT_TRUE(response2->complete());
codec_clients2[i]->close();
}
}
};
INSTANTIATE_TEST_SUITE_P(QuicHttpIntegrationTests, QuicHttpIntegrationTest,
testing::ValuesIn(TestEnvironment::getIpVersionsForTest()),
TestUtility::ipTestParamsToString);
INSTANTIATE_TEST_SUITE_P(QuicHttpMultiAddressesIntegrationTest,
QuicHttpMultiAddressesIntegrationTest,
testing::ValuesIn(TestEnvironment::getIpVersionsForTest()),
TestUtility::ipTestParamsToString);
TEST_P(QuicHttpIntegrationTest, GetRequestAndEmptyResponse) {
useAccessLog("%DOWNSTREAM_TLS_VERSION% %DOWNSTREAM_TLS_CIPHER% %DOWNSTREAM_TLS_SESSION_ID%");
testRouterHeaderOnlyRequestAndResponse();
std::string log = waitForAccessLog(access_log_name_);
EXPECT_THAT(log, testing::MatchesRegex("TLSv1.3 TLS_(AES_128_GCM|CHACHA20_POLY1305)_SHA256 -"));
}
TEST_P(QuicHttpIntegrationTest, GetPeerAndLocalCertsInfo) {
// These are not implemented yet, but configuring them shouldn't cause crash.
useAccessLog("%DOWNSTREAM_PEER_CERT% %DOWNSTREAM_PEER_ISSUER% %DOWNSTREAM_PEER_SERIAL% "
"%DOWNSTREAM_PEER_FINGERPRINT_1% %DOWNSTREAM_PEER_FINGERPRINT_256% "
"%DOWNSTREAM_LOCAL_SUBJECT% %DOWNSTREAM_PEER_SUBJECT% %DOWNSTREAM_LOCAL_URI_SAN% "
"%DOWNSTREAM_PEER_URI_SAN%");
testRouterHeaderOnlyRequestAndResponse();
std::string log = waitForAccessLog(access_log_name_);
EXPECT_EQ("- - - - - - - - -", log);
}
TEST_P(QuicHttpIntegrationTest, Draft29NotSupportedByDefault) {
supported_versions_ = {quic::ParsedQuicVersion::Draft29()};
initialize();
codec_client_ = makeRawHttpConnection(makeClientConnection(lookupPort("http")), absl::nullopt);
EXPECT_TRUE(codec_client_->disconnected());
EXPECT_EQ(quic::QUIC_INVALID_VERSION,
static_cast<EnvoyQuicClientSession*>(codec_client_->connection())->error());
}
TEST_P(QuicHttpIntegrationTest, RuntimeEnableDraft29) {
supported_versions_ = {quic::ParsedQuicVersion::Draft29()};
config_helper_.addRuntimeOverride(
"envoy.reloadable_features.FLAGS_envoy_quic_reloadable_flag_quic_disable_version_draft_29",
"false");
initialize();
codec_client_ = makeRawHttpConnection(makeClientConnection(lookupPort("http")), absl::nullopt);
EXPECT_EQ(transport_socket_factory_->clientContextConfig()->serverNameIndication(),
codec_client_->connection()->requestedServerName());
auto response = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
waitForNextUpstreamRequest(0);
upstream_request_->encodeHeaders(default_response_headers_, true);
ASSERT_TRUE(response->waitForEndStream());
codec_client_->close();
test_server_->waitForCounterEq("http3.quic_version_h3_29", 1u);
}
TEST_P(QuicHttpIntegrationTest, ZeroRtt) {
// Make sure all connections use the same PersistentQuicInfoImpl.
concurrency_ = 1;
const Http::TestResponseHeaderMapImpl too_early_response_headers{{":status", "425"}};
initialize();
// Start the first connection.
codec_client_ = makeHttpConnection(makeClientConnection((lookupPort("http"))));
EXPECT_EQ(transport_socket_factory_->clientContextConfig()->serverNameIndication(),
codec_client_->connection()->requestedServerName());
// Send a complete request on the first connection.
auto response1 = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
waitForNextUpstreamRequest(0);
upstream_request_->encodeHeaders(default_response_headers_, true);
ASSERT_TRUE(response1->waitForEndStream());
// Close the first connection.
codec_client_->close();
// Start a second connection.
codec_client_ = makeRawHttp3Connection(makeClientConnection((lookupPort("http"))), absl::nullopt,
/*wait_for_1rtt_key*/ false);
// Send a complete request on the second connection.
auto response2 = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
waitForNextUpstreamRequest(0);
EXPECT_THAT(upstream_request_->headers(), HeaderValueOf(Http::Headers::get().EarlyData, "1"));
upstream_request_->encodeHeaders(default_response_headers_, true);
ASSERT_TRUE(response2->waitForEndStream());
// Ensure 0-RTT was used by second connection.
EnvoyQuicClientSession* quic_session =
static_cast<EnvoyQuicClientSession*>(codec_client_->connection());
EXPECT_TRUE(static_cast<quic::QuicCryptoClientStream*>(
quic::test::QuicSessionPeer::GetMutableCryptoStream(quic_session))
->EarlyDataAccepted());
EXPECT_NE(quic_session->ssl(), nullptr);
EXPECT_TRUE(quic_session->ssl()->peerCertificateValidated());
// Close the second connection.
codec_client_->close();
if (version_ == Network::Address::IpVersion::v4) {
test_server_->waitForCounterEq(
"listener.127.0.0.1_0.http3.downstream.rx.quic_connection_close_error_"
"code_QUIC_NO_ERROR",
2u);
} else {
test_server_->waitForCounterEq("listener.[__1]_0.http3.downstream.rx.quic_connection_close_"
"error_code_QUIC_NO_ERROR",
2u);
}
test_server_->waitForCounterEq("http3.quic_version_rfc_v1", 2u);
// Start the third connection.
codec_client_ = makeRawHttp3Connection(makeClientConnection((lookupPort("http"))), absl::nullopt,
/*wait_for_1rtt_key*/ false);
auto response3 = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
waitForNextUpstreamRequest(0);
EXPECT_THAT(upstream_request_->headers(), HeaderValueOf(Http::Headers::get().EarlyData, "1"));
upstream_request_->encodeHeaders(too_early_response_headers, true);
ASSERT_TRUE(response3->waitForEndStream());
// This is downstream sending early data, so the 425 response should be forwarded back to the
// client.
EXPECT_EQ("425", response3->headers().getStatusValue());
codec_client_->close();
// Start the fourth connection.
codec_client_ = makeRawHttp3Connection(makeClientConnection((lookupPort("http"))), absl::nullopt,
/*wait_for_1rtt_key*/ false);
Http::TestRequestHeaderMapImpl request{{":method", "GET"},
{":path", "/test/long/url"},
{":scheme", "http"},
{":authority", "host"},
{"Early-Data", "2"}};
auto response4 = codec_client_->makeHeaderOnlyRequest(request);
waitForNextUpstreamRequest(0);
// If the request already has Early-Data header, no additional Early-Data header should be added
// and the header should be forwarded as is.
EXPECT_THAT(upstream_request_->headers(), HeaderValueOf(Http::Headers::get().EarlyData, "2"));
upstream_request_->encodeHeaders(too_early_response_headers, true);
ASSERT_TRUE(response4->waitForEndStream());
// 425 response should be forwarded back to the client.
EXPECT_EQ("425", response4->headers().getStatusValue());
codec_client_->close();
}
TEST_P(QuicHttpIntegrationTest, EarlyDataDisabled) {
// Make sure all connections use the same PersistentQuicInfoImpl.
concurrency_ = 1;
enable_quic_early_data_ = false;
initialize();
// Start the first connection.
codec_client_ = makeHttpConnection(makeClientConnection((lookupPort("http"))));
EXPECT_EQ(transport_socket_factory_->clientContextConfig()->serverNameIndication(),
codec_client_->connection()->requestedServerName());
// Send a complete request on the first connection.
auto response1 = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
waitForNextUpstreamRequest(0);
upstream_request_->encodeHeaders(default_response_headers_, true);
ASSERT_TRUE(response1->waitForEndStream());
// Close the first connection.
codec_client_->close();
// Start a second connection.
codec_client_ = makeHttpConnection(makeClientConnection((lookupPort("http"))));
// Send a complete request on the second connection.
auto response2 = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
waitForNextUpstreamRequest(0);
upstream_request_->encodeHeaders(default_response_headers_, true);
ASSERT_TRUE(response2->waitForEndStream());
// Ensure the 2nd connection is using resumption ticket but doesn't accept early data.
EnvoyQuicClientSession* quic_session =
static_cast<EnvoyQuicClientSession*>(codec_client_->connection());
EXPECT_TRUE(quic_session->IsResumption());
EXPECT_FALSE(quic_session->EarlyDataAccepted());
// Close the second connection.
codec_client_->close();
}
// Ensure multiple quic connections work, regardless of platform BPF support
TEST_P(QuicHttpIntegrationTest, MultipleQuicConnectionsDefaultMode) {
testMultipleQuicConnections();
}
// Ensure multiple quic connections work, regardless of platform BPF support
TEST_P(QuicHttpMultiAddressesIntegrationTest, MultipleQuicConnectionsDefaultMode) {
testMultipleQuicConnections();
}
TEST_P(QuicHttpIntegrationTest, MultipleQuicConnectionsNoBPF) {
// Note: This setting is a no-op on platforms without BPF
class DisableBpf {
public:
DisableBpf() { ActiveQuicListenerFactory::setDisableKernelBpfPacketRoutingForTest(true); }
~DisableBpf() { ActiveQuicListenerFactory::setDisableKernelBpfPacketRoutingForTest(false); }
};
DisableBpf disable;
testMultipleQuicConnections();
}
TEST_P(QuicHttpMultiAddressesIntegrationTest, MultipleQuicConnectionsNoBPF) {
// Note: This setting is a no-op on platforms without BPF
class DisableBpf {
public:
DisableBpf() { ActiveQuicListenerFactory::setDisableKernelBpfPacketRoutingForTest(true); }
~DisableBpf() { ActiveQuicListenerFactory::setDisableKernelBpfPacketRoutingForTest(false); }
};
DisableBpf disable;
testMultipleQuicConnections();
}
// Tests that the packets from a connection with CID longer than 8 bytes are routed to the same
// worker.
TEST_P(QuicHttpIntegrationTest, MultiWorkerWithLongConnectionId) {
setConcurrency(8);
config_helper_.addConfigModifier([=](envoy::config::bootstrap::v3::Bootstrap& bootstrap) -> void {
// SO_REUSEPORT is needed because concurrency > 1.
bootstrap.mutable_static_resources()
->mutable_listeners(0)
->mutable_enable_reuse_port()
->set_value(true);
});
initialize();
// Setup 9-byte CID for the next connection.
designated_connection_ids_.push_back(quic::test::TestConnectionIdNineBytesLong(2u));
testRouterHeaderOnlyRequestAndResponse();
}
TEST_P(QuicHttpIntegrationTest, PortMigration) {
setConcurrency(2);
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);
while (!quic_connection_->IsHandshakeConfirmed()) {
dispatcher_->run(Event::Dispatcher::RunType::NonBlock);
}
// 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);
ASSERT_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());
// Switch to a socket with bad socket options.
auto option = std::make_shared<Network::MockSocketOption>();
EXPECT_CALL(*option, setOption(_, _))
.WillRepeatedly(
Invoke([](Network::Socket&, envoy::config::core::v3::SocketOption::SocketState state) {
if (state == envoy::config::core::v3::SocketOption::STATE_LISTENING) {
return false;
}
return true;
}));
auto options = std::make_shared<Network::Socket::Options>();
options->push_back(option);
quic_connection_->switchConnectionSocket(
createConnectionSocket(server_addr_, local_addr, options));
EXPECT_TRUE(codec_client_->disconnected());
cleanupUpstreamAndDownstream();
}
TEST_P(QuicHttpIntegrationTest, PortMigrationOnPathDegrading) {
setConcurrency(2);
initialize();
client_quic_options_.mutable_num_timeouts_to_trigger_port_migration()->set_value(2);
uint32_t old_port = lookupPort("http");
auto options = std::make_shared<Network::Socket::Options>();
auto option = std::make_shared<Network::MockSocketOption>();
options->push_back(option);
EXPECT_CALL(*option, setOption(_, _)).Times(3u);
codec_client_ = makeHttpConnection(makeClientConnectionWithOptions(old_port, options));
// Make sure that the port migration config is plumbed through.
EXPECT_EQ(2u, quic::test::QuicSentPacketManagerPeer::GetNumPtosForPathDegrading(
&quic_connection_->sent_packet_manager()));
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);
ASSERT_TRUE(quic_connection_->waitForHandshakeDone());
auto old_self_addr = quic_connection_->self_address();
EXPECT_CALL(*option, setOption(_, _)).Times(3u);
quic_connection_->OnPathDegradingDetected();
ASSERT_TRUE(quic_connection_->waitForPathResponse());
auto self_addr = quic_connection_->self_address();
EXPECT_NE(old_self_addr, self_addr);
// 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);
ASSERT_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());
}
TEST_P(QuicHttpIntegrationTest, NoPortMigrationWithoutConfig) {
setConcurrency(2);
initialize();
client_quic_options_.mutable_num_timeouts_to_trigger_port_migration()->set_value(0);
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);
ASSERT_TRUE(quic_connection_->waitForHandshakeDone());
auto old_self_addr = quic_connection_->self_address();
quic_connection_->OnPathDegradingDetected();
ASSERT_FALSE(quic_connection_->waitForPathResponse(std::chrono::milliseconds(2000)));
auto self_addr = quic_connection_->self_address();
EXPECT_EQ(old_self_addr, self_addr);
// 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);
ASSERT_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());
}
TEST_P(QuicHttpIntegrationTest, PortMigrationFailureOnPathDegrading) {
setConcurrency(2);
validation_failure_on_path_response_ = 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);
ASSERT_TRUE(quic_connection_->waitForHandshakeDone());
auto old_self_addr = quic_connection_->self_address();
quic_connection_->OnPathDegradingDetected();
ASSERT_TRUE(quic_connection_->waitForPathResponse());
auto self_addr = quic_connection_->self_address();
// The path validation will fail and thus client self address will not change.
EXPECT_EQ(old_self_addr, self_addr);
// 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);
ASSERT_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());
}
TEST_P(QuicHttpIntegrationTest, AdminDrainDrainsListeners) {
testAdminDrain(Http::CodecType::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 = "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, 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);
ASSERT_TRUE(response->waitForEndStream());
codec_client_->close();
ASSERT_TRUE(response->complete());
EXPECT_EQ("400", response->headers().getStatusValue());
}
TEST_P(QuicHttpIntegrationTest, ResetRequestWithInvalidCharacter) {
config_helper_.addRuntimeOverride("envoy.reloadable_features.validate_upstream_headers", "false");
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
std::string value = std::string(1, 2);
EXPECT_FALSE(Http::HeaderUtility::headerValueIsValid(value));
default_request_headers_.addCopy("illegal_header", value);
auto encoder_decoder = codec_client_->startRequest(default_request_headers_);
request_encoder_ = &encoder_decoder.first;
auto response = std::move(encoder_decoder.second);
ASSERT_TRUE(response->waitForReset());
EXPECT_FALSE(response->complete());
// Verify stream error counters are correctly incremented.
std::string counter_scope = GetParam() == Network::Address::IpVersion::v4
? "listener.127.0.0.1_0.http3.downstream.tx."
: "listener.[__1]_0.http3.downstream.tx.";
std::string error_code = "quic_connection_close_error_code_QUIC_HTTP_FRAME_ERROR";
test_server_->waitForCounterEq(absl::StrCat(counter_scope, error_code), 1U);
}
TEST_P(QuicHttpIntegrationTest, Http3ClientKeepalive) {
initialize();
constexpr uint64_t max_interval_sec = 5;
constexpr uint64_t initial_interval_sec = 1;
// Set connection idle network timeout to be a little larger than max interval.
dynamic_cast<Quic::PersistentQuicInfoImpl&>(*quic_connection_persistent_info_)
.quic_config_.SetIdleNetworkTimeout(quic::QuicTime::Delta::FromSeconds(max_interval_sec + 2));
client_quic_options_.mutable_connection_keepalive()->mutable_max_interval()->set_seconds(
max_interval_sec);
client_quic_options_.mutable_connection_keepalive()->mutable_initial_interval()->set_seconds(
initial_interval_sec);
codec_client_ = makeHttpConnection(makeClientConnection(lookupPort("http")));
auto response = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
waitForNextUpstreamRequest();
// Wait for 10s before sending back response. If keepalive is disabled, the
// connection would have idle timed out.
Event::TimerPtr timer(dispatcher_->createTimer([this]() -> void { dispatcher_->exit(); }));
timer->enableTimer(std::chrono::seconds(10));
dispatcher_->run(Event::Dispatcher::RunType::Block);
upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "200"},
{"set-cookie", "foo"},
{"set-cookie", "bar"}},
true);
EXPECT_TRUE(response->waitForEndStream());
ASSERT_TRUE(response->complete());
// First 6 PING frames should be sent every 1s, and the following ones less frequently.
EXPECT_LE(quic_connection_->GetStats().ping_frames_sent, 8u);
}
TEST_P(QuicHttpIntegrationTest, Http3ClientKeepaliveDisabled) {
initialize();
constexpr uint64_t max_interval_sec = 0;
constexpr uint64_t initial_interval_sec = 1;
// Set connection idle network timeout to be a little larger than max interval.
dynamic_cast<Quic::PersistentQuicInfoImpl&>(*quic_connection_persistent_info_)
.quic_config_.SetIdleNetworkTimeout(quic::QuicTime::Delta::FromSeconds(5));
client_quic_options_.mutable_connection_keepalive()->mutable_max_interval()->set_seconds(
max_interval_sec);
client_quic_options_.mutable_connection_keepalive()->mutable_initial_interval()->set_seconds(
initial_interval_sec);
codec_client_ = makeHttpConnection(makeClientConnection(lookupPort("http")));
auto response = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
waitForNextUpstreamRequest();
// As keepalive is disabled, the connection will timeout after 5s.
EXPECT_TRUE(response->waitForReset());
EXPECT_EQ(quic_connection_->GetStats().ping_frames_sent, 0u);
}