| OLD | NEW |
| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <sys/epoll.h> | 6 #include <sys/epoll.h> |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 sequencer = ReliableQuicStreamPeer::sequencer(crypto_stream); | 648 sequencer = ReliableQuicStreamPeer::sequencer(crypto_stream); |
| 649 EXPECT_NE(FLAGS_quic_release_crypto_stream_buffer && | 649 EXPECT_NE(FLAGS_quic_release_crypto_stream_buffer && |
| 650 FLAGS_quic_reduce_sequencer_buffer_memory_life_time, | 650 FLAGS_quic_reduce_sequencer_buffer_memory_life_time, |
| 651 QuicStreamSequencerPeer::IsUnderlyingBufferAllocated(sequencer)); | 651 QuicStreamSequencerPeer::IsUnderlyingBufferAllocated(sequencer)); |
| 652 } | 652 } |
| 653 | 653 |
| 654 TEST_P(EndToEndTest, SimpleRequestResponse) { | 654 TEST_P(EndToEndTest, SimpleRequestResponse) { |
| 655 ASSERT_TRUE(Initialize()); | 655 ASSERT_TRUE(Initialize()); |
| 656 | 656 |
| 657 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 657 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 658 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 658 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 659 EXPECT_EQ(2, client_->client()->GetNumSentClientHellos()); | 659 EXPECT_EQ(2, client_->client()->GetNumSentClientHellos()); |
| 660 } | 660 } |
| 661 | 661 |
| 662 TEST_P(EndToEndTest, SimpleRequestResponseWithLargeReject) { | 662 TEST_P(EndToEndTest, SimpleRequestResponseWithLargeReject) { |
| 663 chlo_multiplier_ = 1; | 663 chlo_multiplier_ = 1; |
| 664 ASSERT_TRUE(Initialize()); | 664 ASSERT_TRUE(Initialize()); |
| 665 | 665 |
| 666 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 666 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 667 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 667 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 668 EXPECT_EQ(3, client_->client()->GetNumSentClientHellos()); | 668 EXPECT_EQ(3, client_->client()->GetNumSentClientHellos()); |
| 669 } | 669 } |
| 670 | 670 |
| 671 // TODO(rch): figure out how to detect missing v6 support (like on the linux | 671 // TODO(rch): figure out how to detect missing v6 support (like on the linux |
| 672 // try bots) and selectively disable this test. | 672 // try bots) and selectively disable this test. |
| 673 TEST_P(EndToEndTest, DISABLED_SimpleRequestResponsev6) { | 673 TEST_P(EndToEndTest, DISABLED_SimpleRequestResponsev6) { |
| 674 server_address_ = | 674 server_address_ = |
| 675 IPEndPoint(IPAddress::IPv6Localhost(), server_address_.port()); | 675 IPEndPoint(IPAddress::IPv6Localhost(), server_address_.port()); |
| 676 ASSERT_TRUE(Initialize()); | 676 ASSERT_TRUE(Initialize()); |
| 677 | 677 |
| 678 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 678 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 679 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 679 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 680 } | 680 } |
| 681 | 681 |
| 682 TEST_P(EndToEndTest, SeparateFinPacket) { | 682 TEST_P(EndToEndTest, SeparateFinPacket) { |
| 683 ASSERT_TRUE(Initialize()); | 683 ASSERT_TRUE(Initialize()); |
| 684 | 684 |
| 685 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 685 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
| 686 request.set_has_complete_message(false); | 686 request.set_has_complete_message(false); |
| 687 | 687 |
| 688 // Send a request in two parts: the request and then an empty packet with FIN. | 688 // Send a request in two parts: the request and then an empty packet with FIN. |
| 689 client_->SendMessage(request); | 689 client_->SendMessage(request); |
| 690 client_->SendData("", true); | 690 client_->SendData("", true); |
| 691 client_->WaitForResponse(); | 691 client_->WaitForResponse(); |
| 692 EXPECT_EQ(kFooResponseBody, client_->response_body()); | 692 EXPECT_EQ(kFooResponseBody, client_->response_body()); |
| 693 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 693 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 694 | 694 |
| 695 // Now do the same thing but with a content length. | 695 // Now do the same thing but with a content length. |
| 696 request.AddBody("foo", true); | 696 request.AddBody("foo", true); |
| 697 client_->SendMessage(request); | 697 client_->SendMessage(request); |
| 698 client_->SendData("", true); | 698 client_->SendData("", true); |
| 699 client_->WaitForResponse(); | 699 client_->WaitForResponse(); |
| 700 EXPECT_EQ(kFooResponseBody, client_->response_body()); | 700 EXPECT_EQ(kFooResponseBody, client_->response_body()); |
| 701 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 701 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 702 } | 702 } |
| 703 | 703 |
| 704 TEST_P(EndToEndTest, MultipleRequestResponse) { | 704 TEST_P(EndToEndTest, MultipleRequestResponse) { |
| 705 ASSERT_TRUE(Initialize()); | 705 ASSERT_TRUE(Initialize()); |
| 706 | 706 |
| 707 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 707 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 708 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 708 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 709 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar")); | 709 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar")); |
| 710 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 710 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 711 } | 711 } |
| 712 | 712 |
| 713 TEST_P(EndToEndTest, MultipleClients) { | 713 TEST_P(EndToEndTest, MultipleClients) { |
| 714 ASSERT_TRUE(Initialize()); | 714 ASSERT_TRUE(Initialize()); |
| 715 std::unique_ptr<QuicTestClient> client2(CreateQuicClient(nullptr)); | 715 std::unique_ptr<QuicTestClient> client2(CreateQuicClient(nullptr)); |
| 716 | 716 |
| 717 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 717 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
| 718 request.AddHeader("content-length", "3"); | 718 request.AddHeader("content-length", "3"); |
| 719 request.set_has_complete_message(false); | 719 request.set_has_complete_message(false); |
| 720 | 720 |
| 721 client_->SendMessage(request); | 721 client_->SendMessage(request); |
| 722 client2->SendMessage(request); | 722 client2->SendMessage(request); |
| 723 | 723 |
| 724 client_->SendData("bar", true); | 724 client_->SendData("bar", true); |
| 725 client_->WaitForResponse(); | 725 client_->WaitForResponse(); |
| 726 EXPECT_EQ(kFooResponseBody, client_->response_body()); | 726 EXPECT_EQ(kFooResponseBody, client_->response_body()); |
| 727 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 727 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 728 | 728 |
| 729 client2->SendData("eep", true); | 729 client2->SendData("eep", true); |
| 730 client2->WaitForResponse(); | 730 client2->WaitForResponse(); |
| 731 EXPECT_EQ(kFooResponseBody, client2->response_body()); | 731 EXPECT_EQ(kFooResponseBody, client2->response_body()); |
| 732 EXPECT_EQ(200u, client2->response_headers()->parsed_response_code()); | 732 EXPECT_EQ("200", client2->response_headers()->find(":status")->second); |
| 733 } | 733 } |
| 734 | 734 |
| 735 TEST_P(EndToEndTest, RequestOverMultiplePackets) { | 735 TEST_P(EndToEndTest, RequestOverMultiplePackets) { |
| 736 // Send a large enough request to guarantee fragmentation. | 736 // Send a large enough request to guarantee fragmentation. |
| 737 string huge_request = "/some/path?query=" + string(kMaxPacketSize, '.'); | 737 string huge_request = "/some/path?query=" + string(kMaxPacketSize, '.'); |
| 738 AddToCache(huge_request, 200, kBarResponseBody); | 738 AddToCache(huge_request, 200, kBarResponseBody); |
| 739 | 739 |
| 740 ASSERT_TRUE(Initialize()); | 740 ASSERT_TRUE(Initialize()); |
| 741 | 741 |
| 742 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest(huge_request)); | 742 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest(huge_request)); |
| 743 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 743 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 744 } | 744 } |
| 745 | 745 |
| 746 TEST_P(EndToEndTest, MultiplePacketsRandomOrder) { | 746 TEST_P(EndToEndTest, MultiplePacketsRandomOrder) { |
| 747 // Send a large enough request to guarantee fragmentation. | 747 // Send a large enough request to guarantee fragmentation. |
| 748 string huge_request = "/some/path?query=" + string(kMaxPacketSize, '.'); | 748 string huge_request = "/some/path?query=" + string(kMaxPacketSize, '.'); |
| 749 AddToCache(huge_request, 200, kBarResponseBody); | 749 AddToCache(huge_request, 200, kBarResponseBody); |
| 750 | 750 |
| 751 ASSERT_TRUE(Initialize()); | 751 ASSERT_TRUE(Initialize()); |
| 752 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); | 752 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); |
| 753 SetReorderPercentage(50); | 753 SetReorderPercentage(50); |
| 754 | 754 |
| 755 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest(huge_request)); | 755 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest(huge_request)); |
| 756 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 756 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 757 } | 757 } |
| 758 | 758 |
| 759 TEST_P(EndToEndTest, PostMissingBytes) { | 759 TEST_P(EndToEndTest, PostMissingBytes) { |
| 760 ASSERT_TRUE(Initialize()); | 760 ASSERT_TRUE(Initialize()); |
| 761 | 761 |
| 762 // Add a content length header with no body. | 762 // Add a content length header with no body. |
| 763 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 763 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
| 764 request.AddHeader("content-length", "3"); | 764 request.AddHeader("content-length", "3"); |
| 765 request.set_skip_message_validation(true); | 765 request.set_skip_message_validation(true); |
| 766 | 766 |
| 767 // This should be detected as stream fin without complete request, | 767 // This should be detected as stream fin without complete request, |
| 768 // triggering an error response. | 768 // triggering an error response. |
| 769 client_->SendCustomSynchronousRequest(request); | 769 client_->SendCustomSynchronousRequest(request); |
| 770 EXPECT_EQ(QuicSimpleServerStream::kErrorResponseBody, | 770 EXPECT_EQ(QuicSimpleServerStream::kErrorResponseBody, |
| 771 client_->response_body()); | 771 client_->response_body()); |
| 772 EXPECT_EQ(500u, client_->response_headers()->parsed_response_code()); | 772 EXPECT_EQ("500", client_->response_headers()->find(":status")->second); |
| 773 } | 773 } |
| 774 | 774 |
| 775 TEST_P(EndToEndTest, LargePostNoPacketLoss) { | 775 TEST_P(EndToEndTest, LargePostNoPacketLoss) { |
| 776 ASSERT_TRUE(Initialize()); | 776 ASSERT_TRUE(Initialize()); |
| 777 | 777 |
| 778 client_->client()->WaitForCryptoHandshakeConfirmed(); | 778 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 779 | 779 |
| 780 // 1 MB body. | 780 // 1 MB body. |
| 781 string body; | 781 string body; |
| 782 GenerateBody(&body, 1024 * 1024); | 782 GenerateBody(&body, 1024 * 1024); |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 request.AddHeader("key2", string(15 * 1024, 'a')); | 1195 request.AddHeader("key2", string(15 * 1024, 'a')); |
| 1196 request.AddHeader("key3", string(15 * 1024, 'a')); | 1196 request.AddHeader("key3", string(15 * 1024, 'a')); |
| 1197 request.AddBody(body, true); | 1197 request.AddBody(body, true); |
| 1198 | 1198 |
| 1199 client_->SendCustomSynchronousRequest(request); | 1199 client_->SendCustomSynchronousRequest(request); |
| 1200 if (FLAGS_quic_limit_uncompressed_headers) { | 1200 if (FLAGS_quic_limit_uncompressed_headers) { |
| 1201 EXPECT_EQ(QUIC_HEADERS_TOO_LARGE, client_->stream_error()); | 1201 EXPECT_EQ(QUIC_HEADERS_TOO_LARGE, client_->stream_error()); |
| 1202 } else { | 1202 } else { |
| 1203 EXPECT_EQ(QUIC_STREAM_NO_ERROR, client_->stream_error()); | 1203 EXPECT_EQ(QUIC_STREAM_NO_ERROR, client_->stream_error()); |
| 1204 EXPECT_EQ(kFooResponseBody, client_->response_body()); | 1204 EXPECT_EQ(kFooResponseBody, client_->response_body()); |
| 1205 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 1205 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 1206 } | 1206 } |
| 1207 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); | 1207 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); |
| 1208 } | 1208 } |
| 1209 | 1209 |
| 1210 TEST_P(EndToEndTest, EarlyResponseWithQuicStreamNoError) { | 1210 TEST_P(EndToEndTest, EarlyResponseWithQuicStreamNoError) { |
| 1211 ASSERT_TRUE(Initialize()); | 1211 ASSERT_TRUE(Initialize()); |
| 1212 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1212 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 1213 | 1213 |
| 1214 string large_body; | 1214 string large_body; |
| 1215 GenerateBody(&large_body, 1024 * 1024); | 1215 GenerateBody(&large_body, 1024 * 1024); |
| 1216 | 1216 |
| 1217 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 1217 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
| 1218 request.AddBody(large_body, false); | 1218 request.AddBody(large_body, false); |
| 1219 | 1219 |
| 1220 // Insert an invalid content_length field in request to trigger an early | 1220 // Insert an invalid content_length field in request to trigger an early |
| 1221 // response from server. | 1221 // response from server. |
| 1222 request.AddHeader("content-length", "-3"); | 1222 request.AddHeader("content-length", "-3"); |
| 1223 | 1223 |
| 1224 request.set_skip_message_validation(true); | 1224 request.set_skip_message_validation(true); |
| 1225 client_->SendCustomSynchronousRequest(request); | 1225 client_->SendCustomSynchronousRequest(request); |
| 1226 EXPECT_EQ("bad", client_->response_body()); | 1226 EXPECT_EQ("bad", client_->response_body()); |
| 1227 EXPECT_EQ(500u, client_->response_headers()->parsed_response_code()); | 1227 EXPECT_EQ("500", client_->response_headers()->find(":status")->second); |
| 1228 EXPECT_EQ(QUIC_STREAM_NO_ERROR, client_->stream_error()); | 1228 EXPECT_EQ(QUIC_STREAM_NO_ERROR, client_->stream_error()); |
| 1229 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); | 1229 EXPECT_EQ(QUIC_NO_ERROR, client_->connection_error()); |
| 1230 } | 1230 } |
| 1231 | 1231 |
| 1232 // TODO(rch): this test seems to cause net_unittests timeouts :| | 1232 // TODO(rch): this test seems to cause net_unittests timeouts :| |
| 1233 TEST_P(EndToEndTest, DISABLED_MultipleTermination) { | 1233 TEST_P(EndToEndTest, DISABLED_MultipleTermination) { |
| 1234 ASSERT_TRUE(Initialize()); | 1234 ASSERT_TRUE(Initialize()); |
| 1235 | 1235 |
| 1236 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); | 1236 HTTPMessage request(HttpConstants::HTTP_1_1, HttpConstants::POST, "/foo"); |
| 1237 request.AddHeader("content-length", "3"); | 1237 request.AddHeader("content-length", "3"); |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1499 client_sent_packet_manager.BandwidthEstimate(); | 1499 client_sent_packet_manager.BandwidthEstimate(); |
| 1500 server_sent_packet_manager.BandwidthEstimate(); | 1500 server_sent_packet_manager.BandwidthEstimate(); |
| 1501 server_thread_->Resume(); | 1501 server_thread_->Resume(); |
| 1502 } | 1502 } |
| 1503 | 1503 |
| 1504 TEST_P(EndToEndTest, 0ByteConnectionId) { | 1504 TEST_P(EndToEndTest, 0ByteConnectionId) { |
| 1505 client_config_.SetBytesForConnectionIdToSend(0); | 1505 client_config_.SetBytesForConnectionIdToSend(0); |
| 1506 ASSERT_TRUE(Initialize()); | 1506 ASSERT_TRUE(Initialize()); |
| 1507 | 1507 |
| 1508 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 1508 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 1509 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 1509 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 1510 | 1510 |
| 1511 QuicPacketHeader* header = QuicConnectionPeer::GetLastHeader( | 1511 QuicPacketHeader* header = QuicConnectionPeer::GetLastHeader( |
| 1512 client_->client()->session()->connection()); | 1512 client_->client()->session()->connection()); |
| 1513 EXPECT_EQ(PACKET_0BYTE_CONNECTION_ID, | 1513 EXPECT_EQ(PACKET_0BYTE_CONNECTION_ID, |
| 1514 header->public_header.connection_id_length); | 1514 header->public_header.connection_id_length); |
| 1515 } | 1515 } |
| 1516 | 1516 |
| 1517 TEST_P(EndToEndTest, 8ByteConnectionId) { | 1517 TEST_P(EndToEndTest, 8ByteConnectionId) { |
| 1518 client_config_.SetBytesForConnectionIdToSend(8); | 1518 client_config_.SetBytesForConnectionIdToSend(8); |
| 1519 ASSERT_TRUE(Initialize()); | 1519 ASSERT_TRUE(Initialize()); |
| 1520 | 1520 |
| 1521 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 1521 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 1522 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 1522 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 1523 QuicPacketHeader* header = QuicConnectionPeer::GetLastHeader( | 1523 QuicPacketHeader* header = QuicConnectionPeer::GetLastHeader( |
| 1524 client_->client()->session()->connection()); | 1524 client_->client()->session()->connection()); |
| 1525 EXPECT_EQ(PACKET_8BYTE_CONNECTION_ID, | 1525 EXPECT_EQ(PACKET_8BYTE_CONNECTION_ID, |
| 1526 header->public_header.connection_id_length); | 1526 header->public_header.connection_id_length); |
| 1527 } | 1527 } |
| 1528 | 1528 |
| 1529 TEST_P(EndToEndTest, 15ByteConnectionId) { | 1529 TEST_P(EndToEndTest, 15ByteConnectionId) { |
| 1530 client_config_.SetBytesForConnectionIdToSend(15); | 1530 client_config_.SetBytesForConnectionIdToSend(15); |
| 1531 ASSERT_TRUE(Initialize()); | 1531 ASSERT_TRUE(Initialize()); |
| 1532 | 1532 |
| 1533 // Our server is permissive and allows for out of bounds values. | 1533 // Our server is permissive and allows for out of bounds values. |
| 1534 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 1534 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 1535 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 1535 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 1536 QuicPacketHeader* header = QuicConnectionPeer::GetLastHeader( | 1536 QuicPacketHeader* header = QuicConnectionPeer::GetLastHeader( |
| 1537 client_->client()->session()->connection()); | 1537 client_->client()->session()->connection()); |
| 1538 EXPECT_EQ(PACKET_8BYTE_CONNECTION_ID, | 1538 EXPECT_EQ(PACKET_8BYTE_CONNECTION_ID, |
| 1539 header->public_header.connection_id_length); | 1539 header->public_header.connection_id_length); |
| 1540 } | 1540 } |
| 1541 | 1541 |
| 1542 TEST_P(EndToEndTest, ResetConnection) { | 1542 TEST_P(EndToEndTest, ResetConnection) { |
| 1543 ASSERT_TRUE(Initialize()); | 1543 ASSERT_TRUE(Initialize()); |
| 1544 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1544 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 1545 | 1545 |
| 1546 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 1546 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 1547 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 1547 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 1548 client_->ResetConnection(); | 1548 client_->ResetConnection(); |
| 1549 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar")); | 1549 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar")); |
| 1550 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 1550 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 1551 } | 1551 } |
| 1552 | 1552 |
| 1553 TEST_P(EndToEndTest, MaxStreamsUberTest) { | 1553 TEST_P(EndToEndTest, MaxStreamsUberTest) { |
| 1554 if (!BothSidesSupportStatelessRejects()) { | 1554 if (!BothSidesSupportStatelessRejects()) { |
| 1555 // Connect with lower fake packet loss than we'd like to test. Until | 1555 // Connect with lower fake packet loss than we'd like to test. Until |
| 1556 // b/10126687 is fixed, losing handshake packets is pretty brutal. | 1556 // b/10126687 is fixed, losing handshake packets is pretty brutal. |
| 1557 // TODO(jokulik): Until we support redundant SREJ packets, don't | 1557 // TODO(jokulik): Until we support redundant SREJ packets, don't |
| 1558 // drop handshake packets for stateless rejects. | 1558 // drop handshake packets for stateless rejects. |
| 1559 SetPacketLossPercentage(1); | 1559 SetPacketLossPercentage(1); |
| 1560 } | 1560 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1624 | 1624 |
| 1625 bool IsWriteBlockedDataBuffered() const override { return false; } | 1625 bool IsWriteBlockedDataBuffered() const override { return false; } |
| 1626 | 1626 |
| 1627 IPEndPoint self_address_; | 1627 IPEndPoint self_address_; |
| 1628 }; | 1628 }; |
| 1629 | 1629 |
| 1630 TEST_P(EndToEndTest, ConnectionMigrationClientIPChanged) { | 1630 TEST_P(EndToEndTest, ConnectionMigrationClientIPChanged) { |
| 1631 ASSERT_TRUE(Initialize()); | 1631 ASSERT_TRUE(Initialize()); |
| 1632 | 1632 |
| 1633 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 1633 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 1634 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 1634 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 1635 | 1635 |
| 1636 // Store the client IP address which was used to send the first request. | 1636 // Store the client IP address which was used to send the first request. |
| 1637 IPAddress old_host = client_->client()->GetLatestClientAddress().address(); | 1637 IPAddress old_host = client_->client()->GetLatestClientAddress().address(); |
| 1638 | 1638 |
| 1639 // Migrate socket to the new IP address. | 1639 // Migrate socket to the new IP address. |
| 1640 IPAddress new_host(127, 0, 0, 2); | 1640 IPAddress new_host(127, 0, 0, 2); |
| 1641 EXPECT_NE(old_host, new_host); | 1641 EXPECT_NE(old_host, new_host); |
| 1642 ASSERT_TRUE(client_->client()->MigrateSocket(new_host)); | 1642 ASSERT_TRUE(client_->client()->MigrateSocket(new_host)); |
| 1643 | 1643 |
| 1644 // Send a request using the new socket. | 1644 // Send a request using the new socket. |
| 1645 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar")); | 1645 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar")); |
| 1646 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 1646 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 1647 } | 1647 } |
| 1648 | 1648 |
| 1649 TEST_P(EndToEndTest, ConnectionMigrationClientPortChanged) { | 1649 TEST_P(EndToEndTest, ConnectionMigrationClientPortChanged) { |
| 1650 // Tests that the client's port can change during an established QUIC | 1650 // Tests that the client's port can change during an established QUIC |
| 1651 // connection, and that doing so does not result in the connection being | 1651 // connection, and that doing so does not result in the connection being |
| 1652 // closed by the server. | 1652 // closed by the server. |
| 1653 ASSERT_TRUE(Initialize()); | 1653 ASSERT_TRUE(Initialize()); |
| 1654 | 1654 |
| 1655 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 1655 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 1656 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 1656 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 1657 | 1657 |
| 1658 // Store the client address which was used to send the first request. | 1658 // Store the client address which was used to send the first request. |
| 1659 IPEndPoint old_address = client_->client()->GetLatestClientAddress(); | 1659 IPEndPoint old_address = client_->client()->GetLatestClientAddress(); |
| 1660 int old_fd = client_->client()->GetLatestFD(); | 1660 int old_fd = client_->client()->GetLatestFD(); |
| 1661 | 1661 |
| 1662 // Create a new socket before closing the old one, which will result in a new | 1662 // Create a new socket before closing the old one, which will result in a new |
| 1663 // ephemeral port. | 1663 // ephemeral port. |
| 1664 QuicClientPeer::CreateUDPSocketAndBind(client_->client()); | 1664 QuicClientPeer::CreateUDPSocketAndBind(client_->client()); |
| 1665 | 1665 |
| 1666 // Stop listening and close the old FD. | 1666 // Stop listening and close the old FD. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1682 client_->client()->session()->connection()->self_address().address(), | 1682 client_->client()->session()->connection()->self_address().address(), |
| 1683 new_port)); | 1683 new_port)); |
| 1684 | 1684 |
| 1685 // Register the new FD for epoll events. | 1685 // Register the new FD for epoll events. |
| 1686 int new_fd = client_->client()->GetLatestFD(); | 1686 int new_fd = client_->client()->GetLatestFD(); |
| 1687 EpollServer* eps = client_->epoll_server(); | 1687 EpollServer* eps = client_->epoll_server(); |
| 1688 eps->RegisterFD(new_fd, client_->client(), EPOLLIN | EPOLLOUT | EPOLLET); | 1688 eps->RegisterFD(new_fd, client_->client(), EPOLLIN | EPOLLOUT | EPOLLET); |
| 1689 | 1689 |
| 1690 // Send a second request, using the new FD. | 1690 // Send a second request, using the new FD. |
| 1691 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar")); | 1691 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar")); |
| 1692 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 1692 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 1693 | 1693 |
| 1694 // Verify that the client's ephemeral port is different. | 1694 // Verify that the client's ephemeral port is different. |
| 1695 IPEndPoint new_address = client_->client()->GetLatestClientAddress(); | 1695 IPEndPoint new_address = client_->client()->GetLatestClientAddress(); |
| 1696 EXPECT_EQ(old_address.address(), new_address.address()); | 1696 EXPECT_EQ(old_address.address(), new_address.address()); |
| 1697 EXPECT_NE(old_address.port(), new_address.port()); | 1697 EXPECT_NE(old_address.port(), new_address.port()); |
| 1698 } | 1698 } |
| 1699 | 1699 |
| 1700 TEST_P(EndToEndTest, DifferentFlowControlWindows) { | 1700 TEST_P(EndToEndTest, DifferentFlowControlWindows) { |
| 1701 // Client and server can set different initial flow control receive windows. | 1701 // Client and server can set different initial flow control receive windows. |
| 1702 // These are sent in CHLO/SHLO. Tests that these values are exchanged properly | 1702 // These are sent in CHLO/SHLO. Tests that these values are exchanged properly |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1842 } | 1842 } |
| 1843 | 1843 |
| 1844 TEST_P(EndToEndTest, RequestWithNoBodyWillNeverSendStreamFrameWithFIN) { | 1844 TEST_P(EndToEndTest, RequestWithNoBodyWillNeverSendStreamFrameWithFIN) { |
| 1845 // A stream created on receipt of a simple request with no body will never get | 1845 // A stream created on receipt of a simple request with no body will never get |
| 1846 // a stream frame with a FIN. Verify that we don't keep track of the stream in | 1846 // a stream frame with a FIN. Verify that we don't keep track of the stream in |
| 1847 // the locally closed streams map: it will never be removed if so. | 1847 // the locally closed streams map: it will never be removed if so. |
| 1848 ASSERT_TRUE(Initialize()); | 1848 ASSERT_TRUE(Initialize()); |
| 1849 | 1849 |
| 1850 // Send a simple headers only request, and receive response. | 1850 // Send a simple headers only request, and receive response. |
| 1851 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 1851 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 1852 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 1852 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 1853 | 1853 |
| 1854 // Now verify that the server is not waiting for a final FIN or RST. | 1854 // Now verify that the server is not waiting for a final FIN or RST. |
| 1855 server_thread_->Pause(); | 1855 server_thread_->Pause(); |
| 1856 QuicDispatcher* dispatcher = | 1856 QuicDispatcher* dispatcher = |
| 1857 QuicServerPeer::GetDispatcher(server_thread_->server()); | 1857 QuicServerPeer::GetDispatcher(server_thread_->server()); |
| 1858 QuicSession* session = dispatcher->session_map().begin()->second.get(); | 1858 QuicSession* session = dispatcher->session_map().begin()->second.get(); |
| 1859 EXPECT_EQ( | 1859 EXPECT_EQ( |
| 1860 0u, | 1860 0u, |
| 1861 QuicSessionPeer::GetLocallyClosedStreamsHighestOffset(session).size()); | 1861 QuicSessionPeer::GetLocallyClosedStreamsHighestOffset(session).size()); |
| 1862 server_thread_->Resume(); | 1862 server_thread_->Resume(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1924 | 1924 |
| 1925 // Test the AckNotifier's ability to track multiple packets by making the | 1925 // Test the AckNotifier's ability to track multiple packets by making the |
| 1926 // request body exceed the size of a single packet. | 1926 // request body exceed the size of a single packet. |
| 1927 string request_string = | 1927 string request_string = |
| 1928 "a request body bigger than one packet" + string(kMaxPacketSize, '.'); | 1928 "a request body bigger than one packet" + string(kMaxPacketSize, '.'); |
| 1929 | 1929 |
| 1930 // Send the request, and register the delegate for ACKs. | 1930 // Send the request, and register the delegate for ACKs. |
| 1931 client_->SendData(request_string, true, delegate.get()); | 1931 client_->SendData(request_string, true, delegate.get()); |
| 1932 client_->WaitForResponse(); | 1932 client_->WaitForResponse(); |
| 1933 EXPECT_EQ(kFooResponseBody, client_->response_body()); | 1933 EXPECT_EQ(kFooResponseBody, client_->response_body()); |
| 1934 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 1934 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 1935 | 1935 |
| 1936 // Send another request to flush out any pending ACKs on the server. | 1936 // Send another request to flush out any pending ACKs on the server. |
| 1937 client_->SendSynchronousRequest("/bar"); | 1937 client_->SendSynchronousRequest("/bar"); |
| 1938 | 1938 |
| 1939 // Pause the server to avoid races. | 1939 // Pause the server to avoid races. |
| 1940 server_thread_->Pause(); | 1940 server_thread_->Pause(); |
| 1941 // Make sure the delegate does get the notification it expects. | 1941 // Make sure the delegate does get the notification it expects. |
| 1942 while (!delegate->has_been_notified()) { | 1942 while (!delegate->has_been_notified()) { |
| 1943 // Waits for up to 50 ms. | 1943 // Waits for up to 50 ms. |
| 1944 client_->client()->WaitForEvents(); | 1944 client_->client()->WaitForEvents(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1965 // We must pause the server's thread in order to call WritePacket without | 1965 // We must pause the server's thread in order to call WritePacket without |
| 1966 // race conditions. | 1966 // race conditions. |
| 1967 server_thread_->Pause(); | 1967 server_thread_->Pause(); |
| 1968 server_writer_->WritePacket( | 1968 server_writer_->WritePacket( |
| 1969 packet->data(), packet->length(), server_address_.address(), | 1969 packet->data(), packet->length(), server_address_.address(), |
| 1970 client_->client()->GetLatestClientAddress(), nullptr); | 1970 client_->client()->GetLatestClientAddress(), nullptr); |
| 1971 server_thread_->Resume(); | 1971 server_thread_->Resume(); |
| 1972 | 1972 |
| 1973 // The request should fail. | 1973 // The request should fail. |
| 1974 EXPECT_EQ("", client_->SendSynchronousRequest("/foo")); | 1974 EXPECT_EQ("", client_->SendSynchronousRequest("/foo")); |
| 1975 EXPECT_EQ(0u, client_->response_headers()->parsed_response_code()); | 1975 EXPECT_TRUE(client_->response_headers()->empty()); |
| 1976 EXPECT_EQ(QUIC_PUBLIC_RESET, client_->connection_error()); | 1976 EXPECT_EQ(QUIC_PUBLIC_RESET, client_->connection_error()); |
| 1977 } | 1977 } |
| 1978 | 1978 |
| 1979 // Send a public reset from the server for a different connection ID. | 1979 // Send a public reset from the server for a different connection ID. |
| 1980 // It should be ignored. | 1980 // It should be ignored. |
| 1981 TEST_P(EndToEndTest, ServerSendPublicResetWithDifferentConnectionId) { | 1981 TEST_P(EndToEndTest, ServerSendPublicResetWithDifferentConnectionId) { |
| 1982 ASSERT_TRUE(Initialize()); | 1982 ASSERT_TRUE(Initialize()); |
| 1983 | 1983 |
| 1984 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1984 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 1985 | 1985 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2002 // We must pause the server's thread in order to call WritePacket without | 2002 // We must pause the server's thread in order to call WritePacket without |
| 2003 // race conditions. | 2003 // race conditions. |
| 2004 server_thread_->Pause(); | 2004 server_thread_->Pause(); |
| 2005 server_writer_->WritePacket( | 2005 server_writer_->WritePacket( |
| 2006 packet->data(), packet->length(), server_address_.address(), | 2006 packet->data(), packet->length(), server_address_.address(), |
| 2007 client_->client()->GetLatestClientAddress(), nullptr); | 2007 client_->client()->GetLatestClientAddress(), nullptr); |
| 2008 server_thread_->Resume(); | 2008 server_thread_->Resume(); |
| 2009 | 2009 |
| 2010 // The connection should be unaffected. | 2010 // The connection should be unaffected. |
| 2011 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 2011 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 2012 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 2012 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 2013 | 2013 |
| 2014 client_->client()->session()->connection()->set_debug_visitor(nullptr); | 2014 client_->client()->session()->connection()->set_debug_visitor(nullptr); |
| 2015 } | 2015 } |
| 2016 | 2016 |
| 2017 // Send a public reset from the client for a different connection ID. | 2017 // Send a public reset from the client for a different connection ID. |
| 2018 // It should be ignored. | 2018 // It should be ignored. |
| 2019 TEST_P(EndToEndTest, ClientSendPublicResetWithDifferentConnectionId) { | 2019 TEST_P(EndToEndTest, ClientSendPublicResetWithDifferentConnectionId) { |
| 2020 ASSERT_TRUE(Initialize()); | 2020 ASSERT_TRUE(Initialize()); |
| 2021 | 2021 |
| 2022 // Send the public reset. | 2022 // Send the public reset. |
| 2023 QuicConnectionId incorrect_connection_id = | 2023 QuicConnectionId incorrect_connection_id = |
| 2024 client_->client()->session()->connection()->connection_id() + 1; | 2024 client_->client()->session()->connection()->connection_id() + 1; |
| 2025 QuicPublicResetPacket header; | 2025 QuicPublicResetPacket header; |
| 2026 header.public_header.connection_id = incorrect_connection_id; | 2026 header.public_header.connection_id = incorrect_connection_id; |
| 2027 header.public_header.reset_flag = true; | 2027 header.public_header.reset_flag = true; |
| 2028 header.public_header.version_flag = false; | 2028 header.public_header.version_flag = false; |
| 2029 header.rejected_packet_number = 10101; | 2029 header.rejected_packet_number = 10101; |
| 2030 QuicFramer framer(server_supported_versions_, QuicTime::Zero(), | 2030 QuicFramer framer(server_supported_versions_, QuicTime::Zero(), |
| 2031 Perspective::IS_CLIENT); | 2031 Perspective::IS_CLIENT); |
| 2032 std::unique_ptr<QuicEncryptedPacket> packet( | 2032 std::unique_ptr<QuicEncryptedPacket> packet( |
| 2033 framer.BuildPublicResetPacket(header)); | 2033 framer.BuildPublicResetPacket(header)); |
| 2034 client_writer_->WritePacket( | 2034 client_writer_->WritePacket( |
| 2035 packet->data(), packet->length(), | 2035 packet->data(), packet->length(), |
| 2036 client_->client()->GetLatestClientAddress().address(), server_address_, | 2036 client_->client()->GetLatestClientAddress().address(), server_address_, |
| 2037 nullptr); | 2037 nullptr); |
| 2038 | 2038 |
| 2039 // The connection should be unaffected. | 2039 // The connection should be unaffected. |
| 2040 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 2040 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 2041 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 2041 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 2042 } | 2042 } |
| 2043 | 2043 |
| 2044 // Send a version negotiation packet from the server for a different | 2044 // Send a version negotiation packet from the server for a different |
| 2045 // connection ID. It should be ignored. | 2045 // connection ID. It should be ignored. |
| 2046 TEST_P(EndToEndTest, ServerSendVersionNegotiationWithDifferentConnectionId) { | 2046 TEST_P(EndToEndTest, ServerSendVersionNegotiationWithDifferentConnectionId) { |
| 2047 ASSERT_TRUE(Initialize()); | 2047 ASSERT_TRUE(Initialize()); |
| 2048 | 2048 |
| 2049 client_->client()->WaitForCryptoHandshakeConfirmed(); | 2049 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 2050 | 2050 |
| 2051 // Send the version negotiation packet. | 2051 // Send the version negotiation packet. |
| 2052 QuicConnectionId incorrect_connection_id = | 2052 QuicConnectionId incorrect_connection_id = |
| 2053 client_->client()->session()->connection()->connection_id() + 1; | 2053 client_->client()->session()->connection()->connection_id() + 1; |
| 2054 std::unique_ptr<QuicEncryptedPacket> packet( | 2054 std::unique_ptr<QuicEncryptedPacket> packet( |
| 2055 QuicFramer::BuildVersionNegotiationPacket(incorrect_connection_id, | 2055 QuicFramer::BuildVersionNegotiationPacket(incorrect_connection_id, |
| 2056 server_supported_versions_)); | 2056 server_supported_versions_)); |
| 2057 testing::NiceMock<MockQuicConnectionDebugVisitor> visitor; | 2057 testing::NiceMock<MockQuicConnectionDebugVisitor> visitor; |
| 2058 client_->client()->session()->connection()->set_debug_visitor(&visitor); | 2058 client_->client()->session()->connection()->set_debug_visitor(&visitor); |
| 2059 EXPECT_CALL(visitor, OnIncorrectConnectionId(incorrect_connection_id)) | 2059 EXPECT_CALL(visitor, OnIncorrectConnectionId(incorrect_connection_id)) |
| 2060 .Times(1); | 2060 .Times(1); |
| 2061 // We must pause the server's thread in order to call WritePacket without | 2061 // We must pause the server's thread in order to call WritePacket without |
| 2062 // race conditions. | 2062 // race conditions. |
| 2063 server_thread_->Pause(); | 2063 server_thread_->Pause(); |
| 2064 server_writer_->WritePacket( | 2064 server_writer_->WritePacket( |
| 2065 packet->data(), packet->length(), server_address_.address(), | 2065 packet->data(), packet->length(), server_address_.address(), |
| 2066 client_->client()->GetLatestClientAddress(), nullptr); | 2066 client_->client()->GetLatestClientAddress(), nullptr); |
| 2067 server_thread_->Resume(); | 2067 server_thread_->Resume(); |
| 2068 | 2068 |
| 2069 // The connection should be unaffected. | 2069 // The connection should be unaffected. |
| 2070 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 2070 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 2071 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 2071 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 2072 | 2072 |
| 2073 client_->client()->session()->connection()->set_debug_visitor(nullptr); | 2073 client_->client()->session()->connection()->set_debug_visitor(nullptr); |
| 2074 } | 2074 } |
| 2075 | 2075 |
| 2076 // A bad header shouldn't tear down the connection, because the receiver can't | 2076 // A bad header shouldn't tear down the connection, because the receiver can't |
| 2077 // tell the connection ID. | 2077 // tell the connection ID. |
| 2078 TEST_P(EndToEndTest, BadPacketHeaderTruncated) { | 2078 TEST_P(EndToEndTest, BadPacketHeaderTruncated) { |
| 2079 ASSERT_TRUE(Initialize()); | 2079 ASSERT_TRUE(Initialize()); |
| 2080 | 2080 |
| 2081 // Start the connection. | 2081 // Start the connection. |
| 2082 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 2082 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 2083 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 2083 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 2084 | 2084 |
| 2085 // Packet with invalid public flags. | 2085 // Packet with invalid public flags. |
| 2086 char packet[] = {// public flags (8 byte connection_id) | 2086 char packet[] = {// public flags (8 byte connection_id) |
| 2087 0x3C, | 2087 0x3C, |
| 2088 // truncated connection ID | 2088 // truncated connection ID |
| 2089 0x11}; | 2089 0x11}; |
| 2090 client_writer_->WritePacket( | 2090 client_writer_->WritePacket( |
| 2091 &packet[0], sizeof(packet), | 2091 &packet[0], sizeof(packet), |
| 2092 client_->client()->GetLatestClientAddress().address(), server_address_, | 2092 client_->client()->GetLatestClientAddress().address(), server_address_, |
| 2093 nullptr); | 2093 nullptr); |
| 2094 // Give the server time to process the packet. | 2094 // Give the server time to process the packet. |
| 2095 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); | 2095 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); |
| 2096 // Pause the server so we can access the server's internals without races. | 2096 // Pause the server so we can access the server's internals without races. |
| 2097 server_thread_->Pause(); | 2097 server_thread_->Pause(); |
| 2098 QuicDispatcher* dispatcher = | 2098 QuicDispatcher* dispatcher = |
| 2099 QuicServerPeer::GetDispatcher(server_thread_->server()); | 2099 QuicServerPeer::GetDispatcher(server_thread_->server()); |
| 2100 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, | 2100 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, |
| 2101 QuicDispatcherPeer::GetAndClearLastError(dispatcher)); | 2101 QuicDispatcherPeer::GetAndClearLastError(dispatcher)); |
| 2102 server_thread_->Resume(); | 2102 server_thread_->Resume(); |
| 2103 | 2103 |
| 2104 // The connection should not be terminated. | 2104 // The connection should not be terminated. |
| 2105 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 2105 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 2106 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 2106 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 2107 } | 2107 } |
| 2108 | 2108 |
| 2109 // A bad header shouldn't tear down the connection, because the receiver can't | 2109 // A bad header shouldn't tear down the connection, because the receiver can't |
| 2110 // tell the connection ID. | 2110 // tell the connection ID. |
| 2111 TEST_P(EndToEndTest, BadPacketHeaderFlags) { | 2111 TEST_P(EndToEndTest, BadPacketHeaderFlags) { |
| 2112 ASSERT_TRUE(Initialize()); | 2112 ASSERT_TRUE(Initialize()); |
| 2113 | 2113 |
| 2114 // Start the connection. | 2114 // Start the connection. |
| 2115 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 2115 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 2116 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 2116 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 2117 | 2117 |
| 2118 // Packet with invalid public flags. | 2118 // Packet with invalid public flags. |
| 2119 char packet[] = { | 2119 char packet[] = { |
| 2120 // invalid public flags | 2120 // invalid public flags |
| 2121 0xFF, | 2121 0xFF, |
| 2122 // connection_id | 2122 // connection_id |
| 2123 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 2123 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 2124 // packet sequence number | 2124 // packet sequence number |
| 2125 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | 2125 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, |
| 2126 // private flags | 2126 // private flags |
| 2127 0x00, | 2127 0x00, |
| 2128 }; | 2128 }; |
| 2129 client_writer_->WritePacket( | 2129 client_writer_->WritePacket( |
| 2130 &packet[0], sizeof(packet), | 2130 &packet[0], sizeof(packet), |
| 2131 client_->client()->GetLatestClientAddress().address(), server_address_, | 2131 client_->client()->GetLatestClientAddress().address(), server_address_, |
| 2132 nullptr); | 2132 nullptr); |
| 2133 // Give the server time to process the packet. | 2133 // Give the server time to process the packet. |
| 2134 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); | 2134 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); |
| 2135 // Pause the server so we can access the server's internals without races. | 2135 // Pause the server so we can access the server's internals without races. |
| 2136 server_thread_->Pause(); | 2136 server_thread_->Pause(); |
| 2137 QuicDispatcher* dispatcher = | 2137 QuicDispatcher* dispatcher = |
| 2138 QuicServerPeer::GetDispatcher(server_thread_->server()); | 2138 QuicServerPeer::GetDispatcher(server_thread_->server()); |
| 2139 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, | 2139 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, |
| 2140 QuicDispatcherPeer::GetAndClearLastError(dispatcher)); | 2140 QuicDispatcherPeer::GetAndClearLastError(dispatcher)); |
| 2141 server_thread_->Resume(); | 2141 server_thread_->Resume(); |
| 2142 | 2142 |
| 2143 // The connection should not be terminated. | 2143 // The connection should not be terminated. |
| 2144 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 2144 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 2145 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 2145 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 2146 } | 2146 } |
| 2147 | 2147 |
| 2148 // Send a packet from the client with bad encrypted data. The server should not | 2148 // Send a packet from the client with bad encrypted data. The server should not |
| 2149 // tear down the connection. | 2149 // tear down the connection. |
| 2150 TEST_P(EndToEndTest, BadEncryptedData) { | 2150 TEST_P(EndToEndTest, BadEncryptedData) { |
| 2151 ASSERT_TRUE(Initialize()); | 2151 ASSERT_TRUE(Initialize()); |
| 2152 | 2152 |
| 2153 // Start the connection. | 2153 // Start the connection. |
| 2154 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 2154 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 2155 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 2155 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 2156 | 2156 |
| 2157 std::unique_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( | 2157 std::unique_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( |
| 2158 client_->client()->session()->connection()->connection_id(), false, false, | 2158 client_->client()->session()->connection()->connection_id(), false, false, |
| 2159 false, kDefaultPathId, 1, "At least 20 characters.", | 2159 false, kDefaultPathId, 1, "At least 20 characters.", |
| 2160 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER)); | 2160 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER)); |
| 2161 // Damage the encrypted data. | 2161 // Damage the encrypted data. |
| 2162 string damaged_packet(packet->data(), packet->length()); | 2162 string damaged_packet(packet->data(), packet->length()); |
| 2163 damaged_packet[30] ^= 0x01; | 2163 damaged_packet[30] ^= 0x01; |
| 2164 DVLOG(1) << "Sending bad packet."; | 2164 DVLOG(1) << "Sending bad packet."; |
| 2165 client_writer_->WritePacket( | 2165 client_writer_->WritePacket( |
| 2166 damaged_packet.data(), damaged_packet.length(), | 2166 damaged_packet.data(), damaged_packet.length(), |
| 2167 client_->client()->GetLatestClientAddress().address(), server_address_, | 2167 client_->client()->GetLatestClientAddress().address(), server_address_, |
| 2168 nullptr); | 2168 nullptr); |
| 2169 // Give the server time to process the packet. | 2169 // Give the server time to process the packet. |
| 2170 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); | 2170 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); |
| 2171 // This error is sent to the connection's OnError (which ignores it), so the | 2171 // This error is sent to the connection's OnError (which ignores it), so the |
| 2172 // dispatcher doesn't see it. | 2172 // dispatcher doesn't see it. |
| 2173 // Pause the server so we can access the server's internals without races. | 2173 // Pause the server so we can access the server's internals without races. |
| 2174 server_thread_->Pause(); | 2174 server_thread_->Pause(); |
| 2175 QuicDispatcher* dispatcher = | 2175 QuicDispatcher* dispatcher = |
| 2176 QuicServerPeer::GetDispatcher(server_thread_->server()); | 2176 QuicServerPeer::GetDispatcher(server_thread_->server()); |
| 2177 EXPECT_EQ(QUIC_NO_ERROR, | 2177 EXPECT_EQ(QUIC_NO_ERROR, |
| 2178 QuicDispatcherPeer::GetAndClearLastError(dispatcher)); | 2178 QuicDispatcherPeer::GetAndClearLastError(dispatcher)); |
| 2179 server_thread_->Resume(); | 2179 server_thread_->Resume(); |
| 2180 | 2180 |
| 2181 // The connection should not be terminated. | 2181 // The connection should not be terminated. |
| 2182 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 2182 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 2183 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 2183 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 2184 } | 2184 } |
| 2185 | 2185 |
| 2186 // A test stream that gives |response_body_| as an error response body. | 2186 // A test stream that gives |response_body_| as an error response body. |
| 2187 class ServerStreamWithErrorResponseBody : public QuicSimpleServerStream { | 2187 class ServerStreamWithErrorResponseBody : public QuicSimpleServerStream { |
| 2188 public: | 2188 public: |
| 2189 ServerStreamWithErrorResponseBody(QuicStreamId id, | 2189 ServerStreamWithErrorResponseBody(QuicStreamId id, |
| 2190 QuicSpdySession* session, | 2190 QuicSpdySession* session, |
| 2191 string response_body) | 2191 string response_body) |
| 2192 : QuicSimpleServerStream(id, session), | 2192 : QuicSimpleServerStream(id, session), |
| 2193 response_body_(std::move(response_body)) {} | 2193 response_body_(std::move(response_body)) {} |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2441 GenerateBody(&request_body, kRequestBodySize); | 2441 GenerateBody(&request_body, kRequestBodySize); |
| 2442 request.AddBody(request_body, false); | 2442 request.AddBody(request_body, false); |
| 2443 // Set an invalid content-length, so the request will receive an early 500 | 2443 // Set an invalid content-length, so the request will receive an early 500 |
| 2444 // response. Must be done after AddBody, which also sets content-length. | 2444 // response. Must be done after AddBody, which also sets content-length. |
| 2445 request.AddHeader("content-length", "-1"); | 2445 request.AddHeader("content-length", "-1"); |
| 2446 request.set_skip_message_validation(true); | 2446 request.set_skip_message_validation(true); |
| 2447 | 2447 |
| 2448 // Send the request. | 2448 // Send the request. |
| 2449 client_->SendMessage(request); | 2449 client_->SendMessage(request); |
| 2450 client_->WaitForResponse(); | 2450 client_->WaitForResponse(); |
| 2451 EXPECT_EQ(500u, client_->response_headers()->parsed_response_code()); | 2451 EXPECT_EQ("500", client_->response_headers()->find(":status")->second); |
| 2452 | 2452 |
| 2453 // Pause the server so we can access the server's internals without races. | 2453 // Pause the server so we can access the server's internals without races. |
| 2454 server_thread_->Pause(); | 2454 server_thread_->Pause(); |
| 2455 | 2455 |
| 2456 QuicDispatcher* dispatcher = | 2456 QuicDispatcher* dispatcher = |
| 2457 QuicServerPeer::GetDispatcher(server_thread_->server()); | 2457 QuicServerPeer::GetDispatcher(server_thread_->server()); |
| 2458 QuicDispatcher::SessionMap const& map = | 2458 QuicDispatcher::SessionMap const& map = |
| 2459 QuicDispatcherPeer::session_map(dispatcher); | 2459 QuicDispatcherPeer::session_map(dispatcher); |
| 2460 QuicDispatcher::SessionMap::const_iterator it = map.begin(); | 2460 QuicDispatcher::SessionMap::const_iterator it = map.begin(); |
| 2461 EXPECT_TRUE(it != map.end()); | 2461 EXPECT_TRUE(it != map.end()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2487 request.AddHeader("content-length", "-1"); | 2487 request.AddHeader("content-length", "-1"); |
| 2488 request.set_skip_message_validation(true); | 2488 request.set_skip_message_validation(true); |
| 2489 request.set_has_complete_message(false); | 2489 request.set_has_complete_message(false); |
| 2490 | 2490 |
| 2491 // Tell the client to not close the stream if it receives an early response. | 2491 // Tell the client to not close the stream if it receives an early response. |
| 2492 client_->set_allow_bidirectional_data(true); | 2492 client_->set_allow_bidirectional_data(true); |
| 2493 // Send the headers. | 2493 // Send the headers. |
| 2494 client_->SendMessage(request); | 2494 client_->SendMessage(request); |
| 2495 // Receive the response and let the server close writing. | 2495 // Receive the response and let the server close writing. |
| 2496 client_->WaitForInitialResponse(); | 2496 client_->WaitForInitialResponse(); |
| 2497 EXPECT_EQ(500u, client_->response_headers()->parsed_response_code()); | 2497 EXPECT_EQ("500", client_->response_headers()->find(":status")->second); |
| 2498 | 2498 |
| 2499 // Receive the reset stream from server on early response. | 2499 // Receive the reset stream from server on early response. |
| 2500 ReliableQuicStream* stream = | 2500 ReliableQuicStream* stream = |
| 2501 client_->client()->session()->GetOrCreateStream(kClientDataStreamId1); | 2501 client_->client()->session()->GetOrCreateStream(kClientDataStreamId1); |
| 2502 // The stream is reset by server's reset stream. | 2502 // The stream is reset by server's reset stream. |
| 2503 EXPECT_EQ(stream, nullptr); | 2503 EXPECT_EQ(stream, nullptr); |
| 2504 } | 2504 } |
| 2505 | 2505 |
| 2506 TEST_P(EndToEndTest, Trailers) { | 2506 TEST_P(EndToEndTest, Trailers) { |
| 2507 // Test sending and receiving HTTP/2 Trailers (trailing HEADERS frames). | 2507 // Test sending and receiving HTTP/2 Trailers (trailing HEADERS frames). |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2521 headers["content-length"] = IntToString(kBody.size()); | 2521 headers["content-length"] = IntToString(kBody.size()); |
| 2522 | 2522 |
| 2523 SpdyHeaderBlock trailers; | 2523 SpdyHeaderBlock trailers; |
| 2524 trailers["some-trailing-header"] = "trailing-header-value"; | 2524 trailers["some-trailing-header"] = "trailing-header-value"; |
| 2525 | 2525 |
| 2526 QuicInMemoryCache::GetInstance()->AddResponse( | 2526 QuicInMemoryCache::GetInstance()->AddResponse( |
| 2527 server_hostname_, "/trailer_url", std::move(headers), kBody, | 2527 server_hostname_, "/trailer_url", std::move(headers), kBody, |
| 2528 trailers.Clone()); | 2528 trailers.Clone()); |
| 2529 | 2529 |
| 2530 EXPECT_EQ(kBody, client_->SendSynchronousRequest("/trailer_url")); | 2530 EXPECT_EQ(kBody, client_->SendSynchronousRequest("/trailer_url")); |
| 2531 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 2531 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 2532 EXPECT_EQ(trailers, client_->response_trailers()); | 2532 EXPECT_EQ(trailers, client_->response_trailers()); |
| 2533 } | 2533 } |
| 2534 | 2534 |
| 2535 class EndToEndTestServerPush : public EndToEndTest { | 2535 class EndToEndTestServerPush : public EndToEndTest { |
| 2536 protected: | 2536 protected: |
| 2537 const size_t kNumMaxStreams = 10; | 2537 const size_t kNumMaxStreams = 10; |
| 2538 | 2538 |
| 2539 EndToEndTestServerPush() : EndToEndTest() { | 2539 EndToEndTestServerPush() : EndToEndTest() { |
| 2540 client_config_.SetMaxStreamsPerConnection(kNumMaxStreams, kNumMaxStreams); | 2540 client_config_.SetMaxStreamsPerConnection(kNumMaxStreams, kNumMaxStreams); |
| 2541 client_config_.SetMaxIncomingDynamicStreamsToSend(kNumMaxStreams); | 2541 client_config_.SetMaxIncomingDynamicStreamsToSend(kNumMaxStreams); |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2983 client_->WaitForResponse(); | 2983 client_->WaitForResponse(); |
| 2984 EXPECT_EQ(kBarResponseBody, client_->response_body()); | 2984 EXPECT_EQ(kBarResponseBody, client_->response_body()); |
| 2985 QuicConnectionStats client_stats = | 2985 QuicConnectionStats client_stats = |
| 2986 client_->client()->session()->connection()->GetStats(); | 2986 client_->client()->session()->connection()->GetStats(); |
| 2987 EXPECT_EQ(0u, client_stats.packets_lost); | 2987 EXPECT_EQ(0u, client_stats.packets_lost); |
| 2988 EXPECT_EQ(1, client_->client()->GetNumSentClientHellos()); | 2988 EXPECT_EQ(1, client_->client()->GetNumSentClientHellos()); |
| 2989 } | 2989 } |
| 2990 } // namespace | 2990 } // namespace |
| 2991 } // namespace test | 2991 } // namespace test |
| 2992 } // namespace net | 2992 } // namespace net |
| OLD | NEW |