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

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

Issue 355293003: Restrict QUIC session pool when channel ID is present. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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_client_session.h" 5 #include "net/quic/quic_client_session.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/files/file_path.h"
9 #include "base/rand_util.h" 10 #include "base/rand_util.h"
10 #include "net/base/capturing_net_log.h" 11 #include "net/base/capturing_net_log.h"
11 #include "net/base/test_completion_callback.h" 12 #include "net/base/test_completion_callback.h"
13 #include "net/base/test_data_directory.h"
12 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" 14 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h"
13 #include "net/quic/crypto/crypto_protocol.h" 15 #include "net/quic/crypto/crypto_protocol.h"
14 #include "net/quic/crypto/quic_decrypter.h" 16 #include "net/quic/crypto/quic_decrypter.h"
15 #include "net/quic/crypto/quic_encrypter.h" 17 #include "net/quic/crypto/quic_encrypter.h"
16 #include "net/quic/crypto/quic_server_info.h" 18 #include "net/quic/crypto/quic_server_info.h"
17 #include "net/quic/quic_default_packet_writer.h" 19 #include "net/quic/quic_default_packet_writer.h"
18 #include "net/quic/test_tools/crypto_test_utils.h" 20 #include "net/quic/test_tools/crypto_test_utils.h"
19 #include "net/quic/test_tools/quic_client_session_peer.h" 21 #include "net/quic/test_tools/quic_client_session_peer.h"
20 #include "net/quic/test_tools/quic_test_utils.h" 22 #include "net/quic/test_tools/quic_test_utils.h"
21 #include "net/quic/test_tools/simple_quic_framer.h" 23 #include "net/quic/test_tools/simple_quic_framer.h"
22 #include "net/socket/socket_test_util.h" 24 #include "net/socket/socket_test_util.h"
25 #include "net/test/cert_test_util.h"
23 #include "net/udp/datagram_client_socket.h" 26 #include "net/udp/datagram_client_socket.h"
24 27
25 using testing::_; 28 using testing::_;
26 29
27 namespace net { 30 namespace net {
28 namespace test { 31 namespace test {
29 namespace { 32 namespace {
30 33
31 const char kServerHostname[] = "www.example.com"; 34 const char kServerHostname[] = "www.example.com";
32 const uint16 kServerPort = 80; 35 const uint16 kServerPort = 80;
(...skipping 27 matching lines...) Expand all
60 QuicVersion version_; 63 QuicVersion version_;
61 QuicPacketHeader header_; 64 QuicPacketHeader header_;
62 }; 65 };
63 66
64 class QuicClientSessionTest : public ::testing::TestWithParam<QuicVersion> { 67 class QuicClientSessionTest : public ::testing::TestWithParam<QuicVersion> {
65 protected: 68 protected:
66 QuicClientSessionTest() 69 QuicClientSessionTest()
67 : writer_(new TestPacketWriter(GetParam())), 70 : writer_(new TestPacketWriter(GetParam())),
68 connection_( 71 connection_(
69 new PacketSavingConnection(false, SupportedVersions(GetParam()))), 72 new PacketSavingConnection(false, SupportedVersions(GetParam()))),
70 session_(connection_, GetSocket().Pass(), writer_.Pass(), NULL, NULL, 73 session_(host_port_pair, connection_, GetSocket().Pass(),
74 writer_.Pass(), NULL, NULL,
71 make_scoped_ptr((QuicServerInfo*)NULL), 75 make_scoped_ptr((QuicServerInfo*)NULL),
72 QuicServerId(kServerHostname, kServerPort, false, 76 QuicServerId(kServerHostname, kServerPort, false,
73 PRIVACY_MODE_DISABLED), 77 PRIVACY_MODE_DISABLED),
74 DefaultQuicConfig(), &crypto_config_, 78 DefaultQuicConfig(), &crypto_config_,
75 base::MessageLoop::current()->message_loop_proxy().get(), 79 base::MessageLoop::current()->message_loop_proxy().get(),
76 &net_log_) { 80 &net_log_) {
77 session_.config()->SetDefaults(); 81 session_.config()->SetDefaults();
78 crypto_config_.SetDefaults(); 82 crypto_config_.SetDefaults();
79 } 83 }
80 84
(...skipping 10 matching lines...) Expand all
91 95
92 void CompleteCryptoHandshake() { 96 void CompleteCryptoHandshake() {
93 ASSERT_EQ(ERR_IO_PENDING, 97 ASSERT_EQ(ERR_IO_PENDING,
94 session_.CryptoConnect(false, callback_.callback())); 98 session_.CryptoConnect(false, callback_.callback()));
95 CryptoTestUtils::HandshakeWithFakeServer( 99 CryptoTestUtils::HandshakeWithFakeServer(
96 connection_, session_.GetCryptoStream()); 100 connection_, session_.GetCryptoStream());
97 ASSERT_EQ(OK, callback_.WaitForResult()); 101 ASSERT_EQ(OK, callback_.WaitForResult());
98 } 102 }
99 103
100 scoped_ptr<QuicDefaultPacketWriter> writer_; 104 scoped_ptr<QuicDefaultPacketWriter> writer_;
105 const HostPortPair host_port_pair;
wtc 2014/06/27 23:55:51 1. The member name is missing the trailing '_'. 2
Ryan Hamilton 2014/07/01 18:37:17 Done.
101 PacketSavingConnection* connection_; 106 PacketSavingConnection* connection_;
102 CapturingNetLog net_log_; 107 CapturingNetLog net_log_;
103 MockClientSocketFactory socket_factory_; 108 MockClientSocketFactory socket_factory_;
104 StaticSocketDataProvider socket_data_; 109 StaticSocketDataProvider socket_data_;
105 QuicClientSession session_; 110 QuicClientSession session_;
106 MockClock clock_; 111 MockClock clock_;
107 MockRandom random_; 112 MockRandom random_;
108 QuicConnectionVisitorInterface* visitor_; 113 QuicConnectionVisitorInterface* visitor_;
109 TestCompletionCallback callback_; 114 TestCompletionCallback callback_;
110 QuicCryptoClientConfig crypto_config_; 115 QuicCryptoClientConfig crypto_config_;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 164
160 TEST_P(QuicClientSessionTest, GoAwayReceived) { 165 TEST_P(QuicClientSessionTest, GoAwayReceived) {
161 CompleteCryptoHandshake(); 166 CompleteCryptoHandshake();
162 167
163 // After receiving a GoAway, I should no longer be able to create outgoing 168 // After receiving a GoAway, I should no longer be able to create outgoing
164 // streams. 169 // streams.
165 session_.OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away.")); 170 session_.OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away."));
166 EXPECT_EQ(NULL, session_.CreateOutgoingDataStream()); 171 EXPECT_EQ(NULL, session_.CreateOutgoingDataStream());
167 } 172 }
168 173
174 TEST_P(QuicClientSessionTest, CanPool) {
175 // Load a cert that is valid for:
176 // www.example.org
177 // mail.example.org
178 // www.example.com
179 base::FilePath certs_dir = GetTestCertsDirectory();
180 scoped_refptr<X509Certificate> test_cert(
181 ImportCertFromFile(certs_dir, "spdy_pooling.pem"));
182 ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert);
183
184 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
185 ssl.cert = test_cert;
186 socket_factory_.AddSSLSocketDataProvider(&ssl);
187
188 CompleteCryptoHandshake();
189
190 EXPECT_TRUE(session_.CanPool("www.example.org"));
191 EXPECT_TRUE(session_.CanPool("mail.example.org"));
192 EXPECT_TRUE(session_.CanPool("mail.example.com"));
193 EXPECT_FALSE(session_.CanPool("mail.google.com"));
194 }
195
196 /*
wtc 2014/06/27 23:55:51 Nit: use #if 0 to comment out a block of code. Ple
Ryan Hamilton 2014/07/01 18:37:17 Sorry, this was not yet implemented since it depen
197 TEST_P(QuicClientSessionTest, ConnectionPooledWithTlsChannelId) {
198 session_deps_.host_resolver->set_synchronous_mode(true);
199
200 MockConnect connect_data(SYNCHRONOUS, OK);
201
202 // No actual data will be sent.
203 MockWrite writes[] = {
204 MockWrite(ASYNC, 0, 1) // EOF
205 };
206
207 MockRead reads[] = {
208 MockRead(ASYNC, 0, 0) // EOF
209 };
210 DeterministicSocketData data(reads, arraysize(reads),
211 writes, arraysize(writes));
212 data.set_connect_data(connect_data);
213 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
214
215 // Load a cert that is valid for:
216 // www.example.org
217 // mail.example.org
218 // www.example.com
219 base::FilePath certs_dir = GetTestCertsDirectory();
220 scoped_refptr<X509Certificate> test_cert(
221 ImportCertFromFile(certs_dir, "spdy_pooling.pem"));
222 ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert);
223
224 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
225 ssl.channel_id_sent = true;
226 ssl.cert = test_cert;
227 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
228
229 CreateDeterministicNetworkSession();
230
231 base::WeakPtr<SpdySession> session =
232 CreateSecureSpdySession(http_session_, key_, BoundNetLog());
233
234 EXPECT_TRUE(session->CanPool("www.example.org"));
235 EXPECT_TRUE(session->CanPool("mail.example.org"));
236 EXPECT_FALSE(session->CanPool("mail.example.com"));
237 EXPECT_FALSE(session->CanPool("mail.google.com"));
238 }
239 */
240
169 } // namespace 241 } // namespace
170 } // namespace test 242 } // namespace test
171 } // namespace net 243 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698