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

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

Issue 218923002: Merge internal change: 63891842 - QuicServerId changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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"
11 #include "net/quic/quic_flags.h" 11 #include "net/quic/quic_flags.h"
12 #include "net/quic/quic_protocol.h" 12 #include "net/quic/quic_protocol.h"
13 #include "net/quic/quic_session_key.h" 13 #include "net/quic/quic_server_id.h"
14 #include "net/quic/test_tools/crypto_test_utils.h" 14 #include "net/quic/test_tools/crypto_test_utils.h"
15 #include "net/quic/test_tools/quic_test_utils.h" 15 #include "net/quic/test_tools/quic_test_utils.h"
16 #include "net/quic/test_tools/simple_quic_framer.h" 16 #include "net/quic/test_tools/simple_quic_framer.h"
17 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 namespace net { 20 namespace net {
21 namespace test { 21 namespace test {
22 namespace { 22 namespace {
23 23
24 const char kServerHostname[] = "example.com"; 24 const char kServerHostname[] = "example.com";
25 const uint16 kServerPort = 80; 25 const uint16 kServerPort = 80;
26 26
27 class QuicCryptoClientStreamTest : public ::testing::Test { 27 class QuicCryptoClientStreamTest : public ::testing::Test {
28 public: 28 public:
29 QuicCryptoClientStreamTest() 29 QuicCryptoClientStreamTest()
30 : connection_(new PacketSavingConnection(false)), 30 : connection_(new PacketSavingConnection(false)),
31 session_(new TestClientSession(connection_, DefaultQuicConfig())), 31 session_(new TestClientSession(connection_, DefaultQuicConfig())),
32 server_key_(kServerHostname, kServerPort, false, kPrivacyModeDisabled), 32 server_id_(kServerHostname, kServerPort, false, kPrivacyModeDisabled),
33 stream_(new QuicCryptoClientStream( 33 stream_(new QuicCryptoClientStream(
34 server_key_, session_.get(), NULL, &crypto_config_)) { 34 server_id_, session_.get(), NULL, &crypto_config_)) {
35 session_->SetCryptoStream(stream_.get()); 35 session_->SetCryptoStream(stream_.get());
36 session_->config()->SetDefaults(); 36 session_->config()->SetDefaults();
37 crypto_config_.SetDefaults(); 37 crypto_config_.SetDefaults();
38 } 38 }
39 39
40 void CompleteCryptoHandshake() { 40 void CompleteCryptoHandshake() {
41 EXPECT_TRUE(stream_->CryptoConnect()); 41 EXPECT_TRUE(stream_->CryptoConnect());
42 CryptoTestUtils::HandshakeWithFakeServer(connection_, stream_.get()); 42 CryptoTestUtils::HandshakeWithFakeServer(connection_, stream_.get());
43 } 43 }
44 44
45 void ConstructHandshakeMessage() { 45 void ConstructHandshakeMessage() {
46 CryptoFramer framer; 46 CryptoFramer framer;
47 message_data_.reset(framer.ConstructHandshakeMessage(message_)); 47 message_data_.reset(framer.ConstructHandshakeMessage(message_));
48 } 48 }
49 49
50 PacketSavingConnection* connection_; 50 PacketSavingConnection* connection_;
51 scoped_ptr<TestClientSession> session_; 51 scoped_ptr<TestClientSession> session_;
52 QuicSessionKey server_key_; 52 QuicServerId server_id_;
53 scoped_ptr<QuicCryptoClientStream> stream_; 53 scoped_ptr<QuicCryptoClientStream> stream_;
54 CryptoHandshakeMessage message_; 54 CryptoHandshakeMessage message_;
55 scoped_ptr<QuicData> message_data_; 55 scoped_ptr<QuicData> message_data_;
56 QuicCryptoClientConfig crypto_config_; 56 QuicCryptoClientConfig crypto_config_;
57 }; 57 };
58 58
59 TEST_F(QuicCryptoClientStreamTest, NotInitiallyConected) { 59 TEST_F(QuicCryptoClientStreamTest, NotInitiallyConected) {
60 EXPECT_FALSE(stream_->encryption_established()); 60 EXPECT_FALSE(stream_->encryption_established());
61 EXPECT_FALSE(stream_->handshake_confirmed()); 61 EXPECT_FALSE(stream_->handshake_confirmed());
62 } 62 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 config->max_streams_per_connection()); 100 config->max_streams_per_connection());
101 EXPECT_EQ(0, config->keepalive_timeout().ToSeconds()); 101 EXPECT_EQ(0, config->keepalive_timeout().ToSeconds());
102 102
103 const QuicCryptoNegotiatedParameters& crypto_params( 103 const QuicCryptoNegotiatedParameters& crypto_params(
104 stream_->crypto_negotiated_params()); 104 stream_->crypto_negotiated_params());
105 EXPECT_EQ(crypto_config_.aead[0], crypto_params.aead); 105 EXPECT_EQ(crypto_config_.aead[0], crypto_params.aead);
106 EXPECT_EQ(crypto_config_.kexs[0], crypto_params.key_exchange); 106 EXPECT_EQ(crypto_config_.kexs[0], crypto_params.key_exchange);
107 } 107 }
108 108
109 TEST_F(QuicCryptoClientStreamTest, InvalidHostname) { 109 TEST_F(QuicCryptoClientStreamTest, InvalidHostname) {
110 QuicSessionKey server_key("invalid", 80, false, kPrivacyModeDisabled); 110 QuicServerId server_id("invalid", 80, false, kPrivacyModeDisabled);
111 stream_.reset(new QuicCryptoClientStream(server_key, session_.get(), NULL, 111 stream_.reset(new QuicCryptoClientStream(server_id, session_.get(), NULL,
112 &crypto_config_)); 112 &crypto_config_));
113 session_->SetCryptoStream(stream_.get()); 113 session_->SetCryptoStream(stream_.get());
114 114
115 CompleteCryptoHandshake(); 115 CompleteCryptoHandshake();
116 EXPECT_TRUE(stream_->encryption_established()); 116 EXPECT_TRUE(stream_->encryption_established());
117 EXPECT_TRUE(stream_->handshake_confirmed()); 117 EXPECT_TRUE(stream_->handshake_confirmed());
118 } 118 }
119 119
120 TEST_F(QuicCryptoClientStreamTest, ExpiredServerConfig) { 120 TEST_F(QuicCryptoClientStreamTest, ExpiredServerConfig) {
121 // Seed the config with a cached server config. 121 // Seed the config with a cached server config.
122 CompleteCryptoHandshake(); 122 CompleteCryptoHandshake();
123 123
124 connection_ = new PacketSavingConnection(true); 124 connection_ = new PacketSavingConnection(true);
125 session_.reset(new TestClientSession(connection_, DefaultQuicConfig())); 125 session_.reset(new TestClientSession(connection_, DefaultQuicConfig()));
126 stream_.reset(new QuicCryptoClientStream(server_key_, session_.get(), NULL, 126 stream_.reset(new QuicCryptoClientStream(server_id_, session_.get(), NULL,
127 &crypto_config_)); 127 &crypto_config_));
128 128
129 session_->SetCryptoStream(stream_.get()); 129 session_->SetCryptoStream(stream_.get());
130 session_->config()->SetDefaults(); 130 session_->config()->SetDefaults();
131 131
132 // Advance time 5 years to ensure that we pass the expiry time of the cached 132 // Advance time 5 years to ensure that we pass the expiry time of the cached
133 // server config. 133 // server config.
134 reinterpret_cast<MockClock*>(const_cast<QuicClock*>(connection_->clock())) 134 reinterpret_cast<MockClock*>(const_cast<QuicClock*>(connection_->clock()))
135 ->AdvanceTime(QuicTime::Delta::FromSeconds(60 * 60 * 24 * 365 * 5)); 135 ->AdvanceTime(QuicTime::Delta::FromSeconds(60 * 60 * 24 * 365 * 5));
136 136
137 // Check that a client hello was sent and that CryptoConnect doesn't fail 137 // Check that a client hello was sent and that CryptoConnect doesn't fail
138 // with an error. 138 // with an error.
139 EXPECT_TRUE(stream_->CryptoConnect()); 139 EXPECT_TRUE(stream_->CryptoConnect());
140 ASSERT_EQ(1u, connection_->packets_.size()); 140 ASSERT_EQ(1u, connection_->packets_.size());
141 } 141 }
142 142
143 } // namespace 143 } // namespace
144 } // namespace test 144 } // namespace test
145 } // namespace net 145 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698