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" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 104 |
105 // Verify that headers stream is always protected and data streams are | 105 // Verify that headers stream is always protected and data streams are |
106 // optionally protected. | 106 // optionally protected. |
107 EXPECT_EQ(FEC_PROTECT_ALWAYS, | 107 EXPECT_EQ(FEC_PROTECT_ALWAYS, |
108 QuicSessionPeer::GetHeadersStream(session_.get())->fec_policy()); | 108 QuicSessionPeer::GetHeadersStream(session_.get())->fec_policy()); |
109 QuicSpdyClientStream* stream = session_->CreateOutgoingDataStream(); | 109 QuicSpdyClientStream* stream = session_->CreateOutgoingDataStream(); |
110 ASSERT_TRUE(stream); | 110 ASSERT_TRUE(stream); |
111 EXPECT_EQ(FEC_PROTECT_OPTIONAL, stream->fec_policy()); | 111 EXPECT_EQ(FEC_PROTECT_OPTIONAL, stream->fec_policy()); |
112 } | 112 } |
113 | 113 |
114 TEST_P(ToolsQuicClientSessionTest, EmptyPacketReceived) { | 114 // Regression test for b/17206611. |
115 // This test covers broken behavior that empty packets cause QUIC connection | 115 TEST_P(ToolsQuicClientSessionTest, InvalidPacketReceived) { |
116 // broken. | |
117 | |
118 // Create Packet with 0 length. | 116 // Create Packet with 0 length. |
119 QuicEncryptedPacket invalid_packet(nullptr, 0, false); | 117 QuicEncryptedPacket invalid_packet(nullptr, 0, false); |
120 IPEndPoint server_address(TestPeerIPAddress(), kTestPort); | 118 IPEndPoint server_address(TestPeerIPAddress(), kTestPort); |
121 IPEndPoint client_address(TestPeerIPAddress(), kTestPort); | 119 IPEndPoint client_address(TestPeerIPAddress(), kTestPort); |
122 | 120 |
123 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session_->connection()), | 121 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session_->connection()), |
124 ProcessUdpPacket(server_address, client_address, _)) | 122 ProcessUdpPacket(server_address, client_address, _)) |
125 .WillRepeatedly( | 123 .WillRepeatedly( |
126 Invoke(reinterpret_cast<MockConnection*>(session_->connection()), | 124 Invoke(reinterpret_cast<MockConnection*>(session_->connection()), |
127 &MockConnection::ReallyProcessUdpPacket)); | 125 &MockConnection::ReallyProcessUdpPacket)); |
128 | 126 |
129 // Expect call to close connection with error QUIC_INVALID_PACKET_HEADER. | 127 // Validate that empty packets don't close the connection. |
130 // TODO(b/17206611): Correct behavior: packet should get dropped and | 128 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails(_, _)).Times(0); |
131 // connection should remain open. | |
132 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails( | |
133 QUIC_INVALID_PACKET_HEADER, _)).Times(1); | |
134 session_->connection()->ProcessUdpPacket(client_address, server_address, | 129 session_->connection()->ProcessUdpPacket(client_address, server_address, |
135 invalid_packet); | 130 invalid_packet); |
136 | 131 |
137 // Create a packet that causes DecryptPacket failed. The packet will get | 132 // Verifiy that small, invalid packets don't close the connection. |
138 // dropped without closing connection. This is a correct behavior. | |
139 char buf[2] = {0x00, 0x01}; | 133 char buf[2] = {0x00, 0x01}; |
140 QuicEncryptedPacket valid_packet(buf, 2, false); | 134 QuicEncryptedPacket valid_packet(buf, 2, false); |
141 // Close connection shouldn't be called. | 135 // Close connection shouldn't be called. |
142 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails(_, _)).Times(0); | 136 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails(_, _)).Times(0); |
143 session_->connection()->ProcessUdpPacket(client_address, server_address, | 137 session_->connection()->ProcessUdpPacket(client_address, server_address, |
144 valid_packet); | 138 valid_packet); |
145 } | 139 } |
146 | 140 |
147 } // namespace | 141 } // namespace |
148 } // namespace test | 142 } // namespace test |
149 } // namespace tools | 143 } // namespace tools |
150 } // namespace net | 144 } // namespace net |
OLD | NEW |