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 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 1443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1454 public: | 1454 public: |
1455 WrongAddressWriter() { | 1455 WrongAddressWriter() { |
1456 IPAddressNumber ip; | 1456 IPAddressNumber ip; |
1457 CHECK(net::ParseIPLiteralToNumber("127.0.0.2", &ip)); | 1457 CHECK(net::ParseIPLiteralToNumber("127.0.0.2", &ip)); |
1458 self_address_ = IPEndPoint(ip, 0); | 1458 self_address_ = IPEndPoint(ip, 0); |
1459 } | 1459 } |
1460 | 1460 |
1461 WriteResult WritePacket(const char* buffer, | 1461 WriteResult WritePacket(const char* buffer, |
1462 size_t buf_len, | 1462 size_t buf_len, |
1463 const IPAddressNumber& /*real_self_address*/, | 1463 const IPAddressNumber& /*real_self_address*/, |
1464 const IPEndPoint& peer_address) override { | 1464 const IPEndPoint& peer_address, |
| 1465 PerPacketOptions* options) override { |
1465 // Use wrong address! | 1466 // Use wrong address! |
1466 return QuicPacketWriterWrapper::WritePacket( | 1467 return QuicPacketWriterWrapper::WritePacket(buffer, buf_len, |
1467 buffer, buf_len, self_address_.address().bytes(), peer_address); | 1468 self_address_.address().bytes(), |
| 1469 peer_address, options); |
1468 } | 1470 } |
1469 | 1471 |
1470 bool IsWriteBlockedDataBuffered() const override { return false; } | 1472 bool IsWriteBlockedDataBuffered() const override { return false; } |
1471 | 1473 |
1472 IPEndPoint self_address_; | 1474 IPEndPoint self_address_; |
1473 }; | 1475 }; |
1474 | 1476 |
1475 TEST_P(EndToEndTest, ConnectionMigrationClientIPChanged) { | 1477 TEST_P(EndToEndTest, ConnectionMigrationClientIPChanged) { |
1476 ASSERT_TRUE(Initialize()); | 1478 ASSERT_TRUE(Initialize()); |
1477 | 1479 |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1796 QuicFramer framer(server_supported_versions_, QuicTime::Zero(), | 1798 QuicFramer framer(server_supported_versions_, QuicTime::Zero(), |
1797 Perspective::IS_SERVER); | 1799 Perspective::IS_SERVER); |
1798 scoped_ptr<QuicEncryptedPacket> packet(framer.BuildPublicResetPacket(header)); | 1800 scoped_ptr<QuicEncryptedPacket> packet(framer.BuildPublicResetPacket(header)); |
1799 testing::NiceMock<MockQuicConnectionDebugVisitor> visitor; | 1801 testing::NiceMock<MockQuicConnectionDebugVisitor> visitor; |
1800 client_->client()->session()->connection()->set_debug_visitor(&visitor); | 1802 client_->client()->session()->connection()->set_debug_visitor(&visitor); |
1801 EXPECT_CALL(visitor, OnIncorrectConnectionId(incorrect_connection_id)) | 1803 EXPECT_CALL(visitor, OnIncorrectConnectionId(incorrect_connection_id)) |
1802 .Times(1); | 1804 .Times(1); |
1803 // We must pause the server's thread in order to call WritePacket without | 1805 // We must pause the server's thread in order to call WritePacket without |
1804 // race conditions. | 1806 // race conditions. |
1805 server_thread_->Pause(); | 1807 server_thread_->Pause(); |
1806 server_writer_->WritePacket(packet->data(), packet->length(), | 1808 server_writer_->WritePacket( |
1807 server_address_.address().bytes(), | 1809 packet->data(), packet->length(), server_address_.address().bytes(), |
1808 client_->client()->GetLatestClientAddress()); | 1810 client_->client()->GetLatestClientAddress(), nullptr); |
1809 server_thread_->Resume(); | 1811 server_thread_->Resume(); |
1810 | 1812 |
1811 // The connection should be unaffected. | 1813 // The connection should be unaffected. |
1812 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 1814 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
1813 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 1815 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
1814 | 1816 |
1815 client_->client()->session()->connection()->set_debug_visitor(nullptr); | 1817 client_->client()->session()->connection()->set_debug_visitor(nullptr); |
1816 } | 1818 } |
1817 | 1819 |
1818 // Send a public reset from the client for a different connection ID. | 1820 // Send a public reset from the client for a different connection ID. |
1819 // It should be ignored. | 1821 // It should be ignored. |
1820 TEST_P(EndToEndTest, ClientSendPublicResetWithDifferentConnectionId) { | 1822 TEST_P(EndToEndTest, ClientSendPublicResetWithDifferentConnectionId) { |
1821 ASSERT_TRUE(Initialize()); | 1823 ASSERT_TRUE(Initialize()); |
1822 | 1824 |
1823 // Send the public reset. | 1825 // Send the public reset. |
1824 QuicConnectionId incorrect_connection_id = | 1826 QuicConnectionId incorrect_connection_id = |
1825 client_->client()->session()->connection()->connection_id() + 1; | 1827 client_->client()->session()->connection()->connection_id() + 1; |
1826 QuicPublicResetPacket header; | 1828 QuicPublicResetPacket header; |
1827 header.public_header.connection_id = incorrect_connection_id; | 1829 header.public_header.connection_id = incorrect_connection_id; |
1828 header.public_header.reset_flag = true; | 1830 header.public_header.reset_flag = true; |
1829 header.public_header.version_flag = false; | 1831 header.public_header.version_flag = false; |
1830 header.rejected_packet_number = 10101; | 1832 header.rejected_packet_number = 10101; |
1831 QuicFramer framer(server_supported_versions_, QuicTime::Zero(), | 1833 QuicFramer framer(server_supported_versions_, QuicTime::Zero(), |
1832 Perspective::IS_CLIENT); | 1834 Perspective::IS_CLIENT); |
1833 scoped_ptr<QuicEncryptedPacket> packet(framer.BuildPublicResetPacket(header)); | 1835 scoped_ptr<QuicEncryptedPacket> packet(framer.BuildPublicResetPacket(header)); |
1834 client_writer_->WritePacket( | 1836 client_writer_->WritePacket( |
1835 packet->data(), packet->length(), | 1837 packet->data(), packet->length(), |
1836 client_->client()->GetLatestClientAddress().address().bytes(), | 1838 client_->client()->GetLatestClientAddress().address().bytes(), |
1837 server_address_); | 1839 server_address_, nullptr); |
1838 | 1840 |
1839 // The connection should be unaffected. | 1841 // The connection should be unaffected. |
1840 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 1842 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
1841 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 1843 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
1842 } | 1844 } |
1843 | 1845 |
1844 // Send a version negotiation packet from the server for a different | 1846 // Send a version negotiation packet from the server for a different |
1845 // connection ID. It should be ignored. | 1847 // connection ID. It should be ignored. |
1846 TEST_P(EndToEndTest, ServerSendVersionNegotiationWithDifferentConnectionId) { | 1848 TEST_P(EndToEndTest, ServerSendVersionNegotiationWithDifferentConnectionId) { |
1847 ASSERT_TRUE(Initialize()); | 1849 ASSERT_TRUE(Initialize()); |
1848 | 1850 |
1849 // Send the version negotiation packet. | 1851 // Send the version negotiation packet. |
1850 QuicConnectionId incorrect_connection_id = | 1852 QuicConnectionId incorrect_connection_id = |
1851 client_->client()->session()->connection()->connection_id() + 1; | 1853 client_->client()->session()->connection()->connection_id() + 1; |
1852 scoped_ptr<QuicEncryptedPacket> packet( | 1854 scoped_ptr<QuicEncryptedPacket> packet( |
1853 QuicFramer::BuildVersionNegotiationPacket(incorrect_connection_id, | 1855 QuicFramer::BuildVersionNegotiationPacket(incorrect_connection_id, |
1854 server_supported_versions_)); | 1856 server_supported_versions_)); |
1855 testing::NiceMock<MockQuicConnectionDebugVisitor> visitor; | 1857 testing::NiceMock<MockQuicConnectionDebugVisitor> visitor; |
1856 client_->client()->session()->connection()->set_debug_visitor(&visitor); | 1858 client_->client()->session()->connection()->set_debug_visitor(&visitor); |
1857 EXPECT_CALL(visitor, OnIncorrectConnectionId(incorrect_connection_id)) | 1859 EXPECT_CALL(visitor, OnIncorrectConnectionId(incorrect_connection_id)) |
1858 .Times(1); | 1860 .Times(1); |
1859 // We must pause the server's thread in order to call WritePacket without | 1861 // We must pause the server's thread in order to call WritePacket without |
1860 // race conditions. | 1862 // race conditions. |
1861 server_thread_->Pause(); | 1863 server_thread_->Pause(); |
1862 server_writer_->WritePacket(packet->data(), packet->length(), | 1864 server_writer_->WritePacket( |
1863 server_address_.address().bytes(), | 1865 packet->data(), packet->length(), server_address_.address().bytes(), |
1864 client_->client()->GetLatestClientAddress()); | 1866 client_->client()->GetLatestClientAddress(), nullptr); |
1865 server_thread_->Resume(); | 1867 server_thread_->Resume(); |
1866 | 1868 |
1867 // The connection should be unaffected. | 1869 // The connection should be unaffected. |
1868 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 1870 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
1869 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 1871 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
1870 | 1872 |
1871 client_->client()->session()->connection()->set_debug_visitor(nullptr); | 1873 client_->client()->session()->connection()->set_debug_visitor(nullptr); |
1872 } | 1874 } |
1873 | 1875 |
1874 // A bad header shouldn't tear down the connection, because the receiver can't | 1876 // A bad header shouldn't tear down the connection, because the receiver can't |
1875 // tell the connection ID. | 1877 // tell the connection ID. |
1876 TEST_P(EndToEndTest, BadPacketHeaderTruncated) { | 1878 TEST_P(EndToEndTest, BadPacketHeaderTruncated) { |
1877 ASSERT_TRUE(Initialize()); | 1879 ASSERT_TRUE(Initialize()); |
1878 | 1880 |
1879 // Start the connection. | 1881 // Start the connection. |
1880 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 1882 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
1881 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 1883 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
1882 | 1884 |
1883 // Packet with invalid public flags. | 1885 // Packet with invalid public flags. |
1884 char packet[] = {// public flags (8 byte connection_id) | 1886 char packet[] = {// public flags (8 byte connection_id) |
1885 0x3C, | 1887 0x3C, |
1886 // truncated connection ID | 1888 // truncated connection ID |
1887 0x11}; | 1889 0x11}; |
1888 client_writer_->WritePacket( | 1890 client_writer_->WritePacket( |
1889 &packet[0], sizeof(packet), | 1891 &packet[0], sizeof(packet), |
1890 client_->client()->GetLatestClientAddress().address().bytes(), | 1892 client_->client()->GetLatestClientAddress().address().bytes(), |
1891 server_address_); | 1893 server_address_, nullptr); |
1892 // Give the server time to process the packet. | 1894 // Give the server time to process the packet. |
1893 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); | 1895 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); |
1894 // Pause the server so we can access the server's internals without races. | 1896 // Pause the server so we can access the server's internals without races. |
1895 server_thread_->Pause(); | 1897 server_thread_->Pause(); |
1896 QuicDispatcher* dispatcher = | 1898 QuicDispatcher* dispatcher = |
1897 QuicServerPeer::GetDispatcher(server_thread_->server()); | 1899 QuicServerPeer::GetDispatcher(server_thread_->server()); |
1898 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, | 1900 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, |
1899 QuicDispatcherPeer::GetAndClearLastError(dispatcher)); | 1901 QuicDispatcherPeer::GetAndClearLastError(dispatcher)); |
1900 server_thread_->Resume(); | 1902 server_thread_->Resume(); |
1901 | 1903 |
(...skipping 18 matching lines...) Expand all Loading... |
1920 // connection_id | 1922 // connection_id |
1921 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 1923 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
1922 // packet sequence number | 1924 // packet sequence number |
1923 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | 1925 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, |
1924 // private flags | 1926 // private flags |
1925 0x00, | 1927 0x00, |
1926 }; | 1928 }; |
1927 client_writer_->WritePacket( | 1929 client_writer_->WritePacket( |
1928 &packet[0], sizeof(packet), | 1930 &packet[0], sizeof(packet), |
1929 client_->client()->GetLatestClientAddress().address().bytes(), | 1931 client_->client()->GetLatestClientAddress().address().bytes(), |
1930 server_address_); | 1932 server_address_, nullptr); |
1931 // Give the server time to process the packet. | 1933 // Give the server time to process the packet. |
1932 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); | 1934 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); |
1933 // Pause the server so we can access the server's internals without races. | 1935 // Pause the server so we can access the server's internals without races. |
1934 server_thread_->Pause(); | 1936 server_thread_->Pause(); |
1935 QuicDispatcher* dispatcher = | 1937 QuicDispatcher* dispatcher = |
1936 QuicServerPeer::GetDispatcher(server_thread_->server()); | 1938 QuicServerPeer::GetDispatcher(server_thread_->server()); |
1937 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, | 1939 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, |
1938 QuicDispatcherPeer::GetAndClearLastError(dispatcher)); | 1940 QuicDispatcherPeer::GetAndClearLastError(dispatcher)); |
1939 server_thread_->Resume(); | 1941 server_thread_->Resume(); |
1940 | 1942 |
(...skipping 15 matching lines...) Expand all Loading... |
1956 client_->client()->session()->connection()->connection_id(), false, false, | 1958 client_->client()->session()->connection()->connection_id(), false, false, |
1957 false, kDefaultPathId, 1, "At least 20 characters.", | 1959 false, kDefaultPathId, 1, "At least 20 characters.", |
1958 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER)); | 1960 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER)); |
1959 // Damage the encrypted data. | 1961 // Damage the encrypted data. |
1960 string damaged_packet(packet->data(), packet->length()); | 1962 string damaged_packet(packet->data(), packet->length()); |
1961 damaged_packet[30] ^= 0x01; | 1963 damaged_packet[30] ^= 0x01; |
1962 DVLOG(1) << "Sending bad packet."; | 1964 DVLOG(1) << "Sending bad packet."; |
1963 client_writer_->WritePacket( | 1965 client_writer_->WritePacket( |
1964 damaged_packet.data(), damaged_packet.length(), | 1966 damaged_packet.data(), damaged_packet.length(), |
1965 client_->client()->GetLatestClientAddress().address().bytes(), | 1967 client_->client()->GetLatestClientAddress().address().bytes(), |
1966 server_address_); | 1968 server_address_, nullptr); |
1967 // Give the server time to process the packet. | 1969 // Give the server time to process the packet. |
1968 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); | 1970 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); |
1969 // This error is sent to the connection's OnError (which ignores it), so the | 1971 // This error is sent to the connection's OnError (which ignores it), so the |
1970 // dispatcher doesn't see it. | 1972 // dispatcher doesn't see it. |
1971 // Pause the server so we can access the server's internals without races. | 1973 // Pause the server so we can access the server's internals without races. |
1972 server_thread_->Pause(); | 1974 server_thread_->Pause(); |
1973 QuicDispatcher* dispatcher = | 1975 QuicDispatcher* dispatcher = |
1974 QuicServerPeer::GetDispatcher(server_thread_->server()); | 1976 QuicServerPeer::GetDispatcher(server_thread_->server()); |
1975 EXPECT_EQ(QUIC_NO_ERROR, | 1977 EXPECT_EQ(QUIC_NO_ERROR, |
1976 QuicDispatcherPeer::GetAndClearLastError(dispatcher)); | 1978 QuicDispatcherPeer::GetAndClearLastError(dispatcher)); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2166 "www.google.com", "/trailer_url", headers, kBody, trailers); | 2168 "www.google.com", "/trailer_url", headers, kBody, trailers); |
2167 | 2169 |
2168 EXPECT_EQ(kBody, client_->SendSynchronousRequest("/trailer_url")); | 2170 EXPECT_EQ(kBody, client_->SendSynchronousRequest("/trailer_url")); |
2169 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 2171 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
2170 EXPECT_EQ(trailers, client_->response_trailers()); | 2172 EXPECT_EQ(trailers, client_->response_trailers()); |
2171 } | 2173 } |
2172 | 2174 |
2173 } // namespace | 2175 } // namespace |
2174 } // namespace test | 2176 } // namespace test |
2175 } // namespace net | 2177 } // namespace net |
OLD | NEW |