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

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

Issue 1437023002: Landing Recent QUIC changes until 2015-11-09 20:32 UTC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "net/quic/crypto/quic_crypto_client_config.h" 5 #include "net/quic/crypto/quic_crypto_client_config.h"
6 6
7 #include "net/quic/crypto/proof_verifier.h" 7 #include "net/quic/crypto/proof_verifier.h"
8 #include "net/quic/quic_server_id.h" 8 #include "net/quic/quic_server_id.h"
9 #include "net/quic/test_tools/crypto_test_utils.h" 9 #include "net/quic/test_tools/crypto_test_utils.h"
10 #include "net/quic/test_tools/mock_random.h" 10 #include "net/quic/test_tools/mock_random.h"
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 EXPECT_TRUE(config.LookupOrCreate(canonical_id2)->IsEmpty()); 312 EXPECT_TRUE(config.LookupOrCreate(canonical_id2)->IsEmpty());
313 } 313 }
314 314
315 TEST(QuicCryptoClientConfigTest, ClearCachedStates) { 315 TEST(QuicCryptoClientConfigTest, ClearCachedStates) {
316 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); 316 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting());
317 QuicServerId server_id("www.google.com", 80, PRIVACY_MODE_DISABLED); 317 QuicServerId server_id("www.google.com", 80, PRIVACY_MODE_DISABLED);
318 QuicCryptoClientConfig::CachedState* state = config.LookupOrCreate(server_id); 318 QuicCryptoClientConfig::CachedState* state = config.LookupOrCreate(server_id);
319 // TODO(rch): Populate other fields of |state|. 319 // TODO(rch): Populate other fields of |state|.
320 vector<string> certs(1); 320 vector<string> certs(1);
321 certs[0] = "Hello Cert"; 321 certs[0] = "Hello Cert";
322 state->SetProof(certs, "signature"); 322 state->SetProof(certs, "cert_sct", "signature");
323 state->set_source_address_token("TOKEN"); 323 state->set_source_address_token("TOKEN");
324 state->SetProofValid(); 324 state->SetProofValid();
325 EXPECT_EQ(1u, state->generation_counter()); 325 EXPECT_EQ(1u, state->generation_counter());
326 326
327 // Verify LookupOrCreate returns the same data. 327 // Verify LookupOrCreate returns the same data.
328 QuicCryptoClientConfig::CachedState* other = config.LookupOrCreate(server_id); 328 QuicCryptoClientConfig::CachedState* other = config.LookupOrCreate(server_id);
329 329
330 EXPECT_EQ(state, other); 330 EXPECT_EQ(state, other);
331 EXPECT_EQ(1u, other->generation_counter()); 331 EXPECT_EQ(1u, other->generation_counter());
332 332
333 // Clear the cached states. 333 // Clear the cached states.
334 config.ClearCachedStates(); 334 config.ClearCachedStates();
335 335
336 // Verify LookupOrCreate doesn't have any data. 336 // Verify LookupOrCreate doesn't have any data.
337 QuicCryptoClientConfig::CachedState* cleared_cache = 337 QuicCryptoClientConfig::CachedState* cleared_cache =
338 config.LookupOrCreate(server_id); 338 config.LookupOrCreate(server_id);
339 339
340 EXPECT_EQ(state, cleared_cache); 340 EXPECT_EQ(state, cleared_cache);
341 EXPECT_FALSE(cleared_cache->proof_valid()); 341 EXPECT_FALSE(cleared_cache->proof_valid());
342 EXPECT_TRUE(cleared_cache->server_config().empty()); 342 EXPECT_TRUE(cleared_cache->server_config().empty());
343 EXPECT_TRUE(cleared_cache->certs().empty()); 343 EXPECT_TRUE(cleared_cache->certs().empty());
344 EXPECT_TRUE(cleared_cache->cert_sct().empty());
344 EXPECT_TRUE(cleared_cache->signature().empty()); 345 EXPECT_TRUE(cleared_cache->signature().empty());
345 EXPECT_EQ(2u, cleared_cache->generation_counter()); 346 EXPECT_EQ(2u, cleared_cache->generation_counter());
346 } 347 }
347 348
348 // Creates a minimal dummy reject message that will pass the client-config 349 // Creates a minimal dummy reject message that will pass the client-config
349 // validation tests. 350 // validation tests.
350 void FillInDummyReject(CryptoHandshakeMessage* rej, bool reject_is_stateless) { 351 void FillInDummyReject(CryptoHandshakeMessage* rej, bool reject_is_stateless) {
351 if (reject_is_stateless) { 352 if (reject_is_stateless) {
352 rej->set_tag(kSREJ); 353 rej->set_tag(kSREJ);
353 } else { 354 } else {
(...skipping 27 matching lines...) Expand all
381 382
382 TEST(QuicCryptoClientConfigTest, ProcessReject) { 383 TEST(QuicCryptoClientConfigTest, ProcessReject) {
383 CryptoHandshakeMessage rej; 384 CryptoHandshakeMessage rej;
384 FillInDummyReject(&rej, /* stateless */ false); 385 FillInDummyReject(&rej, /* stateless */ false);
385 386
386 // Now process the rejection. 387 // Now process the rejection.
387 QuicCryptoClientConfig::CachedState cached; 388 QuicCryptoClientConfig::CachedState cached;
388 QuicCryptoNegotiatedParameters out_params; 389 QuicCryptoNegotiatedParameters out_params;
389 string error; 390 string error;
390 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); 391 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting());
391 EXPECT_EQ(QUIC_NO_ERROR, config.ProcessRejection( 392 EXPECT_EQ(QUIC_NO_ERROR,
392 rej, QuicWallTime::FromUNIXSeconds(0), &cached, 393 config.ProcessRejection(rej, QuicWallTime::FromUNIXSeconds(0),
393 &out_params, &error)); 394 QuicSupportedVersions().front(), &cached,
395 &out_params, &error));
394 EXPECT_FALSE(cached.has_server_designated_connection_id()); 396 EXPECT_FALSE(cached.has_server_designated_connection_id());
395 EXPECT_FALSE(cached.has_server_nonce()); 397 EXPECT_FALSE(cached.has_server_nonce());
396 } 398 }
397 399
398 TEST(QuicCryptoClientConfigTest, ProcessStatelessReject) { 400 TEST(QuicCryptoClientConfigTest, ProcessStatelessReject) {
399 // Create a dummy reject message and mark it as stateless. 401 // Create a dummy reject message and mark it as stateless.
400 CryptoHandshakeMessage rej; 402 CryptoHandshakeMessage rej;
401 FillInDummyReject(&rej, /* stateless */ true); 403 FillInDummyReject(&rej, /* stateless */ true);
402 const QuicConnectionId kConnectionId = 0xdeadbeef; 404 const QuicConnectionId kConnectionId = 0xdeadbeef;
403 const string server_nonce = "SERVER_NONCE"; 405 const string server_nonce = "SERVER_NONCE";
404 rej.SetValue(kRCID, kConnectionId); 406 rej.SetValue(kRCID, kConnectionId);
405 rej.SetStringPiece(kServerNonceTag, server_nonce); 407 rej.SetStringPiece(kServerNonceTag, server_nonce);
406 408
407 // Now process the rejection. 409 // Now process the rejection.
408 QuicCryptoClientConfig::CachedState cached; 410 QuicCryptoClientConfig::CachedState cached;
409 QuicCryptoNegotiatedParameters out_params; 411 QuicCryptoNegotiatedParameters out_params;
410 string error; 412 string error;
411 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); 413 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting());
412 EXPECT_EQ(QUIC_NO_ERROR, config.ProcessRejection( 414 EXPECT_EQ(QUIC_NO_ERROR,
413 rej, QuicWallTime::FromUNIXSeconds(0), &cached, 415 config.ProcessRejection(rej, QuicWallTime::FromUNIXSeconds(0),
414 &out_params, &error)); 416 QuicSupportedVersions().front(), &cached,
417 &out_params, &error));
415 EXPECT_TRUE(cached.has_server_designated_connection_id()); 418 EXPECT_TRUE(cached.has_server_designated_connection_id());
416 EXPECT_EQ(kConnectionId, cached.GetNextServerDesignatedConnectionId()); 419 EXPECT_EQ(kConnectionId, cached.GetNextServerDesignatedConnectionId());
417 EXPECT_EQ(server_nonce, cached.GetNextServerNonce()); 420 EXPECT_EQ(server_nonce, cached.GetNextServerNonce());
418 } 421 }
419 422
420 TEST(QuicCryptoClientConfigTest, BadlyFormattedStatelessReject) { 423 TEST(QuicCryptoClientConfigTest, BadlyFormattedStatelessReject) {
421 // Create a dummy reject message and mark it as stateless. Do not 424 // Create a dummy reject message and mark it as stateless. Do not
422 // add an server-designated connection-id. 425 // add an server-designated connection-id.
423 CryptoHandshakeMessage rej; 426 CryptoHandshakeMessage rej;
424 FillInDummyReject(&rej, /* stateless */ true); 427 FillInDummyReject(&rej, /* stateless */ true);
425 428
426 // Now process the rejection. 429 // Now process the rejection.
427 QuicCryptoClientConfig::CachedState cached; 430 QuicCryptoClientConfig::CachedState cached;
428 QuicCryptoNegotiatedParameters out_params; 431 QuicCryptoNegotiatedParameters out_params;
429 string error; 432 string error;
430 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); 433 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting());
431 EXPECT_EQ( 434 EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND,
432 QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND, 435 config.ProcessRejection(rej, QuicWallTime::FromUNIXSeconds(0),
433 config.ProcessRejection(rej, QuicWallTime::FromUNIXSeconds(0), &cached, 436 QuicSupportedVersions().front(), &cached,
434 &out_params, &error)); 437 &out_params, &error));
435 EXPECT_FALSE(cached.has_server_designated_connection_id()); 438 EXPECT_FALSE(cached.has_server_designated_connection_id());
436 EXPECT_EQ("Missing kRCID", error); 439 EXPECT_EQ("Missing kRCID", error);
437 } 440 }
438 441
439 TEST(QuicCryptoClientConfigTest, ServerNonceinSHLO_BeforeQ027) { 442 TEST(QuicCryptoClientConfigTest, ServerNonceinSHLO_BeforeQ027) {
440 // Test that in QUIC_VERSION_26 and lower, the the server does not need to 443 // Test that in QUIC_VERSION_26 and lower, the the server does not need to
441 // include a nonce in the SHLO. 444 // include a nonce in the SHLO.
442 CryptoHandshakeMessage msg; 445 CryptoHandshakeMessage msg;
443 msg.set_tag(kSHLO); 446 msg.set_tag(kSHLO);
444 // Choose the lowest version. 447 // Choose the lowest version.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 QuicCryptoNegotiatedParameters out_params; 481 QuicCryptoNegotiatedParameters out_params;
479 string error_details; 482 string error_details;
480 EXPECT_EQ(QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER, 483 EXPECT_EQ(QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER,
481 config.ProcessServerHello(msg, 0, version, supported_versions, 484 config.ProcessServerHello(msg, 0, version, supported_versions,
482 &cached, &out_params, &error_details)); 485 &cached, &out_params, &error_details));
483 EXPECT_EQ("server hello missing server nonce", error_details); 486 EXPECT_EQ("server hello missing server nonce", error_details);
484 } 487 }
485 488
486 } // namespace test 489 } // namespace test
487 } // namespace net 490 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/quic_crypto_client_config.cc ('k') | net/quic/crypto/quic_crypto_server_config.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698