| 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/quic/core/crypto/aes_128_gcm_12_encrypter.h" | 9 #include "net/quic/core/crypto/aes_128_gcm_12_encrypter.h" |
| 10 #include "net/quic/core/quic_flags.h" | 10 #include "net/quic/core/quic_flags.h" |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 // Verifiy that small, invalid packets don't close the connection. | 260 // Verifiy that small, invalid packets don't close the connection. |
| 261 char buf[2] = {0x00, 0x01}; | 261 char buf[2] = {0x00, 0x01}; |
| 262 QuicReceivedPacket valid_packet(buf, 2, QuicTime::Zero(), false); | 262 QuicReceivedPacket valid_packet(buf, 2, QuicTime::Zero(), false); |
| 263 // Close connection shouldn't be called. | 263 // Close connection shouldn't be called. |
| 264 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0); | 264 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0); |
| 265 session_->ProcessUdpPacket(client_address, server_address, valid_packet); | 265 session_->ProcessUdpPacket(client_address, server_address, valid_packet); |
| 266 | 266 |
| 267 // Verify that a non-decryptable packet doesn't close the connection. | 267 // Verify that a non-decryptable packet doesn't close the connection. |
| 268 QuicConnectionId connection_id = session_->connection()->connection_id(); | 268 QuicConnectionId connection_id = session_->connection()->connection_id(); |
| 269 std::unique_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( | 269 std::unique_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( |
| 270 connection_id, false, false, 100, "data", PACKET_8BYTE_CONNECTION_ID, | 270 GetPeerInMemoryConnectionId(connection_id), false, false, 100, "data", |
| 271 PACKET_6BYTE_PACKET_NUMBER, nullptr, Perspective::IS_SERVER)); | 271 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, nullptr, |
| 272 Perspective::IS_SERVER)); |
| 272 std::unique_ptr<QuicReceivedPacket> received( | 273 std::unique_ptr<QuicReceivedPacket> received( |
| 273 ConstructReceivedPacket(*packet, QuicTime::Zero())); | 274 ConstructReceivedPacket(*packet, QuicTime::Zero())); |
| 274 // Change the last byte of the encrypted data. | 275 // Change the last byte of the encrypted data. |
| 275 *(const_cast<char*>(received->data() + received->length() - 1)) += 1; | 276 *(const_cast<char*>(received->data() + received->length() - 1)) += 1; |
| 276 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0); | 277 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0); |
| 277 EXPECT_CALL(*connection_, OnError(Truly(CheckForDecryptionError))).Times(1); | 278 EXPECT_CALL(*connection_, OnError(Truly(CheckForDecryptionError))).Times(1); |
| 278 session_->ProcessUdpPacket(client_address, server_address, *received); | 279 session_->ProcessUdpPacket(client_address, server_address, *received); |
| 279 } | 280 } |
| 280 | 281 |
| 281 // A packet with invalid framing should cause a connection to be closed. | 282 // A packet with invalid framing should cause a connection to be closed. |
| 282 TEST_P(QuicClientSessionTest, InvalidFramedPacketReceived) { | 283 TEST_P(QuicClientSessionTest, InvalidFramedPacketReceived) { |
| 283 QuicSocketAddress server_address(TestPeerIPAddress(), kTestPort); | 284 QuicSocketAddress server_address(TestPeerIPAddress(), kTestPort); |
| 284 QuicSocketAddress client_address(TestPeerIPAddress(), kTestPort); | 285 QuicSocketAddress client_address(TestPeerIPAddress(), kTestPort); |
| 285 | 286 |
| 286 EXPECT_CALL(*connection_, ProcessUdpPacket(server_address, client_address, _)) | 287 EXPECT_CALL(*connection_, ProcessUdpPacket(server_address, client_address, _)) |
| 287 .WillRepeatedly(Invoke(implicit_cast<MockQuicConnection*>(connection_), | 288 .WillRepeatedly(Invoke(implicit_cast<MockQuicConnection*>(connection_), |
| 288 &MockQuicConnection::ReallyProcessUdpPacket)); | 289 &MockQuicConnection::ReallyProcessUdpPacket)); |
| 289 EXPECT_CALL(*connection_, OnError(_)).Times(1); | 290 EXPECT_CALL(*connection_, OnError(_)).Times(1); |
| 290 | 291 |
| 291 // Verify that a decryptable packet with bad frames does close the connection. | 292 // Verify that a decryptable packet with bad frames does close the connection. |
| 292 QuicConnectionId connection_id = session_->connection()->connection_id(); | 293 QuicConnectionId connection_id = session_->connection()->connection_id(); |
| 293 QuicVersionVector versions = {GetParam()}; | 294 QuicVersionVector versions = {GetParam()}; |
| 294 std::unique_ptr<QuicEncryptedPacket> packet(ConstructMisFramedEncryptedPacket( | 295 std::unique_ptr<QuicEncryptedPacket> packet(ConstructMisFramedEncryptedPacket( |
| 295 connection_id, false, false, 100, "data", PACKET_8BYTE_CONNECTION_ID, | 296 GetPeerInMemoryConnectionId(connection_id), false, false, 100, "data", |
| 296 PACKET_6BYTE_PACKET_NUMBER, &versions, Perspective::IS_SERVER)); | 297 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, &versions, |
| 298 Perspective::IS_SERVER)); |
| 297 std::unique_ptr<QuicReceivedPacket> received( | 299 std::unique_ptr<QuicReceivedPacket> received( |
| 298 ConstructReceivedPacket(*packet, QuicTime::Zero())); | 300 ConstructReceivedPacket(*packet, QuicTime::Zero())); |
| 299 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(1); | 301 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(1); |
| 300 session_->ProcessUdpPacket(client_address, server_address, *received); | 302 session_->ProcessUdpPacket(client_address, server_address, *received); |
| 301 } | 303 } |
| 302 | 304 |
| 303 TEST_P(QuicClientSessionTest, PushPromiseOnPromiseHeaders) { | 305 TEST_P(QuicClientSessionTest, PushPromiseOnPromiseHeaders) { |
| 304 // Initialize crypto before the client session will create a stream. | 306 // Initialize crypto before the client session will create a stream. |
| 305 CompleteCryptoHandshake(); | 307 CompleteCryptoHandshake(); |
| 306 | 308 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 QuicClientPromisedInfo* promised = | 498 QuicClientPromisedInfo* promised = |
| 497 session_->GetPromisedById(promised_stream_id_); | 499 session_->GetPromisedById(promised_stream_id_); |
| 498 EXPECT_NE(promised, nullptr); | 500 EXPECT_NE(promised, nullptr); |
| 499 EXPECT_NE(session_->GetPromisedByUrl(promise_url_), nullptr); | 501 EXPECT_NE(session_->GetPromisedByUrl(promise_url_), nullptr); |
| 500 EXPECT_EQ(session_->GetPromisedStream(promised_stream_id_), nullptr); | 502 EXPECT_EQ(session_->GetPromisedStream(promised_stream_id_), nullptr); |
| 501 } | 503 } |
| 502 | 504 |
| 503 } // namespace | 505 } // namespace |
| 504 } // namespace test | 506 } // namespace test |
| 505 } // namespace net | 507 } // namespace net |
| OLD | NEW |