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 "net/tools/quic/quic_client_session.h" | 5 #include "net/tools/quic/quic_client_session.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "net/base/ip_endpoint.h" | 9 #include "net/base/ip_endpoint.h" |
10 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" | 10 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" |
11 #include "net/quic/quic_flags.h" | 11 #include "net/quic/quic_flags.h" |
12 #include "net/quic/test_tools/crypto_test_utils.h" | 12 #include "net/quic/test_tools/crypto_test_utils.h" |
13 #include "net/quic/test_tools/quic_session_peer.h" | 13 #include "net/quic/test_tools/quic_session_peer.h" |
14 #include "net/quic/test_tools/quic_test_utils.h" | 14 #include "net/quic/test_tools/quic_test_utils.h" |
15 #include "net/tools/quic/quic_spdy_client_stream.h" | 15 #include "net/tools/quic/quic_spdy_client_stream.h" |
16 #include "net/tools/quic/test_tools/quic_test_utils.h" | |
17 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
18 | 17 |
19 using net::test::CryptoTestUtils; | 18 using net::test::CryptoTestUtils; |
20 using net::test::DefaultQuicConfig; | 19 using net::test::DefaultQuicConfig; |
21 using net::test::PacketSavingConnection; | 20 using net::test::PacketSavingConnection; |
22 using net::test::QuicSessionPeer; | 21 using net::test::QuicSessionPeer; |
23 using net::test::SupportedVersions; | 22 using net::test::SupportedVersions; |
24 using net::test::TestPeerIPAddress; | |
25 using net::test::ValueRestore; | 23 using net::test::ValueRestore; |
26 using net::test::kTestPort; | |
27 using net::tools::test::MockConnection; | |
28 using testing::Invoke; | |
29 using testing::_; | 24 using testing::_; |
30 | 25 |
31 namespace net { | 26 namespace net { |
32 namespace tools { | 27 namespace tools { |
33 namespace test { | 28 namespace test { |
34 namespace { | 29 namespace { |
35 | 30 |
36 const char kServerHostname[] = "www.example.com"; | 31 const char kServerHostname[] = "www.example.com"; |
37 const uint16 kPort = 80; | 32 const uint16 kPort = 80; |
38 | 33 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 102 |
108 // Verify that headers stream is always protected and data streams are | 103 // Verify that headers stream is always protected and data streams are |
109 // optionally protected. | 104 // optionally protected. |
110 EXPECT_EQ(FEC_PROTECT_ALWAYS, | 105 EXPECT_EQ(FEC_PROTECT_ALWAYS, |
111 QuicSessionPeer::GetHeadersStream(session_.get())->fec_policy()); | 106 QuicSessionPeer::GetHeadersStream(session_.get())->fec_policy()); |
112 QuicSpdyClientStream* stream = session_->CreateOutgoingDataStream(); | 107 QuicSpdyClientStream* stream = session_->CreateOutgoingDataStream(); |
113 ASSERT_TRUE(stream); | 108 ASSERT_TRUE(stream); |
114 EXPECT_EQ(FEC_PROTECT_OPTIONAL, stream->fec_policy()); | 109 EXPECT_EQ(FEC_PROTECT_OPTIONAL, stream->fec_policy()); |
115 } | 110 } |
116 | 111 |
117 TEST_P(ToolsQuicClientSessionTest, EmptyPacketReceived) { | |
118 // This test covers broken behavior that empty packets cause QUIC connection | |
119 // broken. | |
120 | |
121 // Create Packet with 0 length. | |
122 QuicEncryptedPacket invalid_packet(nullptr, 0, false); | |
123 IPEndPoint server_address(TestPeerIPAddress(), kTestPort); | |
124 IPEndPoint client_address(TestPeerIPAddress(), kTestPort); | |
125 | |
126 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session_->connection()), | |
127 ProcessUdpPacket(server_address, client_address, _)) | |
128 .WillRepeatedly( | |
129 Invoke(reinterpret_cast<MockConnection*>(session_->connection()), | |
130 &MockConnection::ReallyProcessUdpPacket)); | |
131 | |
132 // Expect call to close connection with error QUIC_INVALID_PACKET_HEADER. | |
133 // TODO(b/17206611): Correct behavior: packet should get dropped and | |
134 // connection should remain open. | |
135 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails( | |
136 QUIC_INVALID_PACKET_HEADER, _)).Times(1); | |
137 session_->connection()->ProcessUdpPacket(client_address, server_address, | |
138 invalid_packet); | |
139 | |
140 // Create a packet that causes DecryptPacket failed. The packet will get | |
141 // dropped without closing connection. This is a correct behavior. | |
142 char buf[2] = {0x00, 0x01}; | |
143 QuicEncryptedPacket valid_packet(buf, 2, false); | |
144 // Close connection shouldn't be called. | |
145 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails(_, _)).Times(0); | |
146 session_->connection()->ProcessUdpPacket(client_address, server_address, | |
147 valid_packet); | |
148 } | |
149 | |
150 } // namespace | 112 } // namespace |
151 } // namespace test | 113 } // namespace test |
152 } // namespace tools | 114 } // namespace tools |
153 } // namespace net | 115 } // namespace net |
OLD | NEW |