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