Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(655)

Side by Side Diff: net/quic/quic_crypto_client_stream_test.cc

Issue 15937012: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Small bug fixes Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 bool frame_valid_; 44 bool frame_valid_;
45 45
46 DISALLOW_COPY_AND_ASSIGN(TestQuicVisitor); 46 DISALLOW_COPY_AND_ASSIGN(TestQuicVisitor);
47 }; 47 };
48 48
49 class QuicCryptoClientStreamTest : public ::testing::Test { 49 class QuicCryptoClientStreamTest : public ::testing::Test {
50 public: 50 public:
51 QuicCryptoClientStreamTest() 51 QuicCryptoClientStreamTest()
52 : addr_(), 52 : addr_(),
53 connection_(new PacketSavingConnection(1, addr_, true)), 53 connection_(new PacketSavingConnection(1, addr_, true)),
54 session_(connection_, QuicConfig(), true), 54 session_(new TestSession(connection_, DefaultQuicConfig(), true)),
55 stream_(new QuicCryptoClientStream(kServerHostname, &session_, 55 stream_(new QuicCryptoClientStream(kServerHostname, session_.get(),
56 &crypto_config_)) { 56 &crypto_config_)) {
57 session_.SetCryptoStream(stream_.get()); 57 session_->SetCryptoStream(stream_.get());
58 session_.config()->SetDefaults();
59 crypto_config_.SetDefaults(); 58 crypto_config_.SetDefaults();
60 } 59 }
61 60
62 void CompleteCryptoHandshake() { 61 void CompleteCryptoHandshake() {
63 EXPECT_TRUE(stream_->CryptoConnect()); 62 EXPECT_TRUE(stream_->CryptoConnect());
64 CryptoTestUtils::HandshakeWithFakeServer(connection_, stream_.get()); 63 CryptoTestUtils::HandshakeWithFakeServer(connection_, stream_.get());
65 } 64 }
66 65
67 void ConstructHandshakeMessage() { 66 void ConstructHandshakeMessage() {
68 CryptoFramer framer; 67 CryptoFramer framer;
69 message_data_.reset(framer.ConstructHandshakeMessage(message_)); 68 message_data_.reset(framer.ConstructHandshakeMessage(message_));
70 } 69 }
71 70
72 IPEndPoint addr_; 71 IPEndPoint addr_;
73 PacketSavingConnection* connection_; 72 PacketSavingConnection* connection_;
74 TestSession session_; 73 scoped_ptr<TestSession> session_;
75 scoped_ptr<QuicCryptoClientStream> stream_; 74 scoped_ptr<QuicCryptoClientStream> stream_;
76 CryptoHandshakeMessage message_; 75 CryptoHandshakeMessage message_;
77 scoped_ptr<QuicData> message_data_; 76 scoped_ptr<QuicData> message_data_;
78 QuicCryptoClientConfig crypto_config_; 77 QuicCryptoClientConfig crypto_config_;
79 }; 78 };
80 79
81 TEST_F(QuicCryptoClientStreamTest, NotInitiallyConected) { 80 TEST_F(QuicCryptoClientStreamTest, NotInitiallyConected) {
82 if (!Aes128Gcm12Encrypter::IsSupported()) { 81 if (!Aes128Gcm12Encrypter::IsSupported()) {
83 LOG(INFO) << "AES GCM not supported. Test skipped."; 82 LOG(INFO) << "AES GCM not supported. Test skipped.";
84 return; 83 return;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 130 }
132 131
133 TEST_F(QuicCryptoClientStreamTest, NegotiatedParameters) { 132 TEST_F(QuicCryptoClientStreamTest, NegotiatedParameters) {
134 if (!Aes128Gcm12Encrypter::IsSupported()) { 133 if (!Aes128Gcm12Encrypter::IsSupported()) {
135 LOG(INFO) << "AES GCM not supported. Test skipped."; 134 LOG(INFO) << "AES GCM not supported. Test skipped.";
136 return; 135 return;
137 } 136 }
138 137
139 CompleteCryptoHandshake(); 138 CompleteCryptoHandshake();
140 139
141 const QuicConfig* config = session_.config(); 140 const QuicConfig* config = session_->config();
142 EXPECT_EQ(kQBIC, config->congestion_control()); 141 EXPECT_EQ(kQBIC, config->congestion_control());
143 EXPECT_EQ(kDefaultTimeoutSecs, 142 EXPECT_EQ(kDefaultTimeoutSecs,
144 config->idle_connection_state_lifetime().ToSeconds()); 143 config->idle_connection_state_lifetime().ToSeconds());
145 EXPECT_EQ(kDefaultMaxStreamsPerConnection, 144 EXPECT_EQ(kDefaultMaxStreamsPerConnection,
146 config->max_streams_per_connection()); 145 config->max_streams_per_connection());
147 EXPECT_EQ(0, config->keepalive_timeout().ToSeconds()); 146 EXPECT_EQ(0, config->keepalive_timeout().ToSeconds());
148 147
149 const QuicCryptoNegotiatedParameters& crypto_params( 148 const QuicCryptoNegotiatedParameters& crypto_params(
150 stream_->crypto_negotiated_params()); 149 stream_->crypto_negotiated_params());
151 EXPECT_EQ(kAESG, crypto_params.aead); 150 EXPECT_EQ(kAESG, crypto_params.aead);
152 EXPECT_EQ(kC255, crypto_params.key_exchange); 151 EXPECT_EQ(kC255, crypto_params.key_exchange);
153 } 152 }
154 153
155 TEST_F(QuicCryptoClientStreamTest, InvalidHostname) { 154 TEST_F(QuicCryptoClientStreamTest, InvalidHostname) {
156 if (!Aes128Gcm12Encrypter::IsSupported()) { 155 if (!Aes128Gcm12Encrypter::IsSupported()) {
157 LOG(INFO) << "AES GCM not supported. Test skipped."; 156 LOG(INFO) << "AES GCM not supported. Test skipped.";
158 return; 157 return;
159 } 158 }
160 159
161 stream_.reset(new QuicCryptoClientStream("invalid", &session_, 160 stream_.reset(new QuicCryptoClientStream("invalid", session_.get(),
162 &crypto_config_)); 161 &crypto_config_));
163 session_.SetCryptoStream(stream_.get()); 162 session_->SetCryptoStream(stream_.get());
164 163
165 CompleteCryptoHandshake(); 164 CompleteCryptoHandshake();
166 EXPECT_TRUE(stream_->encryption_established()); 165 EXPECT_TRUE(stream_->encryption_established());
167 EXPECT_TRUE(stream_->handshake_confirmed()); 166 EXPECT_TRUE(stream_->handshake_confirmed());
168 } 167 }
169 168
169 TEST_F(QuicCryptoClientStreamTest, ExpiredServerConfig) {
170 // Seed the config with a cached server config.
171 CompleteCryptoHandshake();
172
173 connection_ = new PacketSavingConnection(1, addr_, true);
174 session_.reset(new TestSession(connection_, QuicConfig(), true));
175 stream_.reset(new QuicCryptoClientStream(kServerHostname, session_.get(),
176 &crypto_config_));
177
178 session_->SetCryptoStream(stream_.get());
179 session_->config()->SetDefaults();
180
181 // Advance time 5 years to ensure that we pass the expiry time of the cached
182 // server config.
183 reinterpret_cast<MockClock*>(const_cast<QuicClock*>(connection_->clock()))
184 ->AdvanceTime(QuicTime::Delta::FromSeconds(60 * 60 * 24 * 365 * 5));
185
186 // Check that a client hello was sent and that CryptoConnect doesn't fail
187 // with an error.
188 EXPECT_TRUE(stream_->CryptoConnect());
189 ASSERT_EQ(1u, connection_->packets_.size());
190 }
191
170 } // namespace 192 } // namespace
171 } // namespace test 193 } // namespace test
172 } // namespace net 194 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698