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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 static bool CheckForDecryptionError(QuicFramer* framer) { | 123 static bool CheckForDecryptionError(QuicFramer* framer) { |
124 return framer->error() == QUIC_DECRYPTION_FAILURE; | 124 return framer->error() == QUIC_DECRYPTION_FAILURE; |
125 } | 125 } |
126 | 126 |
127 // Regression test for b/17206611. | 127 // Regression test for b/17206611. |
128 TEST_P(ToolsQuicClientSessionTest, InvalidPacketReceived) { | 128 TEST_P(ToolsQuicClientSessionTest, InvalidPacketReceived) { |
129 IPEndPoint server_address(TestPeerIPAddress(), kTestPort); | 129 IPEndPoint server_address(TestPeerIPAddress(), kTestPort); |
130 IPEndPoint client_address(TestPeerIPAddress(), kTestPort); | 130 IPEndPoint client_address(TestPeerIPAddress(), kTestPort); |
131 | 131 |
132 EXPECT_CALL(*connection_, ProcessUdpPacket(server_address, client_address, _)) | 132 EXPECT_CALL(*connection_, ProcessUdpPacket(server_address, client_address, _)) |
133 .WillRepeatedly(Invoke(implicit_cast<MockConnection*>(connection_), | 133 .WillRepeatedly(Invoke(static_cast<MockConnection*>(connection_), |
134 &MockConnection::ReallyProcessUdpPacket)); | 134 &MockConnection::ReallyProcessUdpPacket)); |
135 EXPECT_CALL(*connection_, OnCanWrite()).Times(AnyNumber()); | 135 EXPECT_CALL(*connection_, OnCanWrite()).Times(AnyNumber()); |
136 EXPECT_CALL(*connection_, OnError(_)).Times(1); | 136 EXPECT_CALL(*connection_, OnError(_)).Times(1); |
137 | 137 |
138 // Verify that empty packets don't close the connection. | 138 // Verify that empty packets don't close the connection. |
139 QuicEncryptedPacket zero_length_packet(nullptr, 0, false); | 139 QuicEncryptedPacket zero_length_packet(nullptr, 0, false); |
140 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails(_, _)).Times(0); | 140 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails(_, _)).Times(0); |
141 session_->connection()->ProcessUdpPacket(client_address, server_address, | 141 session_->connection()->ProcessUdpPacket(client_address, server_address, |
142 zero_length_packet); | 142 zero_length_packet); |
143 | 143 |
(...skipping 16 matching lines...) Expand all Loading... |
160 session_->connection()->ProcessUdpPacket(client_address, server_address, | 160 session_->connection()->ProcessUdpPacket(client_address, server_address, |
161 *packet); | 161 *packet); |
162 } | 162 } |
163 | 163 |
164 // A packet with invalid framing should cause a connection to be closed. | 164 // A packet with invalid framing should cause a connection to be closed. |
165 TEST_P(ToolsQuicClientSessionTest, InvalidFramedPacketReceived) { | 165 TEST_P(ToolsQuicClientSessionTest, InvalidFramedPacketReceived) { |
166 IPEndPoint server_address(TestPeerIPAddress(), kTestPort); | 166 IPEndPoint server_address(TestPeerIPAddress(), kTestPort); |
167 IPEndPoint client_address(TestPeerIPAddress(), kTestPort); | 167 IPEndPoint client_address(TestPeerIPAddress(), kTestPort); |
168 | 168 |
169 EXPECT_CALL(*connection_, ProcessUdpPacket(server_address, client_address, _)) | 169 EXPECT_CALL(*connection_, ProcessUdpPacket(server_address, client_address, _)) |
170 .WillRepeatedly(Invoke(implicit_cast<MockConnection*>(connection_), | 170 .WillRepeatedly(Invoke(static_cast<MockConnection*>(connection_), |
171 &MockConnection::ReallyProcessUdpPacket)); | 171 &MockConnection::ReallyProcessUdpPacket)); |
172 EXPECT_CALL(*connection_, OnError(_)).Times(1); | 172 EXPECT_CALL(*connection_, OnError(_)).Times(1); |
173 | 173 |
174 // Verify that a decryptable packet with bad frames does close the connection. | 174 // Verify that a decryptable packet with bad frames does close the connection. |
175 QuicConnectionId connection_id = session_->connection()->connection_id(); | 175 QuicConnectionId connection_id = session_->connection()->connection_id(); |
176 scoped_ptr<QuicEncryptedPacket> packet(ConstructMisFramedEncryptedPacket( | 176 scoped_ptr<QuicEncryptedPacket> packet(ConstructMisFramedEncryptedPacket( |
177 connection_id, false, false, 100, "data", PACKET_8BYTE_CONNECTION_ID, | 177 connection_id, false, false, 100, "data", PACKET_8BYTE_CONNECTION_ID, |
178 PACKET_6BYTE_PACKET_NUMBER, nullptr)); | 178 PACKET_6BYTE_PACKET_NUMBER, nullptr)); |
179 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails(_, _)).Times(1); | 179 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails(_, _)).Times(1); |
180 session_->connection()->ProcessUdpPacket(client_address, server_address, | 180 session_->connection()->ProcessUdpPacket(client_address, server_address, |
181 *packet); | 181 *packet); |
182 } | 182 } |
183 | 183 |
184 } // namespace | 184 } // namespace |
185 } // namespace test | 185 } // namespace test |
186 } // namespace tools | 186 } // namespace tools |
187 } // namespace net | 187 } // namespace net |
OLD | NEW |