| 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_crypto_client_stream.h" | 5 #include "net/quic/quic_crypto_client_stream.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" | 8 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" |
| 9 #include "net/quic/crypto/quic_decrypter.h" | 9 #include "net/quic/crypto/quic_decrypter.h" |
| 10 #include "net/quic/crypto/quic_encrypter.h" | 10 #include "net/quic/crypto/quic_encrypter.h" |
| 11 #include "net/quic/quic_protocol.h" | 11 #include "net/quic/quic_protocol.h" |
| 12 #include "net/quic/test_tools/crypto_test_utils.h" | 12 #include "net/quic/test_tools/crypto_test_utils.h" |
| 13 #include "net/quic/test_tools/quic_test_utils.h" | 13 #include "net/quic/test_tools/quic_test_utils.h" |
| 14 #include "net/quic/test_tools/simple_quic_framer.h" | 14 #include "net/quic/test_tools/simple_quic_framer.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 namespace test { | 19 namespace test { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 const char kServerHostname[] = "example.com"; | 22 const char kServerHostname[] = "example.com"; |
| 23 | 23 |
| 24 class QuicCryptoClientStreamTest : public ::testing::Test { | 24 class QuicCryptoClientStreamTest : public ::testing::Test { |
| 25 public: | 25 public: |
| 26 QuicCryptoClientStreamTest() | 26 QuicCryptoClientStreamTest() |
| 27 : connection_(new PacketSavingConnection(false)), | 27 : connection_(new PacketSavingConnection(false)), |
| 28 session_(new TestSession(connection_, DefaultQuicConfig(), false)), | 28 session_(new TestSession(connection_, DefaultQuicConfig())), |
| 29 stream_(new QuicCryptoClientStream(kServerHostname, session_.get(), | 29 stream_(new QuicCryptoClientStream(kServerHostname, session_.get(), |
| 30 &crypto_config_)) { | 30 &crypto_config_)) { |
| 31 session_->SetCryptoStream(stream_.get()); | 31 session_->SetCryptoStream(stream_.get()); |
| 32 crypto_config_.SetDefaults(); | 32 crypto_config_.SetDefaults(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void CompleteCryptoHandshake() { | 35 void CompleteCryptoHandshake() { |
| 36 EXPECT_TRUE(stream_->CryptoConnect()); | 36 EXPECT_TRUE(stream_->CryptoConnect()); |
| 37 CryptoTestUtils::HandshakeWithFakeServer(connection_, stream_.get()); | 37 CryptoTestUtils::HandshakeWithFakeServer(connection_, stream_.get()); |
| 38 } | 38 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 CompleteCryptoHandshake(); | 107 CompleteCryptoHandshake(); |
| 108 EXPECT_TRUE(stream_->encryption_established()); | 108 EXPECT_TRUE(stream_->encryption_established()); |
| 109 EXPECT_TRUE(stream_->handshake_confirmed()); | 109 EXPECT_TRUE(stream_->handshake_confirmed()); |
| 110 } | 110 } |
| 111 | 111 |
| 112 TEST_F(QuicCryptoClientStreamTest, ExpiredServerConfig) { | 112 TEST_F(QuicCryptoClientStreamTest, ExpiredServerConfig) { |
| 113 // Seed the config with a cached server config. | 113 // Seed the config with a cached server config. |
| 114 CompleteCryptoHandshake(); | 114 CompleteCryptoHandshake(); |
| 115 | 115 |
| 116 connection_ = new PacketSavingConnection(true); | 116 connection_ = new PacketSavingConnection(true); |
| 117 session_.reset(new TestSession(connection_, DefaultQuicConfig(), true)); | 117 session_.reset(new TestSession(connection_, DefaultQuicConfig())); |
| 118 stream_.reset(new QuicCryptoClientStream(kServerHostname, session_.get(), | 118 stream_.reset(new QuicCryptoClientStream(kServerHostname, session_.get(), |
| 119 &crypto_config_)); | 119 &crypto_config_)); |
| 120 | 120 |
| 121 session_->SetCryptoStream(stream_.get()); | 121 session_->SetCryptoStream(stream_.get()); |
| 122 session_->config()->SetDefaults(); | 122 session_->config()->SetDefaults(); |
| 123 | 123 |
| 124 // Advance time 5 years to ensure that we pass the expiry time of the cached | 124 // Advance time 5 years to ensure that we pass the expiry time of the cached |
| 125 // server config. | 125 // server config. |
| 126 reinterpret_cast<MockClock*>(const_cast<QuicClock*>(connection_->clock())) | 126 reinterpret_cast<MockClock*>(const_cast<QuicClock*>(connection_->clock())) |
| 127 ->AdvanceTime(QuicTime::Delta::FromSeconds(60 * 60 * 24 * 365 * 5)); | 127 ->AdvanceTime(QuicTime::Delta::FromSeconds(60 * 60 * 24 * 365 * 5)); |
| 128 | 128 |
| 129 // Check that a client hello was sent and that CryptoConnect doesn't fail | 129 // Check that a client hello was sent and that CryptoConnect doesn't fail |
| 130 // with an error. | 130 // with an error. |
| 131 EXPECT_TRUE(stream_->CryptoConnect()); | 131 EXPECT_TRUE(stream_->CryptoConnect()); |
| 132 ASSERT_EQ(1u, connection_->packets_.size()); | 132 ASSERT_EQ(1u, connection_->packets_.size()); |
| 133 } | 133 } |
| 134 | 134 |
| 135 } // namespace | 135 } // namespace |
| 136 } // namespace test | 136 } // namespace test |
| 137 } // namespace net | 137 } // namespace net |
| OLD | NEW |