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

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: Fix comments 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"
14 #include "net/cert/cert_verify_result.h"
12 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" 15 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h"
13 #include "net/quic/crypto/crypto_protocol.h" 16 #include "net/quic/crypto/crypto_protocol.h"
17 #include "net/quic/crypto/proof_verifier_chromium.h"
14 #include "net/quic/crypto/quic_decrypter.h" 18 #include "net/quic/crypto/quic_decrypter.h"
15 #include "net/quic/crypto/quic_encrypter.h" 19 #include "net/quic/crypto/quic_encrypter.h"
16 #include "net/quic/crypto/quic_server_info.h" 20 #include "net/quic/crypto/quic_server_info.h"
17 #include "net/quic/quic_default_packet_writer.h" 21 #include "net/quic/quic_default_packet_writer.h"
18 #include "net/quic/test_tools/crypto_test_utils.h" 22 #include "net/quic/test_tools/crypto_test_utils.h"
19 #include "net/quic/test_tools/quic_client_session_peer.h" 23 #include "net/quic/test_tools/quic_client_session_peer.h"
20 #include "net/quic/test_tools/quic_test_utils.h" 24 #include "net/quic/test_tools/quic_test_utils.h"
21 #include "net/quic/test_tools/simple_quic_framer.h" 25 #include "net/quic/test_tools/simple_quic_framer.h"
22 #include "net/socket/socket_test_util.h" 26 #include "net/socket/socket_test_util.h"
27 #include "net/test/cert_test_util.h"
23 #include "net/udp/datagram_client_socket.h" 28 #include "net/udp/datagram_client_socket.h"
24 29
25 using testing::_; 30 using testing::_;
26 31
27 namespace net { 32 namespace net {
28 namespace test { 33 namespace test {
29 namespace { 34 namespace {
30 35
31 const char kServerHostname[] = "www.example.com"; 36 const char kServerHostname[] = "www.example.org";
32 const uint16 kServerPort = 80; 37 const uint16 kServerPort = 80;
33 38
34 class TestPacketWriter : public QuicDefaultPacketWriter { 39 class TestPacketWriter : public QuicDefaultPacketWriter {
35 public: 40 public:
36 TestPacketWriter(QuicVersion version) : version_(version) {} 41 TestPacketWriter(QuicVersion version) : version_(version) {}
37 42
38 // QuicPacketWriter 43 // QuicPacketWriter
39 virtual WriteResult WritePacket( 44 virtual WriteResult WritePacket(
40 const char* buffer, size_t buf_len, 45 const char* buffer, size_t buf_len,
41 const IPAddressNumber& self_address, 46 const IPAddressNumber& self_address,
(...skipping 12 matching lines...) Expand all
54 } 59 }
55 60
56 // Returns the header from the last packet written. 61 // Returns the header from the last packet written.
57 const QuicPacketHeader& header() { return header_; } 62 const QuicPacketHeader& header() { return header_; }
58 63
59 private: 64 private:
60 QuicVersion version_; 65 QuicVersion version_;
61 QuicPacketHeader header_; 66 QuicPacketHeader header_;
62 }; 67 };
63 68
69 class FakeChannelIDKey : public ChannelIDKey {
70 public:
71 // ChannelIDKey implementation
72 virtual bool Sign(base::StringPiece signed_data,
73 std::string* out_signature) const OVERRIDE {
74 *out_signature = "";
75 return true;
76 }
77
78 virtual std::string SerializeKey() const OVERRIDE {
79 return "";
80 }
81 };
82
64 class QuicClientSessionTest : public ::testing::TestWithParam<QuicVersion> { 83 class QuicClientSessionTest : public ::testing::TestWithParam<QuicVersion> {
65 protected: 84 protected:
66 QuicClientSessionTest() 85 QuicClientSessionTest()
67 : writer_(new TestPacketWriter(GetParam())), 86 : writer_(new TestPacketWriter(GetParam())),
68 connection_( 87 connection_(
69 new PacketSavingConnection(false, SupportedVersions(GetParam()))), 88 new PacketSavingConnection(false, SupportedVersions(GetParam()))),
70 session_(connection_, GetSocket().Pass(), writer_.Pass(), NULL, NULL, 89 session_(connection_, GetSocket().Pass(), writer_.Pass(), NULL, NULL,
71 make_scoped_ptr((QuicServerInfo*)NULL), 90 make_scoped_ptr((QuicServerInfo*)NULL),
72 QuicServerId(kServerHostname, kServerPort, false, 91 QuicServerId(kServerHostname, kServerPort, false,
73 PRIVACY_MODE_DISABLED), 92 PRIVACY_MODE_DISABLED),
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 178
160 TEST_P(QuicClientSessionTest, GoAwayReceived) { 179 TEST_P(QuicClientSessionTest, GoAwayReceived) {
161 CompleteCryptoHandshake(); 180 CompleteCryptoHandshake();
162 181
163 // After receiving a GoAway, I should no longer be able to create outgoing 182 // After receiving a GoAway, I should no longer be able to create outgoing
164 // streams. 183 // streams.
165 session_.OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away.")); 184 session_.OnGoAway(QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away."));
166 EXPECT_EQ(NULL, session_.CreateOutgoingDataStream()); 185 EXPECT_EQ(NULL, session_.CreateOutgoingDataStream());
167 } 186 }
168 187
188 TEST_P(QuicClientSessionTest, CanPool) {
189 // Load a cert that is valid for:
190 // www.example.org
191 // mail.example.org
192 // www.example.com
193 base::FilePath certs_dir = GetTestCertsDirectory();
194
195 CertVerifyResult result;
196 ProofVerifyDetailsChromium details;
197 details.cert_verify_result.verified_cert =
198 ImportCertFromFile(certs_dir, "spdy_pooling.pem");
199 ASSERT_TRUE(details.cert_verify_result.verified_cert);
200
201 session_.OnProofVerifyDetailsAvailable(details);
202 CompleteCryptoHandshake();
203
204
205 EXPECT_TRUE(session_.CanPool("www.example.org"));
206 EXPECT_TRUE(session_.CanPool("mail.example.org"));
207 EXPECT_TRUE(session_.CanPool("mail.example.com"));
208 EXPECT_FALSE(session_.CanPool("mail.google.com"));
209 }
210
211 TEST_P(QuicClientSessionTest, ConnectionPooledWithTlsChannelId) {
212 // Load a cert that is valid for:
213 // www.example.org
214 // mail.example.org
215 // www.example.com
216 base::FilePath certs_dir = GetTestCertsDirectory();
217
218 CertVerifyResult result;
219 ProofVerifyDetailsChromium details;
220 details.cert_verify_result.verified_cert =
221 ImportCertFromFile(certs_dir, "spdy_pooling.pem");
222 ASSERT_TRUE(details.cert_verify_result.verified_cert);
223
224 session_.OnProofVerifyDetailsAvailable(details);
225 CompleteCryptoHandshake();
226 QuicClientSessionPeer::SetChannelIDKey(&session_, new FakeChannelIDKey);
227
228 EXPECT_TRUE(session_.CanPool("www.example.org"));
229 EXPECT_TRUE(session_.CanPool("mail.example.org"));
230 EXPECT_FALSE(session_.CanPool("mail.example.com"));
231 EXPECT_FALSE(session_.CanPool("mail.google.com"));
232 }
233
169 } // namespace 234 } // namespace
170 } // namespace test 235 } // namespace test
171 } // namespace net 236 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698