| 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/quic/quic_client_session.h" | 5 #include "net/quic/quic_client_session.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
| 12 #include "net/base/capturing_net_log.h" | 12 #include "net/base/capturing_net_log.h" |
| 13 #include "net/base/test_completion_callback.h" | 13 #include "net/base/test_completion_callback.h" |
| 14 #include "net/base/test_data_directory.h" | 14 #include "net/base/test_data_directory.h" |
| 15 #include "net/cert/cert_verify_result.h" | 15 #include "net/cert/cert_verify_result.h" |
| 16 #include "net/http/transport_security_state.h" | 16 #include "net/http/transport_security_state.h" |
| 17 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" | 17 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" |
| 18 #include "net/quic/crypto/crypto_protocol.h" | 18 #include "net/quic/crypto/crypto_protocol.h" |
| 19 #include "net/quic/crypto/proof_verifier_chromium.h" | 19 #include "net/quic/crypto/proof_verifier_chromium.h" |
| 20 #include "net/quic/crypto/quic_decrypter.h" | 20 #include "net/quic/crypto/quic_decrypter.h" |
| 21 #include "net/quic/crypto/quic_encrypter.h" | 21 #include "net/quic/crypto/quic_encrypter.h" |
| 22 #include "net/quic/crypto/quic_server_info.h" | 22 #include "net/quic/crypto/quic_server_info.h" |
| 23 #include "net/quic/quic_default_packet_writer.h" | |
| 24 #include "net/quic/test_tools/crypto_test_utils.h" | 23 #include "net/quic/test_tools/crypto_test_utils.h" |
| 25 #include "net/quic/test_tools/quic_client_session_peer.h" | 24 #include "net/quic/test_tools/quic_client_session_peer.h" |
| 26 #include "net/quic/test_tools/quic_test_utils.h" | 25 #include "net/quic/test_tools/quic_test_utils.h" |
| 27 #include "net/quic/test_tools/simple_quic_framer.h" | 26 #include "net/quic/test_tools/simple_quic_framer.h" |
| 28 #include "net/socket/socket_test_util.h" | 27 #include "net/socket/socket_test_util.h" |
| 29 #include "net/spdy/spdy_test_utils.h" | 28 #include "net/spdy/spdy_test_utils.h" |
| 30 #include "net/test/cert_test_util.h" | 29 #include "net/test/cert_test_util.h" |
| 31 #include "net/udp/datagram_client_socket.h" | 30 #include "net/udp/datagram_client_socket.h" |
| 32 | 31 |
| 33 using testing::_; | 32 using testing::_; |
| 34 | 33 |
| 35 namespace net { | 34 namespace net { |
| 36 namespace test { | 35 namespace test { |
| 37 namespace { | 36 namespace { |
| 38 | 37 |
| 39 const char kServerHostname[] = "www.example.org"; | 38 const char kServerHostname[] = "www.example.org"; |
| 40 const uint16 kServerPort = 80; | 39 const uint16 kServerPort = 80; |
| 41 | 40 |
| 42 class TestPacketWriter : public QuicDefaultPacketWriter { | |
| 43 public: | |
| 44 TestPacketWriter(QuicVersion version) : version_(version) {} | |
| 45 | |
| 46 // QuicPacketWriter | |
| 47 virtual WriteResult WritePacket( | |
| 48 const char* buffer, size_t buf_len, | |
| 49 const IPAddressNumber& self_address, | |
| 50 const IPEndPoint& peer_address) OVERRIDE { | |
| 51 SimpleQuicFramer framer(SupportedVersions(version_)); | |
| 52 QuicEncryptedPacket packet(buffer, buf_len); | |
| 53 EXPECT_TRUE(framer.ProcessPacket(packet)); | |
| 54 header_ = framer.header(); | |
| 55 return WriteResult(WRITE_STATUS_OK, packet.length()); | |
| 56 } | |
| 57 | |
| 58 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { | |
| 59 // Chrome sockets' Write() methods buffer the data until the Write is | |
| 60 // permitted. | |
| 61 return true; | |
| 62 } | |
| 63 | |
| 64 // Returns the header from the last packet written. | |
| 65 const QuicPacketHeader& header() { return header_; } | |
| 66 | |
| 67 private: | |
| 68 QuicVersion version_; | |
| 69 QuicPacketHeader header_; | |
| 70 }; | |
| 71 | |
| 72 class QuicClientSessionTest : public ::testing::TestWithParam<QuicVersion> { | 41 class QuicClientSessionTest : public ::testing::TestWithParam<QuicVersion> { |
| 73 protected: | 42 protected: |
| 74 QuicClientSessionTest() | 43 QuicClientSessionTest() |
| 75 : writer_(new TestPacketWriter(GetParam())), | 44 : connection_( |
| 76 connection_( | |
| 77 new PacketSavingConnection(false, SupportedVersions(GetParam()))), | 45 new PacketSavingConnection(false, SupportedVersions(GetParam()))), |
| 78 session_(connection_, GetSocket().Pass(), writer_.Pass(), NULL, NULL, | 46 session_(connection_, GetSocket().Pass(), NULL, NULL, |
| 79 &transport_security_state_, | 47 &transport_security_state_, |
| 80 make_scoped_ptr((QuicServerInfo*)NULL), | 48 make_scoped_ptr((QuicServerInfo*)NULL), |
| 81 QuicServerId(kServerHostname, kServerPort, false, | 49 QuicServerId(kServerHostname, kServerPort, false, |
| 82 PRIVACY_MODE_DISABLED), | 50 PRIVACY_MODE_DISABLED), |
| 83 DefaultQuicConfig(), &crypto_config_, | 51 DefaultQuicConfig(), &crypto_config_, |
| 84 base::MessageLoop::current()->message_loop_proxy().get(), | 52 base::MessageLoop::current()->message_loop_proxy().get(), |
| 85 &net_log_) { | 53 &net_log_) { |
| 86 session_.InitializeSession(); | 54 session_.InitializeSession(); |
| 87 session_.config()->SetDefaults(); | 55 session_.config()->SetDefaults(); |
| 88 crypto_config_.SetDefaults(); | 56 crypto_config_.SetDefaults(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 100 } | 68 } |
| 101 | 69 |
| 102 void CompleteCryptoHandshake() { | 70 void CompleteCryptoHandshake() { |
| 103 ASSERT_EQ(ERR_IO_PENDING, | 71 ASSERT_EQ(ERR_IO_PENDING, |
| 104 session_.CryptoConnect(false, callback_.callback())); | 72 session_.CryptoConnect(false, callback_.callback())); |
| 105 CryptoTestUtils::HandshakeWithFakeServer( | 73 CryptoTestUtils::HandshakeWithFakeServer( |
| 106 connection_, session_.GetCryptoStream()); | 74 connection_, session_.GetCryptoStream()); |
| 107 ASSERT_EQ(OK, callback_.WaitForResult()); | 75 ASSERT_EQ(OK, callback_.WaitForResult()); |
| 108 } | 76 } |
| 109 | 77 |
| 110 scoped_ptr<QuicDefaultPacketWriter> writer_; | |
| 111 PacketSavingConnection* connection_; | 78 PacketSavingConnection* connection_; |
| 112 CapturingNetLog net_log_; | 79 CapturingNetLog net_log_; |
| 113 MockClientSocketFactory socket_factory_; | 80 MockClientSocketFactory socket_factory_; |
| 114 StaticSocketDataProvider socket_data_; | 81 StaticSocketDataProvider socket_data_; |
| 115 TransportSecurityState transport_security_state_; | 82 TransportSecurityState transport_security_state_; |
| 116 QuicClientSession session_; | 83 QuicClientSession session_; |
| 117 MockClock clock_; | 84 MockClock clock_; |
| 118 MockRandom random_; | 85 MockRandom random_; |
| 119 QuicConnectionVisitorInterface* visitor_; | 86 QuicConnectionVisitorInterface* visitor_; |
| 120 TestCompletionCallback callback_; | 87 TestCompletionCallback callback_; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 session_.OnProofVerifyDetailsAvailable(details); | 227 session_.OnProofVerifyDetailsAvailable(details); |
| 261 CompleteCryptoHandshake(); | 228 CompleteCryptoHandshake(); |
| 262 QuicClientSessionPeer::SetChannelIDSent(&session_, true); | 229 QuicClientSessionPeer::SetChannelIDSent(&session_, true); |
| 263 | 230 |
| 264 EXPECT_TRUE(session_.CanPool("mail.example.org")); | 231 EXPECT_TRUE(session_.CanPool("mail.example.org")); |
| 265 } | 232 } |
| 266 | 233 |
| 267 } // namespace | 234 } // namespace |
| 268 } // namespace test | 235 } // namespace test |
| 269 } // namespace net | 236 } // namespace net |
| OLD | NEW |