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

Side by Side Diff: net/quic/crypto/crypto_server_test.cc

Issue 862133002: Update from https://crrev.com/312398 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
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 <ostream> 5 #include <ostream>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "crypto/secure_hash.h" 10 #include "crypto/secure_hash.h"
(...skipping 24 matching lines...) Expand all
35 : server_config_(server_config) {} 35 : server_config_(server_config) {}
36 36
37 base::Lock* GetStrikeRegisterClientLock() { 37 base::Lock* GetStrikeRegisterClientLock() {
38 return &server_config_->strike_register_client_lock_; 38 return &server_config_->strike_register_client_lock_;
39 } 39 }
40 40
41 private: 41 private:
42 QuicCryptoServerConfig* server_config_; 42 QuicCryptoServerConfig* server_config_;
43 }; 43 };
44 44
45 // Run tests with combinations of 45 // Run tests with both parities of
46 // {FLAGS_use_early_return_when_verifying_chlo, 46 // FLAGS_use_early_return_when_verifying_chlo.
47 // FLAGS_send_quic_crypto_reject_reason}.
48 struct TestParams { 47 struct TestParams {
49 TestParams(bool use_early_return_when_verifying_chlo, 48 explicit TestParams(bool use_early_return_when_verifying_chlo)
50 bool send_quic_crypto_reject_reason)
51 : use_early_return_when_verifying_chlo( 49 : use_early_return_when_verifying_chlo(
52 use_early_return_when_verifying_chlo), 50 use_early_return_when_verifying_chlo) {}
53 send_quic_crypto_reject_reason(send_quic_crypto_reject_reason) {
54 }
55 51
56 friend ostream& operator<<(ostream& os, const TestParams& p) { 52 friend ostream& operator<<(ostream& os, const TestParams& p) {
57 os << "{ use_early_return_when_verifying_chlo: " 53 os << "{ use_early_return_when_verifying_chlo: "
58 << p.use_early_return_when_verifying_chlo 54 << p.use_early_return_when_verifying_chlo << " }";
59 << " send_quic_crypto_reject_reason: "
60 << p.send_quic_crypto_reject_reason << " }";
61 return os; 55 return os;
62 } 56 }
63 57
64 bool use_early_return_when_verifying_chlo; 58 bool use_early_return_when_verifying_chlo;
65 bool send_quic_crypto_reject_reason;
66 }; 59 };
67 60
68 // Constructs various test permutations. 61 // Constructs various test permutations.
69 vector<TestParams> GetTestParams() { 62 vector<TestParams> GetTestParams() {
70 vector<TestParams> params; 63 vector<TestParams> params;
71 params.push_back(TestParams(false, false)); 64 params.push_back(TestParams(false));
72 params.push_back(TestParams(false, true)); 65 params.push_back(TestParams(true));
73 params.push_back(TestParams(true, false));
74 params.push_back(TestParams(true, true));
75 return params; 66 return params;
76 } 67 }
77 68
78 class CryptoServerTest : public ::testing::TestWithParam<TestParams> { 69 class CryptoServerTest : public ::testing::TestWithParam<TestParams> {
79 public: 70 public:
80 CryptoServerTest() 71 CryptoServerTest()
81 : rand_(QuicRandom::GetInstance()), 72 : rand_(QuicRandom::GetInstance()),
82 client_address_(Loopback4(), 1234), 73 client_address_(Loopback4(), 1234),
83 config_(QuicCryptoServerConfig::TESTING, rand_) { 74 config_(QuicCryptoServerConfig::TESTING, rand_) {
84 config_.SetProofSource(CryptoTestUtils::ProofSourceForTesting()); 75 config_.SetProofSource(CryptoTestUtils::ProofSourceForTesting());
85 supported_versions_ = QuicSupportedVersions(); 76 supported_versions_ = QuicSupportedVersions();
86 client_version_ = QuicUtils::TagToString( 77 client_version_ = QuicUtils::TagToString(
87 QuicVersionToQuicTag(supported_versions_.front())); 78 QuicVersionToQuicTag(supported_versions_.front()));
88 79
89 FLAGS_use_early_return_when_verifying_chlo = 80 FLAGS_use_early_return_when_verifying_chlo =
90 GetParam().use_early_return_when_verifying_chlo; 81 GetParam().use_early_return_when_verifying_chlo;
91 FLAGS_send_quic_crypto_reject_reason =
92 GetParam().send_quic_crypto_reject_reason;
93 } 82 }
94 83
95 void SetUp() override { 84 void SetUp() override {
96 scoped_ptr<CryptoHandshakeMessage> msg( 85 scoped_ptr<CryptoHandshakeMessage> msg(
97 config_.AddDefaultConfig(rand_, &clock_, 86 config_.AddDefaultConfig(rand_, &clock_,
98 config_options_)); 87 config_options_));
99 88
100 StringPiece orbit; 89 StringPiece orbit;
101 CHECK(msg->GetStringPiece(kORBT, &orbit)); 90 CHECK(msg->GetStringPiece(kORBT, &orbit));
102 CHECK_EQ(sizeof(orbit_), orbit.size()); 91 CHECK_EQ(sizeof(orbit_), orbit.size());
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 StringPiece(reinterpret_cast<const char*>(orbit_), sizeof(orbit_)), 255 StringPiece(reinterpret_cast<const char*>(orbit_), sizeof(orbit_)),
267 &nonce); 256 &nonce);
268 return nonce; 257 return nonce;
269 } 258 }
270 259
271 void CheckRejectReasons( 260 void CheckRejectReasons(
272 const HandshakeFailureReason* expected_handshake_failures, 261 const HandshakeFailureReason* expected_handshake_failures,
273 size_t expected_count) { 262 size_t expected_count) {
274 const uint32* reject_reasons; 263 const uint32* reject_reasons;
275 size_t num_reject_reasons; 264 size_t num_reject_reasons;
276 COMPILE_ASSERT(sizeof(QuicTag) == sizeof(uint32), header_out_of_sync); 265 static_assert(sizeof(QuicTag) == sizeof(uint32), "header out of sync");
277 QuicErrorCode error_code = out_.GetTaglist(kRREJ, &reject_reasons, 266 QuicErrorCode error_code = out_.GetTaglist(kRREJ, &reject_reasons,
278 &num_reject_reasons); 267 &num_reject_reasons);
279 if (!FLAGS_send_quic_crypto_reject_reason) {
280 ASSERT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND, error_code);
281 return;
282 }
283 ASSERT_EQ(QUIC_NO_ERROR, error_code); 268 ASSERT_EQ(QUIC_NO_ERROR, error_code);
284 269
285 if (FLAGS_use_early_return_when_verifying_chlo) { 270 if (FLAGS_use_early_return_when_verifying_chlo) {
286 EXPECT_EQ(1u, num_reject_reasons); 271 EXPECT_EQ(1u, num_reject_reasons);
287 } else { 272 } else {
288 EXPECT_EQ(expected_count, num_reject_reasons); 273 EXPECT_EQ(expected_count, num_reject_reasons);
289 } 274 }
290 for (size_t i = 0; i < num_reject_reasons; ++i) { 275 for (size_t i = 0; i < num_reject_reasons; ++i) {
291 EXPECT_EQ(expected_handshake_failures[i], reject_reasons[i]); 276 EXPECT_EQ(expected_handshake_failures[i], reject_reasons[i]);
292 } 277 }
(...skipping 10 matching lines...) Expand all
303 QuicCryptoNegotiatedParameters params_; 288 QuicCryptoNegotiatedParameters params_;
304 CryptoHandshakeMessage out_; 289 CryptoHandshakeMessage out_;
305 uint8 orbit_[kOrbitSize]; 290 uint8 orbit_[kOrbitSize];
306 291
307 // These strings contain hex escaped values from the server suitable for 292 // These strings contain hex escaped values from the server suitable for
308 // passing to |InchoateClientHello| when constructing client hello messages. 293 // passing to |InchoateClientHello| when constructing client hello messages.
309 string nonce_hex_, pub_hex_, srct_hex_, scid_hex_; 294 string nonce_hex_, pub_hex_, srct_hex_, scid_hex_;
310 scoped_ptr<CryptoHandshakeMessage> server_config_; 295 scoped_ptr<CryptoHandshakeMessage> server_config_;
311 }; 296 };
312 297
313 // Run all CryptoServerTest with all combinations of 298 // Run all CryptoServerTest with both values of
314 // FLAGS_use_early_return_when_verifying_chlo and 299 // FLAGS_use_early_return_when_verifying_chlo
315 // FLAGS_send_quic_crypto_reject_reason.
316 INSTANTIATE_TEST_CASE_P(CryptoServerTests, 300 INSTANTIATE_TEST_CASE_P(CryptoServerTests,
317 CryptoServerTest, 301 CryptoServerTest,
318 ::testing::ValuesIn(GetTestParams())); 302 ::testing::ValuesIn(GetTestParams()));
319 303
320 TEST_P(CryptoServerTest, BadSNI) { 304 TEST_P(CryptoServerTest, BadSNI) {
321 static const char* kBadSNIs[] = { 305 static const char* kBadSNIs[] = {
322 "", 306 "",
323 "foo", 307 "foo",
324 "#00", 308 "#00",
325 "#ff00", 309 "#ff00",
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 703
720 strike_register_client_->RunPendingVerifications(); 704 strike_register_client_->RunPendingVerifications();
721 ASSERT_TRUE(called); 705 ASSERT_TRUE(called);
722 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); 706 EXPECT_EQ(0, strike_register_client_->PendingVerifications());
723 // The message should be rejected now. 707 // The message should be rejected now.
724 EXPECT_EQ(kREJ, out_.tag()); 708 EXPECT_EQ(kREJ, out_.tag());
725 } 709 }
726 710
727 } // namespace test 711 } // namespace test
728 } // namespace net 712 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698