| 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 <memory> |
| 7 #include <vector> | 8 #include <vector> |
| 8 | 9 |
| 9 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 10 #include "net/base/ip_endpoint.h" | 11 #include "net/base/ip_endpoint.h" |
| 11 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" | 12 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" |
| 12 #include "net/quic/quic_flags.h" | 13 #include "net/quic/quic_flags.h" |
| 13 #include "net/quic/spdy_utils.h" | 14 #include "net/quic/spdy_utils.h" |
| 14 #include "net/quic/test_tools/crypto_test_utils.h" | 15 #include "net/quic/test_tools/crypto_test_utils.h" |
| 15 #include "net/quic/test_tools/mock_quic_spdy_client_stream.h" | 16 #include "net/quic/test_tools/mock_quic_spdy_client_stream.h" |
| 16 #include "net/quic/test_tools/quic_connection_peer.h" | 17 #include "net/quic/test_tools/quic_connection_peer.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 static_cast<QuicCryptoClientStream*>(session_->GetCryptoStream()); | 117 static_cast<QuicCryptoClientStream*>(session_->GetCryptoStream()); |
| 117 CryptoTestUtils::FakeServerOptions options; | 118 CryptoTestUtils::FakeServerOptions options; |
| 118 CryptoTestUtils::HandshakeWithFakeServer(&helper_, &alarm_factory_, | 119 CryptoTestUtils::HandshakeWithFakeServer(&helper_, &alarm_factory_, |
| 119 connection_, stream, options); | 120 connection_, stream, options); |
| 120 } | 121 } |
| 121 | 122 |
| 122 QuicCryptoClientConfig crypto_config_; | 123 QuicCryptoClientConfig crypto_config_; |
| 123 MockConnectionHelper helper_; | 124 MockConnectionHelper helper_; |
| 124 MockAlarmFactory alarm_factory_; | 125 MockAlarmFactory alarm_factory_; |
| 125 PacketSavingConnection* connection_; | 126 PacketSavingConnection* connection_; |
| 126 scoped_ptr<TestQuicClientSession> session_; | 127 std::unique_ptr<TestQuicClientSession> session_; |
| 127 QuicClientPushPromiseIndex push_promise_index_; | 128 QuicClientPushPromiseIndex push_promise_index_; |
| 128 SpdyHeaderBlock push_promise_; | 129 SpdyHeaderBlock push_promise_; |
| 129 string promise_url_; | 130 string promise_url_; |
| 130 QuicStreamId promised_stream_id_; | 131 QuicStreamId promised_stream_id_; |
| 131 QuicStreamId associated_stream_id_; | 132 QuicStreamId associated_stream_id_; |
| 132 }; | 133 }; |
| 133 | 134 |
| 134 INSTANTIATE_TEST_CASE_P(Tests, | 135 INSTANTIATE_TEST_CASE_P(Tests, |
| 135 QuicClientSessionTest, | 136 QuicClientSessionTest, |
| 136 ::testing::ValuesIn(QuicSupportedVersions())); | 137 ::testing::ValuesIn(QuicSupportedVersions())); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 259 |
| 259 // Verifiy that small, invalid packets don't close the connection. | 260 // Verifiy that small, invalid packets don't close the connection. |
| 260 char buf[2] = {0x00, 0x01}; | 261 char buf[2] = {0x00, 0x01}; |
| 261 QuicReceivedPacket valid_packet(buf, 2, QuicTime::Zero(), false); | 262 QuicReceivedPacket valid_packet(buf, 2, QuicTime::Zero(), false); |
| 262 // Close connection shouldn't be called. | 263 // Close connection shouldn't be called. |
| 263 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0); | 264 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0); |
| 264 session_->ProcessUdpPacket(client_address, server_address, valid_packet); | 265 session_->ProcessUdpPacket(client_address, server_address, valid_packet); |
| 265 | 266 |
| 266 // Verify that a non-decryptable packet doesn't close the connection. | 267 // Verify that a non-decryptable packet doesn't close the connection. |
| 267 QuicConnectionId connection_id = session_->connection()->connection_id(); | 268 QuicConnectionId connection_id = session_->connection()->connection_id(); |
| 268 scoped_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( | 269 std::unique_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( |
| 269 connection_id, false, false, false, kDefaultPathId, 100, "data")); | 270 connection_id, false, false, false, kDefaultPathId, 100, "data")); |
| 270 scoped_ptr<QuicReceivedPacket> received( | 271 std::unique_ptr<QuicReceivedPacket> received( |
| 271 ConstructReceivedPacket(*packet, QuicTime::Zero())); | 272 ConstructReceivedPacket(*packet, QuicTime::Zero())); |
| 272 // Change the last byte of the encrypted data. | 273 // Change the last byte of the encrypted data. |
| 273 *(const_cast<char*>(received->data() + received->length() - 1)) += 1; | 274 *(const_cast<char*>(received->data() + received->length() - 1)) += 1; |
| 274 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0); | 275 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(0); |
| 275 EXPECT_CALL(*connection_, OnError(Truly(CheckForDecryptionError))).Times(1); | 276 EXPECT_CALL(*connection_, OnError(Truly(CheckForDecryptionError))).Times(1); |
| 276 session_->ProcessUdpPacket(client_address, server_address, *received); | 277 session_->ProcessUdpPacket(client_address, server_address, *received); |
| 277 } | 278 } |
| 278 | 279 |
| 279 // A packet with invalid framing should cause a connection to be closed. | 280 // A packet with invalid framing should cause a connection to be closed. |
| 280 TEST_P(QuicClientSessionTest, InvalidFramedPacketReceived) { | 281 TEST_P(QuicClientSessionTest, InvalidFramedPacketReceived) { |
| 281 IPEndPoint server_address(TestPeerIPAddress(), kTestPort); | 282 IPEndPoint server_address(TestPeerIPAddress(), kTestPort); |
| 282 IPEndPoint client_address(TestPeerIPAddress(), kTestPort); | 283 IPEndPoint client_address(TestPeerIPAddress(), kTestPort); |
| 283 | 284 |
| 284 EXPECT_CALL(*connection_, ProcessUdpPacket(server_address, client_address, _)) | 285 EXPECT_CALL(*connection_, ProcessUdpPacket(server_address, client_address, _)) |
| 285 .WillRepeatedly(Invoke(static_cast<MockConnection*>(connection_), | 286 .WillRepeatedly(Invoke(static_cast<MockConnection*>(connection_), |
| 286 &MockConnection::ReallyProcessUdpPacket)); | 287 &MockConnection::ReallyProcessUdpPacket)); |
| 287 EXPECT_CALL(*connection_, OnError(_)).Times(1); | 288 EXPECT_CALL(*connection_, OnError(_)).Times(1); |
| 288 | 289 |
| 289 // Verify that a decryptable packet with bad frames does close the connection. | 290 // Verify that a decryptable packet with bad frames does close the connection. |
| 290 QuicConnectionId connection_id = session_->connection()->connection_id(); | 291 QuicConnectionId connection_id = session_->connection()->connection_id(); |
| 291 scoped_ptr<QuicEncryptedPacket> packet(ConstructMisFramedEncryptedPacket( | 292 std::unique_ptr<QuicEncryptedPacket> packet(ConstructMisFramedEncryptedPacket( |
| 292 connection_id, false, false, false, kDefaultPathId, 100, "data", | 293 connection_id, false, false, false, kDefaultPathId, 100, "data", |
| 293 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, nullptr)); | 294 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, nullptr)); |
| 294 scoped_ptr<QuicReceivedPacket> received( | 295 std::unique_ptr<QuicReceivedPacket> received( |
| 295 ConstructReceivedPacket(*packet, QuicTime::Zero())); | 296 ConstructReceivedPacket(*packet, QuicTime::Zero())); |
| 296 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(1); | 297 EXPECT_CALL(*connection_, CloseConnection(_, _, _)).Times(1); |
| 297 session_->ProcessUdpPacket(client_address, server_address, *received); | 298 session_->ProcessUdpPacket(client_address, server_address, *received); |
| 298 } | 299 } |
| 299 | 300 |
| 300 TEST_P(QuicClientSessionTest, PushPromiseOnPromiseHeaders) { | 301 TEST_P(QuicClientSessionTest, PushPromiseOnPromiseHeaders) { |
| 301 // Initialize crypto before the client session will create a stream. | 302 // Initialize crypto before the client session will create a stream. |
| 302 CompleteCryptoHandshake(); | 303 CompleteCryptoHandshake(); |
| 303 | 304 |
| 304 MockQuicSpdyClientStream* stream = static_cast<MockQuicSpdyClientStream*>( | 305 MockQuicSpdyClientStream* stream = static_cast<MockQuicSpdyClientStream*>( |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 QuicClientPromisedInfo* promised = | 507 QuicClientPromisedInfo* promised = |
| 507 session_->GetPromisedById(promised_stream_id_); | 508 session_->GetPromisedById(promised_stream_id_); |
| 508 EXPECT_NE(promised, nullptr); | 509 EXPECT_NE(promised, nullptr); |
| 509 EXPECT_NE(session_->GetPromisedByUrl(promise_url_), nullptr); | 510 EXPECT_NE(session_->GetPromisedByUrl(promise_url_), nullptr); |
| 510 EXPECT_EQ(session_->GetPromisedStream(promised_stream_id_), nullptr); | 511 EXPECT_EQ(session_->GetPromisedStream(promised_stream_id_), nullptr); |
| 511 } | 512 } |
| 512 | 513 |
| 513 } // namespace | 514 } // namespace |
| 514 } // namespace test | 515 } // namespace test |
| 515 } // namespace net | 516 } // namespace net |
| OLD | NEW |