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/core/crypto/crypto_server_test.cc

Issue 2589983002: Create a QUIC wrapper around scoped_refptr. (Closed)
Patch Set: rm = nullptr Created 4 years 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/core/crypto/crypto_handshake.h ('k') | net/quic/core/crypto/proof_source.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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <algorithm> 5 #include <algorithm>
6 #include <cstdint> 6 #include <cstdint>
7 #include <memory> 7 #include <memory>
8 #include <ostream> 8 #include <ostream>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 srct_hex_ = "#" + QuicUtils::HexEncode(srct); 173 srct_hex_ = "#" + QuicUtils::HexEncode(srct);
174 174
175 StringPiece scfg; 175 StringPiece scfg;
176 ASSERT_TRUE(out_.GetStringPiece(kSCFG, &scfg)); 176 ASSERT_TRUE(out_.GetStringPiece(kSCFG, &scfg));
177 server_config_.reset(CryptoFramer::ParseMessage(scfg)); 177 server_config_.reset(CryptoFramer::ParseMessage(scfg));
178 178
179 StringPiece scid; 179 StringPiece scid;
180 ASSERT_TRUE(server_config_->GetStringPiece(kSCID, &scid)); 180 ASSERT_TRUE(server_config_->GetStringPiece(kSCID, &scid));
181 scid_hex_ = "#" + QuicUtils::HexEncode(scid); 181 scid_hex_ = "#" + QuicUtils::HexEncode(scid);
182 182
183 signed_config_ = 183 signed_config_ = QuicReferenceCountedPointer<QuicSignedServerConfig>(
184 scoped_refptr<QuicSignedServerConfig>(new QuicSignedServerConfig()); 184 new QuicSignedServerConfig());
185 DCHECK(signed_config_->chain.get() == nullptr); 185 DCHECK(signed_config_->chain.get() == nullptr);
186 } 186 }
187 187
188 // Helper used to accept the result of ValidateClientHello and pass 188 // Helper used to accept the result of ValidateClientHello and pass
189 // it on to ProcessClientHello. 189 // it on to ProcessClientHello.
190 class ValidateCallback : public ValidateClientHelloResultCallback { 190 class ValidateCallback : public ValidateClientHelloResultCallback {
191 public: 191 public:
192 ValidateCallback(CryptoServerTest* test, 192 ValidateCallback(CryptoServerTest* test,
193 bool should_succeed, 193 bool should_succeed,
194 const char* error_substr, 194 const char* error_substr,
195 bool* called) 195 bool* called)
196 : test_(test), 196 : test_(test),
197 should_succeed_(should_succeed), 197 should_succeed_(should_succeed),
198 error_substr_(error_substr), 198 error_substr_(error_substr),
199 called_(called) { 199 called_(called) {
200 *called_ = false; 200 *called_ = false;
201 } 201 }
202 202
203 void Run(scoped_refptr<Result> result, 203 void Run(QuicReferenceCountedPointer<Result> result,
204 std::unique_ptr<ProofSource::Details> /* details */) override { 204 std::unique_ptr<ProofSource::Details> /* details */) override {
205 ASSERT_FALSE(*called_); 205 ASSERT_FALSE(*called_);
206 test_->ProcessValidationResult(std::move(result), should_succeed_, 206 test_->ProcessValidationResult(std::move(result), should_succeed_,
207 error_substr_); 207 error_substr_);
208 *called_ = true; 208 *called_ = true;
209 } 209 }
210 210
211 private: 211 private:
212 CryptoServerTest* test_; 212 CryptoServerTest* test_;
213 const bool should_succeed_; 213 const bool should_succeed_;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 QuicSocketAddress server_address; 256 QuicSocketAddress server_address;
257 config_.ValidateClientHello( 257 config_.ValidateClientHello(
258 message, client_address_.host(), server_address, 258 message, client_address_.host(), server_address,
259 supported_versions_.front(), &clock_, signed_config_, 259 supported_versions_.front(), &clock_, signed_config_,
260 std::unique_ptr<ValidateCallback>( 260 std::unique_ptr<ValidateCallback>(
261 new ValidateCallback(this, false, error_substr, called))); 261 new ValidateCallback(this, false, error_substr, called)));
262 } 262 }
263 263
264 class ProcessCallback : public ProcessClientHelloResultCallback { 264 class ProcessCallback : public ProcessClientHelloResultCallback {
265 public: 265 public:
266 ProcessCallback(scoped_refptr<ValidateCallback::Result> result, 266 ProcessCallback(
267 bool should_succeed, 267 QuicReferenceCountedPointer<ValidateCallback::Result> result,
268 const char* error_substr, 268 bool should_succeed,
269 bool* called, 269 const char* error_substr,
270 CryptoHandshakeMessage* out) 270 bool* called,
271 CryptoHandshakeMessage* out)
271 : result_(std::move(result)), 272 : result_(std::move(result)),
272 should_succeed_(should_succeed), 273 should_succeed_(should_succeed),
273 error_substr_(error_substr), 274 error_substr_(error_substr),
274 called_(called), 275 called_(called),
275 out_(out) { 276 out_(out) {
276 *called_ = false; 277 *called_ = false;
277 } 278 }
278 279
279 void Run( 280 void Run(
280 QuicErrorCode error, 281 QuicErrorCode error,
(...skipping 12 matching lines...) Expand all
293 EXPECT_TRUE(error_details.find(error_substr_) != string::npos) 294 EXPECT_TRUE(error_details.find(error_substr_) != string::npos)
294 << error_substr_ << " not in " << error_details; 295 << error_substr_ << " not in " << error_details;
295 } 296 }
296 if (message != nullptr) { 297 if (message != nullptr) {
297 *out_ = *message; 298 *out_ = *message;
298 } 299 }
299 *called_ = true; 300 *called_ = true;
300 } 301 }
301 302
302 private: 303 private:
303 const scoped_refptr<ValidateCallback::Result> result_; 304 const QuicReferenceCountedPointer<ValidateCallback::Result> result_;
304 const bool should_succeed_; 305 const bool should_succeed_;
305 const char* const error_substr_; 306 const char* const error_substr_;
306 bool* called_; 307 bool* called_;
307 CryptoHandshakeMessage* out_; 308 CryptoHandshakeMessage* out_;
308 }; 309 };
309 310
310 void ProcessValidationResult(scoped_refptr<ValidateCallback::Result> result, 311 void ProcessValidationResult(
311 bool should_succeed, 312 QuicReferenceCountedPointer<ValidateCallback::Result> result,
312 const char* error_substr) { 313 bool should_succeed,
314 const char* error_substr) {
313 QuicSocketAddress server_address; 315 QuicSocketAddress server_address;
314 QuicConnectionId server_designated_connection_id = 316 QuicConnectionId server_designated_connection_id =
315 rand_for_id_generation_.RandUint64(); 317 rand_for_id_generation_.RandUint64();
316 bool called; 318 bool called;
317 config_.ProcessClientHello( 319 config_.ProcessClientHello(
318 result, /*reject_only=*/false, /*connection_id=*/1, server_address, 320 result, /*reject_only=*/false, /*connection_id=*/1, server_address,
319 client_address_, supported_versions_.front(), supported_versions_, 321 client_address_, supported_versions_.front(), supported_versions_,
320 use_stateless_rejects_, server_designated_connection_id, &clock_, rand_, 322 use_stateless_rejects_, server_designated_connection_id, &clock_, rand_,
321 &compressed_certs_cache_, params_, signed_config_, 323 &compressed_certs_cache_, params_, signed_config_,
322 /*total_framing_overhead=*/50, chlo_packet_size_, 324 /*total_framing_overhead=*/50, chlo_packet_size_,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 QuicRandom* const rand_; 393 QuicRandom* const rand_;
392 MockRandom rand_for_id_generation_; 394 MockRandom rand_for_id_generation_;
393 MockClock clock_; 395 MockClock clock_;
394 QuicSocketAddress client_address_; 396 QuicSocketAddress client_address_;
395 QuicVersionVector supported_versions_; 397 QuicVersionVector supported_versions_;
396 QuicVersion client_version_; 398 QuicVersion client_version_;
397 string client_version_string_; 399 string client_version_string_;
398 QuicCryptoServerConfig config_; 400 QuicCryptoServerConfig config_;
399 QuicCompressedCertsCache compressed_certs_cache_; 401 QuicCompressedCertsCache compressed_certs_cache_;
400 QuicCryptoServerConfig::ConfigOptions config_options_; 402 QuicCryptoServerConfig::ConfigOptions config_options_;
401 scoped_refptr<QuicCryptoNegotiatedParameters> params_; 403 QuicReferenceCountedPointer<QuicCryptoNegotiatedParameters> params_;
402 scoped_refptr<QuicSignedServerConfig> signed_config_; 404 QuicReferenceCountedPointer<QuicSignedServerConfig> signed_config_;
403 CryptoHandshakeMessage out_; 405 CryptoHandshakeMessage out_;
404 uint8_t orbit_[kOrbitSize]; 406 uint8_t orbit_[kOrbitSize];
405 bool use_stateless_rejects_; 407 bool use_stateless_rejects_;
406 size_t chlo_packet_size_; 408 size_t chlo_packet_size_;
407 409
408 // These strings contain hex escaped values from the server suitable for using 410 // These strings contain hex escaped values from the server suitable for using
409 // when constructing client hello messages. 411 // when constructing client hello messages.
410 string nonce_hex_, pub_hex_, srct_hex_, scid_hex_; 412 string nonce_hex_, pub_hex_, srct_hex_, scid_hex_;
411 std::unique_ptr<CryptoHandshakeMessage> server_config_; 413 std::unique_ptr<CryptoHandshakeMessage> server_config_;
412 }; 414 };
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 // QuicCryptoServerConfig::EvaluateClientHello will leave info.unique as false 1146 // QuicCryptoServerConfig::EvaluateClientHello will leave info.unique as false
1145 // and cause ProcessClientHello to exit early (and generate a REJ message). 1147 // and cause ProcessClientHello to exit early (and generate a REJ message).
1146 config_.set_replay_protection(false); 1148 config_.set_replay_protection(false);
1147 1149
1148 ShouldSucceed(msg); 1150 ShouldSucceed(msg);
1149 EXPECT_EQ(kSHLO, out_.tag()); 1151 EXPECT_EQ(kSHLO, out_.tag());
1150 } 1152 }
1151 1153
1152 } // namespace test 1154 } // namespace test
1153 } // namespace net 1155 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/crypto/crypto_handshake.h ('k') | net/quic/core/crypto/proof_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698