Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: net/tools/quic/quic_dispatcher_test.cc

Issue 1983493002: Minor clean up of QuicDispatcherTests * Use an actual serialized CHLO instead of "foo" for stream d… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@121596064
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/tools/quic/quic_dispatcher.h" 5 #include "net/tools/quic/quic_dispatcher.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <ostream> 8 #include <ostream>
9 #include <string> 9 #include <string>
10 10
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 259
260 void CreateTimeWaitListManager() { 260 void CreateTimeWaitListManager() {
261 time_wait_list_manager_ = 261 time_wait_list_manager_ =
262 new MockTimeWaitListManager(QuicDispatcherPeer::GetWriter(&dispatcher_), 262 new MockTimeWaitListManager(QuicDispatcherPeer::GetWriter(&dispatcher_),
263 &dispatcher_, &helper_, &alarm_factory_); 263 &dispatcher_, &helper_, &alarm_factory_);
264 // dispatcher_ takes the ownership of time_wait_list_manager_. 264 // dispatcher_ takes the ownership of time_wait_list_manager_.
265 QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_, 265 QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_,
266 time_wait_list_manager_); 266 time_wait_list_manager_);
267 } 267 }
268 268
269 string SerializeCHLO() {
270 CryptoHandshakeMessage client_hello;
271 client_hello.set_tag(kCHLO);
272 return client_hello.GetSerialized().AsStringPiece().as_string();
273 }
274
269 EpollServer eps_; 275 EpollServer eps_;
270 QuicEpollConnectionHelper helper_; 276 QuicEpollConnectionHelper helper_;
271 MockQuicConnectionHelper mock_helper_; 277 MockQuicConnectionHelper mock_helper_;
272 QuicEpollAlarmFactory alarm_factory_; 278 QuicEpollAlarmFactory alarm_factory_;
273 MockAlarmFactory mock_alarm_factory_; 279 MockAlarmFactory mock_alarm_factory_;
274 QuicConfig config_; 280 QuicConfig config_;
275 QuicCryptoServerConfig crypto_config_; 281 QuicCryptoServerConfig crypto_config_;
276 IPEndPoint server_address_; 282 IPEndPoint server_address_;
277 TestDispatcher dispatcher_; 283 TestDispatcher dispatcher_;
278 MockTimeWaitListManager* time_wait_list_manager_; 284 MockTimeWaitListManager* time_wait_list_manager_;
279 TestQuicSpdyServerSession* session1_; 285 TestQuicSpdyServerSession* session1_;
280 TestQuicSpdyServerSession* session2_; 286 TestQuicSpdyServerSession* session2_;
281 string data_; 287 string data_;
282 }; 288 };
283 289
284 TEST_F(QuicDispatcherTest, ProcessPackets) { 290 TEST_F(QuicDispatcherTest, ProcessPackets) {
285 IPEndPoint client_address(net::test::Loopback4(), 1); 291 IPEndPoint client_address(net::test::Loopback4(), 1);
286 server_address_ = IPEndPoint(net::test::Any4(), 5); 292 server_address_ = IPEndPoint(net::test::Any4(), 5);
287 293
288 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)) 294 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address))
289 .WillOnce(testing::Return(CreateSession( 295 .WillOnce(testing::Return(CreateSession(
290 &dispatcher_, config_, 1, client_address, &mock_helper_, 296 &dispatcher_, config_, 1, client_address, &mock_helper_,
291 &mock_alarm_factory_, &crypto_config_, 297 &mock_alarm_factory_, &crypto_config_,
292 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_))); 298 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_)));
293 ProcessPacket(client_address, 1, true, false, "foo"); 299 ProcessPacket(client_address, 1, true, false, SerializeCHLO());
294 EXPECT_EQ(client_address, dispatcher_.current_client_address()); 300 EXPECT_EQ(client_address, dispatcher_.current_client_address());
295 EXPECT_EQ(server_address_, dispatcher_.current_server_address()); 301 EXPECT_EQ(server_address_, dispatcher_.current_server_address());
296 302
297 EXPECT_CALL(dispatcher_, CreateQuicSession(2, client_address)) 303 EXPECT_CALL(dispatcher_, CreateQuicSession(2, client_address))
298 .WillOnce(testing::Return(CreateSession( 304 .WillOnce(testing::Return(CreateSession(
299 &dispatcher_, config_, 2, client_address, &mock_helper_, 305 &dispatcher_, config_, 2, client_address, &mock_helper_,
300 &mock_alarm_factory_, &crypto_config_, 306 &mock_alarm_factory_, &crypto_config_,
301 QuicDispatcherPeer::GetCache(&dispatcher_), &session2_))); 307 QuicDispatcherPeer::GetCache(&dispatcher_), &session2_)));
302 ProcessPacket(client_address, 2, true, false, "bar"); 308 ProcessPacket(client_address, 2, true, false, SerializeCHLO());
303 309
304 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), 310 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
305 ProcessUdpPacket(_, _, _)) 311 ProcessUdpPacket(_, _, _))
306 .Times(1) 312 .Times(1)
307 .WillOnce(testing::WithArgs<2>( 313 .WillOnce(testing::WithArgs<2>(
308 Invoke(this, &QuicDispatcherTest::ValidatePacket))); 314 Invoke(this, &QuicDispatcherTest::ValidatePacket)));
309 ProcessPacket(client_address, 1, false, false, "eep"); 315 ProcessPacket(client_address, 1, false, false, "data");
310 } 316 }
311 317
312 TEST_F(QuicDispatcherTest, StatelessVersionNegotiation) { 318 TEST_F(QuicDispatcherTest, StatelessVersionNegotiation) {
313 IPEndPoint client_address(net::test::Loopback4(), 1); 319 IPEndPoint client_address(net::test::Loopback4(), 1);
314 server_address_ = IPEndPoint(net::test::Any4(), 5); 320 server_address_ = IPEndPoint(net::test::Any4(), 5);
315 321
316 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)).Times(0); 322 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)).Times(0);
317 QuicVersion version = static_cast<QuicVersion>(QuicVersionMin() - 1); 323 QuicVersion version = static_cast<QuicVersion>(QuicVersionMin() - 1);
318 ProcessPacket(client_address, 1, true, version, "foo", 324 ProcessPacket(client_address, 1, true, version, SerializeCHLO(),
319 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1); 325 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1);
320 } 326 }
321 327
322 TEST_F(QuicDispatcherTest, Shutdown) { 328 TEST_F(QuicDispatcherTest, Shutdown) {
323 IPEndPoint client_address(net::test::Loopback4(), 1); 329 IPEndPoint client_address(net::test::Loopback4(), 1);
324 330
325 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address)) 331 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address))
326 .WillOnce(testing::Return(CreateSession( 332 .WillOnce(testing::Return(CreateSession(
327 &dispatcher_, config_, 1, client_address, &mock_helper_, 333 &dispatcher_, config_, 1, client_address, &mock_helper_,
328 &mock_alarm_factory_, &crypto_config_, 334 &mock_alarm_factory_, &crypto_config_,
329 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_))); 335 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_)));
330 336
331 ProcessPacket(client_address, 1, true, false, "foo"); 337 ProcessPacket(client_address, 1, true, false, SerializeCHLO());
332 338
333 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), 339 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
334 CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); 340 CloseConnection(QUIC_PEER_GOING_AWAY, _, _));
335 341
336 dispatcher_.Shutdown(); 342 dispatcher_.Shutdown();
337 } 343 }
338 344
339 TEST_F(QuicDispatcherTest, TimeWaitListManager) { 345 TEST_F(QuicDispatcherTest, TimeWaitListManager) {
340 CreateTimeWaitListManager(); 346 CreateTimeWaitListManager();
341 347
342 // Create a new session. 348 // Create a new session.
343 IPEndPoint client_address(net::test::Loopback4(), 1); 349 IPEndPoint client_address(net::test::Loopback4(), 1);
344 QuicConnectionId connection_id = 1; 350 QuicConnectionId connection_id = 1;
345 EXPECT_CALL(dispatcher_, CreateQuicSession(connection_id, client_address)) 351 EXPECT_CALL(dispatcher_, CreateQuicSession(connection_id, client_address))
346 .WillOnce(testing::Return(CreateSession( 352 .WillOnce(testing::Return(CreateSession(
347 &dispatcher_, config_, connection_id, client_address, &mock_helper_, 353 &dispatcher_, config_, connection_id, client_address, &mock_helper_,
348 &mock_alarm_factory_, &crypto_config_, 354 &mock_alarm_factory_, &crypto_config_,
349 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_))); 355 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_)));
350 ProcessPacket(client_address, connection_id, true, false, "foo"); 356 ProcessPacket(client_address, connection_id, true, false, SerializeCHLO());
351 357
352 // Close the connection by sending public reset packet. 358 // Close the connection by sending public reset packet.
353 QuicPublicResetPacket packet; 359 QuicPublicResetPacket packet;
354 packet.public_header.connection_id = connection_id; 360 packet.public_header.connection_id = connection_id;
355 packet.public_header.reset_flag = true; 361 packet.public_header.reset_flag = true;
356 packet.public_header.version_flag = false; 362 packet.public_header.version_flag = false;
357 packet.rejected_packet_number = 19191; 363 packet.rejected_packet_number = 19191;
358 packet.nonce_proof = 132232; 364 packet.nonce_proof = 132232;
359 std::unique_ptr<QuicEncryptedPacket> encrypted( 365 std::unique_ptr<QuicEncryptedPacket> encrypted(
360 QuicFramer::BuildPublicResetPacket(packet)); 366 QuicFramer::BuildPublicResetPacket(packet));
(...skipping 13 matching lines...) Expand all
374 dispatcher_.ProcessPacket(IPEndPoint(), client_address, *received); 380 dispatcher_.ProcessPacket(IPEndPoint(), client_address, *received);
375 EXPECT_TRUE(time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); 381 EXPECT_TRUE(time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id));
376 382
377 // Dispatcher forwards subsequent packets for this connection_id to the time 383 // Dispatcher forwards subsequent packets for this connection_id to the time
378 // wait list manager. 384 // wait list manager.
379 EXPECT_CALL(*time_wait_list_manager_, 385 EXPECT_CALL(*time_wait_list_manager_,
380 ProcessPacket(_, _, connection_id, _, _)) 386 ProcessPacket(_, _, connection_id, _, _))
381 .Times(1); 387 .Times(1);
382 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) 388 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
383 .Times(0); 389 .Times(0);
384 ProcessPacket(client_address, connection_id, true, false, "foo"); 390 ProcessPacket(client_address, connection_id, true, false, "data");
385 } 391 }
386 392
387 TEST_F(QuicDispatcherTest, NoVersionPacketToTimeWaitListManager) { 393 TEST_F(QuicDispatcherTest, NoVersionPacketToTimeWaitListManager) {
388 CreateTimeWaitListManager(); 394 CreateTimeWaitListManager();
389 395
390 IPEndPoint client_address(net::test::Loopback4(), 1); 396 IPEndPoint client_address(net::test::Loopback4(), 1);
391 QuicConnectionId connection_id = 1; 397 QuicConnectionId connection_id = 1;
392 // Dispatcher forwards all packets for this connection_id to the time wait 398 // Dispatcher forwards all packets for this connection_id to the time wait
393 // list manager. 399 // list manager.
394 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _)).Times(0); 400 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _)).Times(0);
395 EXPECT_CALL(*time_wait_list_manager_, 401 EXPECT_CALL(*time_wait_list_manager_,
396 ProcessPacket(_, _, connection_id, _, _)) 402 ProcessPacket(_, _, connection_id, _, _))
397 .Times(1); 403 .Times(1);
398 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) 404 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
399 .Times(1); 405 .Times(1);
400 ProcessPacket(client_address, connection_id, false, false, "data"); 406 ProcessPacket(client_address, connection_id, false, false, SerializeCHLO());
407 }
408
409 TEST_F(QuicDispatcherTest, ProcessPacketWithZeroPort) {
410 CreateTimeWaitListManager();
411
412 IPEndPoint client_address(net::test::Loopback4(), 0);
413 server_address_ = IPEndPoint(net::test::Any4(), 5);
414
415 // dispatcher_ should drop this packet.
416 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)).Times(0);
417 EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _)).Times(0);
418 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
419 .Times(0);
420 ProcessPacket(client_address, 1, true, false, SerializeCHLO());
421 }
422
423 TEST_F(QuicDispatcherTest, OKSeqNoPacketProcessed) {
424 IPEndPoint client_address(net::test::Loopback4(), 1);
425 QuicConnectionId connection_id = 1;
426 server_address_ = IPEndPoint(net::test::Any4(), 5);
427
428 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address))
429 .WillOnce(testing::Return(CreateSession(
430 &dispatcher_, config_, 1, client_address, &mock_helper_,
431 &mock_alarm_factory_, &crypto_config_,
432 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_)));
433 // A packet whose packet number is the largest that is allowed to start a
434 // connection.
435 ProcessPacket(client_address, connection_id, true, false, SerializeCHLO(),
436 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER,
437 kDefaultPathId,
438 QuicDispatcher::kMaxReasonableInitialPacketNumber);
439 EXPECT_EQ(client_address, dispatcher_.current_client_address());
440 EXPECT_EQ(server_address_, dispatcher_.current_server_address());
441 }
442
443 TEST_F(QuicDispatcherTest, TooBigSeqNoPacketToTimeWaitListManager) {
444 CreateTimeWaitListManager();
445
446 IPEndPoint client_address(net::test::Loopback4(), 1);
447 QuicConnectionId connection_id = 1;
448 // Dispatcher forwards this packet for this connection_id to the time wait
449 // list manager.
450 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _)).Times(0);
451 EXPECT_CALL(*time_wait_list_manager_,
452 ProcessPacket(_, _, connection_id, _, _))
453 .Times(1);
454 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
455 .Times(1);
456 // A packet whose packet number is one to large to be allowed to start a
457 // connection.
458 ProcessPacket(client_address, connection_id, true, false, SerializeCHLO(),
459 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER,
460 kDefaultPathId,
461 QuicDispatcher::kMaxReasonableInitialPacketNumber + 1);
401 } 462 }
402 463
403 // Enables mocking of the handshake-confirmation for stateless rejects. 464 // Enables mocking of the handshake-confirmation for stateless rejects.
404 class MockQuicCryptoServerStream : public QuicCryptoServerStream { 465 class MockQuicCryptoServerStream : public QuicCryptoServerStream {
405 public: 466 public:
406 MockQuicCryptoServerStream(const QuicCryptoServerConfig& crypto_config, 467 MockQuicCryptoServerStream(const QuicCryptoServerConfig& crypto_config,
407 QuicCompressedCertsCache* compressed_certs_cache, 468 QuicCompressedCertsCache* compressed_certs_cache,
408 QuicSession* session) 469 QuicSession* session)
409 : QuicCryptoServerStream(&crypto_config, 470 : QuicCryptoServerStream(&crypto_config,
410 compressed_certs_cache, 471 compressed_certs_cache,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 crypto_stream1_->set_handshake_confirmed_for_testing( 564 crypto_stream1_->set_handshake_confirmed_for_testing(
504 GetParam().crypto_handshake_successful); 565 GetParam().crypto_handshake_successful);
505 crypto_stream1_->SetPeerSupportsStatelessRejects( 566 crypto_stream1_->SetPeerSupportsStatelessRejects(
506 GetParam().client_supports_statelesss_rejects); 567 GetParam().client_supports_statelesss_rejects);
507 return session1_; 568 return session1_;
508 } 569 }
509 570
510 MockQuicCryptoServerStream* crypto_stream1_; 571 MockQuicCryptoServerStream* crypto_stream1_;
511 }; 572 };
512 573
513 TEST_F(QuicDispatcherTest, ProcessPacketWithZeroPort) {
514 CreateTimeWaitListManager();
515
516 IPEndPoint client_address(net::test::Loopback4(), 0);
517 server_address_ = IPEndPoint(net::test::Any4(), 5);
518
519 // dispatcher_ should drop this packet.
520 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)).Times(0);
521 EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _)).Times(0);
522 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
523 .Times(0);
524 ProcessPacket(client_address, 1, true, false, "foo");
525 }
526
527 TEST_F(QuicDispatcherTest, OKSeqNoPacketProcessed) {
528 IPEndPoint client_address(net::test::Loopback4(), 1);
529 QuicConnectionId connection_id = 1;
530 server_address_ = IPEndPoint(net::test::Any4(), 5);
531
532 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address))
533 .WillOnce(testing::Return(CreateSession(
534 &dispatcher_, config_, 1, client_address, &mock_helper_,
535 &mock_alarm_factory_, &crypto_config_,
536 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_)));
537 // A packet whose packet number is the largest that is allowed to start a
538 // connection.
539 ProcessPacket(client_address, connection_id, true, false, "data",
540 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER,
541 kDefaultPathId,
542 QuicDispatcher::kMaxReasonableInitialPacketNumber);
543 EXPECT_EQ(client_address, dispatcher_.current_client_address());
544 EXPECT_EQ(server_address_, dispatcher_.current_server_address());
545 }
546
547 TEST_F(QuicDispatcherTest, TooBigSeqNoPacketToTimeWaitListManager) {
548 CreateTimeWaitListManager();
549
550 IPEndPoint client_address(net::test::Loopback4(), 1);
551 QuicConnectionId connection_id = 1;
552 // Dispatcher forwards this packet for this connection_id to the time wait
553 // list manager.
554 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _)).Times(0);
555 EXPECT_CALL(*time_wait_list_manager_,
556 ProcessPacket(_, _, connection_id, _, _))
557 .Times(1);
558 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
559 .Times(1);
560 // A packet whose packet number is one to large to be allowed to start a
561 // connection.
562 ProcessPacket(client_address, connection_id, true, false, "data",
563 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER,
564 kDefaultPathId,
565 QuicDispatcher::kMaxReasonableInitialPacketNumber + 1);
566 }
567
568 INSTANTIATE_TEST_CASE_P(QuicDispatcherStatelessRejectTests, 574 INSTANTIATE_TEST_CASE_P(QuicDispatcherStatelessRejectTests,
569 QuicDispatcherStatelessRejectTest, 575 QuicDispatcherStatelessRejectTest,
570 ::testing::ValuesIn(GetStatelessRejectTestParams())); 576 ::testing::ValuesIn(GetStatelessRejectTestParams()));
571 577
572 // Parameterized test for stateless rejects. Should test all 578 // Parameterized test for stateless rejects. Should test all
573 // combinations of enabling/disabling, reject/no-reject for stateless 579 // combinations of enabling/disabling, reject/no-reject for stateless
574 // rejects. 580 // rejects.
575 TEST_P(QuicDispatcherStatelessRejectTest, ParameterizedBasicTest) { 581 TEST_P(QuicDispatcherStatelessRejectTest, ParameterizedBasicTest) {
576 CreateTimeWaitListManager(); 582 CreateTimeWaitListManager();
577 583
578 IPEndPoint client_address(net::test::Loopback4(), 1); 584 IPEndPoint client_address(net::test::Loopback4(), 1);
579 QuicConnectionId connection_id = 1; 585 QuicConnectionId connection_id = 1;
580 EXPECT_CALL(dispatcher_, CreateQuicSession(connection_id, client_address)) 586 EXPECT_CALL(dispatcher_, CreateQuicSession(connection_id, client_address))
581 .WillOnce(testing::Return( 587 .WillOnce(testing::Return(
582 CreateSessionBasedOnTestParams(connection_id, client_address))); 588 CreateSessionBasedOnTestParams(connection_id, client_address)));
583 589
584 // Process the first packet for the connection. 590 // Process the first packet for the connection.
585 ProcessPacket(client_address, connection_id, true, false, "foo"); 591 ProcessPacket(client_address, connection_id, true, false, SerializeCHLO());
586 if (ExpectStatelessReject()) { 592 if (ExpectStatelessReject()) {
587 // If this is a stateless reject, the crypto stream will close the 593 // If this is a stateless reject, the crypto stream will close the
588 // connection. 594 // connection.
589 session1_->connection()->CloseConnection( 595 session1_->connection()->CloseConnection(
590 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, "stateless reject", 596 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, "stateless reject",
591 ConnectionCloseBehavior::SILENT_CLOSE); 597 ConnectionCloseBehavior::SILENT_CLOSE);
592 } 598 }
593 599
594 // Send a second packet and check the results. If this is a stateless reject, 600 // Send a second packet and check the results. If this is a stateless reject,
595 // the existing connection_id will go on the time-wait list. 601 // the existing connection_id will go on the time-wait list.
596 EXPECT_EQ(ExpectStatelessReject(), 602 EXPECT_EQ(ExpectStatelessReject(),
597 time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); 603 time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id));
598 if (ExpectStatelessReject()) { 604 if (ExpectStatelessReject()) {
599 // The second packet will be processed on the time-wait list. 605 // The second packet will be processed on the time-wait list.
600 EXPECT_CALL(*time_wait_list_manager_, 606 EXPECT_CALL(*time_wait_list_manager_,
601 ProcessPacket(_, _, connection_id, _, _)) 607 ProcessPacket(_, _, connection_id, _, _))
602 .Times(1); 608 .Times(1);
603 } else { 609 } else {
604 // The second packet will trigger a packet-validation 610 // The second packet will trigger a packet-validation
605 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), 611 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
606 ProcessUdpPacket(_, _, _)) 612 ProcessUdpPacket(_, _, _))
607 .Times(1) 613 .Times(1)
608 .WillOnce(testing::WithArgs<2>( 614 .WillOnce(testing::WithArgs<2>(
609 Invoke(this, &QuicDispatcherTest::ValidatePacket))); 615 Invoke(this, &QuicDispatcherTest::ValidatePacket)));
610 } 616 }
611 ProcessPacket(client_address, connection_id, true, false, "foo"); 617 ProcessPacket(client_address, connection_id, true, false, "data");
612 } 618 }
613 619
614 // Verify the stopgap test: Packets with truncated connection IDs should be 620 // Verify the stopgap test: Packets with truncated connection IDs should be
615 // dropped. 621 // dropped.
616 class QuicDispatcherTestStrayPacketConnectionId : public QuicDispatcherTest {}; 622 class QuicDispatcherTestStrayPacketConnectionId : public QuicDispatcherTest {};
617 623
618 // Packets with truncated connection IDs should be dropped. 624 // Packets with truncated connection IDs should be dropped.
619 TEST_F(QuicDispatcherTestStrayPacketConnectionId, 625 TEST_F(QuicDispatcherTestStrayPacketConnectionId,
620 StrayPacketTruncatedConnectionId) { 626 StrayPacketTruncatedConnectionId) {
621 CreateTimeWaitListManager(); 627 CreateTimeWaitListManager();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 writer_ = new BlockingWriter; 667 writer_ = new BlockingWriter;
662 QuicDispatcherPeer::UseWriter(&dispatcher_, writer_); 668 QuicDispatcherPeer::UseWriter(&dispatcher_, writer_);
663 669
664 IPEndPoint client_address(net::test::Loopback4(), 1); 670 IPEndPoint client_address(net::test::Loopback4(), 1);
665 671
666 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address)) 672 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address))
667 .WillOnce(testing::Return(CreateSession( 673 .WillOnce(testing::Return(CreateSession(
668 &dispatcher_, config_, 1, client_address, &helper_, &alarm_factory_, 674 &dispatcher_, config_, 1, client_address, &helper_, &alarm_factory_,
669 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_), 675 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_),
670 &session1_))); 676 &session1_)));
671 ProcessPacket(client_address, 1, true, false, "foo"); 677 ProcessPacket(client_address, 1, true, false, SerializeCHLO());
672 678
673 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address)) 679 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address))
674 .WillOnce(testing::Return(CreateSession( 680 .WillOnce(testing::Return(CreateSession(
675 &dispatcher_, config_, 2, client_address, &helper_, &alarm_factory_, 681 &dispatcher_, config_, 2, client_address, &helper_, &alarm_factory_,
676 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_), 682 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_),
677 &session2_))); 683 &session2_)));
678 ProcessPacket(client_address, 2, true, false, "bar"); 684 ProcessPacket(client_address, 2, true, false, SerializeCHLO());
679 685
680 blocked_list_ = QuicDispatcherPeer::GetWriteBlockedList(&dispatcher_); 686 blocked_list_ = QuicDispatcherPeer::GetWriteBlockedList(&dispatcher_);
681 } 687 }
682 688
683 void TearDown() override { 689 void TearDown() override {
684 EXPECT_CALL(*connection1(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); 690 EXPECT_CALL(*connection1(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _));
685 EXPECT_CALL(*connection2(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); 691 EXPECT_CALL(*connection2(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _));
686 dispatcher_.Shutdown(); 692 dispatcher_.Shutdown();
687 } 693 }
688 694
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 833
828 // And we'll resume where we left off when we get another call. 834 // And we'll resume where we left off when we get another call.
829 EXPECT_CALL(*connection2(), OnCanWrite()); 835 EXPECT_CALL(*connection2(), OnCanWrite());
830 dispatcher_.OnCanWrite(); 836 dispatcher_.OnCanWrite();
831 EXPECT_FALSE(dispatcher_.HasPendingWrites()); 837 EXPECT_FALSE(dispatcher_.HasPendingWrites());
832 } 838 }
833 839
834 } // namespace 840 } // namespace
835 } // namespace test 841 } // namespace test
836 } // namespace net 842 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698