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

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

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « net/quic/quic_crypto_server_stream.cc ('k') | net/quic/quic_data_writer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_server_stream.h" 5 #include "net/quic/quic_crypto_server_stream.h"
6 6
7 #include <map> 7 #include <map>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 }; 49 };
50 50
51 namespace { 51 namespace {
52 52
53 const char kServerHostname[] = "test.example.com"; 53 const char kServerHostname[] = "test.example.com";
54 const uint16 kServerPort = 80; 54 const uint16 kServerPort = 80;
55 55
56 class QuicCryptoServerStreamTest : public ::testing::TestWithParam<bool> { 56 class QuicCryptoServerStreamTest : public ::testing::TestWithParam<bool> {
57 public: 57 public:
58 QuicCryptoServerStreamTest() 58 QuicCryptoServerStreamTest()
59 : connection_(new PacketSavingConnection(true)), 59 : connection_(new PacketSavingConnection(/*is_server=*/true)),
60 session_(connection_, DefaultQuicConfig()), 60 session_(connection_, DefaultQuicConfig()),
61 crypto_config_(QuicCryptoServerConfig::TESTING, 61 crypto_config_(QuicCryptoServerConfig::TESTING,
62 QuicRandom::GetInstance()), 62 QuicRandom::GetInstance()),
63 stream_(crypto_config_, &session_), 63 stream_(crypto_config_, &session_),
64 strike_register_client_(nullptr) { 64 strike_register_client_(nullptr) {
65 session_.SetCryptoStream(&stream_); 65 session_.SetCryptoStream(&stream_);
66 // We advance the clock initially because the default time is zero and the 66 // We advance the clock initially because the default time is zero and the
67 // strike register worries that we've just overflowed a uint32 time. 67 // strike register worries that we've just overflowed a uint32 time.
68 connection_->AdvanceTime(QuicTime::Delta::FromSeconds(100000)); 68 connection_->AdvanceTime(QuicTime::Delta::FromSeconds(100000));
69 // TODO(wtc): replace this with ProofSourceForTesting() when Chromium has 69 // TODO(wtc): replace this with ProofSourceForTesting() when Chromium has
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 // CompleteCryptoHandshake returns the number of client hellos sent. This 126 // CompleteCryptoHandshake returns the number of client hellos sent. This
127 // test should send: 127 // test should send:
128 // * One to get a source-address token and certificates. 128 // * One to get a source-address token and certificates.
129 // * One to complete the handshake. 129 // * One to complete the handshake.
130 EXPECT_EQ(2, CompleteCryptoHandshake()); 130 EXPECT_EQ(2, CompleteCryptoHandshake());
131 EXPECT_TRUE(stream_.encryption_established()); 131 EXPECT_TRUE(stream_.encryption_established());
132 EXPECT_TRUE(stream_.handshake_confirmed()); 132 EXPECT_TRUE(stream_.handshake_confirmed());
133 } 133 }
134 134
135 TEST_P(QuicCryptoServerStreamTest, ZeroRTT) { 135 TEST_P(QuicCryptoServerStreamTest, ZeroRTT) {
136 PacketSavingConnection* client_conn = new PacketSavingConnection(false); 136 PacketSavingConnection* client_conn =
137 PacketSavingConnection* server_conn = new PacketSavingConnection(false); 137 new PacketSavingConnection(/*is_server=*/false);
138 PacketSavingConnection* server_conn =
139 new PacketSavingConnection(/*is_server=*/true);
138 client_conn->AdvanceTime(QuicTime::Delta::FromSeconds(100000)); 140 client_conn->AdvanceTime(QuicTime::Delta::FromSeconds(100000));
139 server_conn->AdvanceTime(QuicTime::Delta::FromSeconds(100000)); 141 server_conn->AdvanceTime(QuicTime::Delta::FromSeconds(100000));
140 142
141 QuicConfig client_config; 143 QuicConfig client_config;
142 scoped_ptr<TestClientSession> client_session( 144 scoped_ptr<TestClientSession> client_session(
143 new TestClientSession(client_conn, client_config)); 145 new TestClientSession(client_conn, client_config));
144 QuicCryptoClientConfig client_crypto_config; 146 QuicCryptoClientConfig client_crypto_config;
145 147
146 QuicServerId server_id(kServerHostname, kServerPort, false, 148 QuicServerId server_id(kServerHostname, kServerPort, false,
147 PRIVACY_MODE_DISABLED); 149 PRIVACY_MODE_DISABLED);
148 scoped_ptr<QuicCryptoClientStream> client(new QuicCryptoClientStream( 150 scoped_ptr<QuicCryptoClientStream> client(new QuicCryptoClientStream(
149 server_id, client_session.get(), nullptr, &client_crypto_config)); 151 server_id, client_session.get(), nullptr, &client_crypto_config));
150 client_session->SetCryptoStream(client.get()); 152 client_session->SetCryptoStream(client.get());
151 153
152 // Do a first handshake in order to prime the client config with the server's 154 // Do a first handshake in order to prime the client config with the server's
153 // information. 155 // information.
154 client->CryptoConnect(); 156 client->CryptoConnect();
155 CHECK_EQ(1u, client_conn->packets_.size()); 157 CHECK_EQ(1u, client_conn->encrypted_packets_.size());
156 158
157 scoped_ptr<TestSession> server_session(new TestSession(server_conn, config_)); 159 scoped_ptr<TestSession> server_session(new TestSession(server_conn, config_));
158 scoped_ptr<QuicCryptoServerStream> server( 160 scoped_ptr<QuicCryptoServerStream> server(
159 new QuicCryptoServerStream(crypto_config_, server_session.get())); 161 new QuicCryptoServerStream(crypto_config_, server_session.get()));
160 server_session->SetCryptoStream(server.get()); 162 server_session->SetCryptoStream(server.get());
161 163
162 CryptoTestUtils::CommunicateHandshakeMessages( 164 CryptoTestUtils::CommunicateHandshakeMessages(
163 client_conn, client.get(), server_conn, server.get()); 165 client_conn, client.get(), server_conn, server.get());
164 EXPECT_EQ(2, client->num_sent_client_hellos()); 166 EXPECT_EQ(2, client->num_sent_client_hellos());
165 167
166 // Now do another handshake, hopefully in 0-RTT. 168 // Now do another handshake, hopefully in 0-RTT.
167 LOG(INFO) << "Resetting for 0-RTT handshake attempt"; 169 LOG(INFO) << "Resetting for 0-RTT handshake attempt";
168 170
169 client_conn = new PacketSavingConnection(false); 171 client_conn = new PacketSavingConnection(/*is_server=*/false);
170 server_conn = new PacketSavingConnection(false); 172 server_conn = new PacketSavingConnection(/*is_server=*/true);
171 // We need to advance time past the strike-server window so that it's 173 // We need to advance time past the strike-server window so that it's
172 // authoritative in this time span. 174 // authoritative in this time span.
173 client_conn->AdvanceTime(QuicTime::Delta::FromSeconds(102000)); 175 client_conn->AdvanceTime(QuicTime::Delta::FromSeconds(102000));
174 server_conn->AdvanceTime(QuicTime::Delta::FromSeconds(102000)); 176 server_conn->AdvanceTime(QuicTime::Delta::FromSeconds(102000));
175 177
176 // This causes the client's nonce to be different and thus stops the 178 // This causes the client's nonce to be different and thus stops the
177 // strike-register from rejecting the repeated nonce. 179 // strike-register from rejecting the repeated nonce.
178 reinterpret_cast<MockRandom*>(client_conn->random_generator())->ChangeValue(); 180 reinterpret_cast<MockRandom*>(client_conn->random_generator())->ChangeValue();
179 client_session.reset(new TestClientSession(client_conn, client_config)); 181 client_session.reset(new TestClientSession(client_conn, client_config));
180 server_session.reset(new TestSession(server_conn, config_)); 182 server_session.reset(new TestSession(server_conn, config_));
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 274
273 TEST_P(QuicCryptoServerStreamTest, OnlySendSCUPAfterHandshakeComplete) { 275 TEST_P(QuicCryptoServerStreamTest, OnlySendSCUPAfterHandshakeComplete) {
274 // An attempt to send a SCUP before completing handshake should fail. 276 // An attempt to send a SCUP before completing handshake should fail.
275 stream_.SendServerConfigUpdate(nullptr); 277 stream_.SendServerConfigUpdate(nullptr);
276 EXPECT_EQ(0, stream_.num_server_config_update_messages_sent()); 278 EXPECT_EQ(0, stream_.num_server_config_update_messages_sent());
277 } 279 }
278 280
279 } // namespace 281 } // namespace
280 } // namespace test 282 } // namespace test
281 } // namespace net 283 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_crypto_server_stream.cc ('k') | net/quic/quic_data_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698