| OLD | NEW |
| 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/http/transport_security_state.h" | 5 #include "net/http/transport_security_state.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 TransportSecurityState state; | 479 TransportSecurityState state; |
| 480 const base::Time current_time(base::Time::Now()); | 480 const base::Time current_time(base::Time::Now()); |
| 481 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); | 481 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); |
| 482 | 482 |
| 483 EXPECT_FALSE(state.ShouldUpgradeToSSL("example.com")); | 483 EXPECT_FALSE(state.ShouldUpgradeToSSL("example.com")); |
| 484 bool include_subdomains = false; | 484 bool include_subdomains = false; |
| 485 state.AddHSTS("EXample.coM", expiry, include_subdomains); | 485 state.AddHSTS("EXample.coM", expiry, include_subdomains); |
| 486 EXPECT_TRUE(state.ShouldUpgradeToSSL("example.com")); | 486 EXPECT_TRUE(state.ShouldUpgradeToSSL("example.com")); |
| 487 } | 487 } |
| 488 | 488 |
| 489 TEST_F(TransportSecurityStateTest, Fuzz) { | |
| 490 TransportSecurityState state; | |
| 491 TransportSecurityState::STSState sts_state; | |
| 492 TransportSecurityState::PKPState pkp_state; | |
| 493 | |
| 494 EnableStaticPins(&state); | |
| 495 | |
| 496 for (size_t i = 0; i < 128; i++) { | |
| 497 std::string hostname; | |
| 498 | |
| 499 for (;;) { | |
| 500 if (base::RandInt(0, 16) == 7) { | |
| 501 break; | |
| 502 } | |
| 503 if (i > 0 && base::RandInt(0, 7) == 7) { | |
| 504 hostname.append(1, '.'); | |
| 505 } | |
| 506 hostname.append(1, 'a' + base::RandInt(0, 25)); | |
| 507 } | |
| 508 state.GetStaticDomainState(hostname, &sts_state, &pkp_state); | |
| 509 } | |
| 510 } | |
| 511 | |
| 512 TEST_F(TransportSecurityStateTest, MatchesCase2) { | 489 TEST_F(TransportSecurityStateTest, MatchesCase2) { |
| 513 TransportSecurityState state; | 490 TransportSecurityState state; |
| 514 const base::Time current_time(base::Time::Now()); | 491 const base::Time current_time(base::Time::Now()); |
| 515 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); | 492 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); |
| 516 | 493 |
| 517 // Check dynamic entries | 494 // Check dynamic entries |
| 518 EXPECT_FALSE(state.ShouldUpgradeToSSL("EXample.coM")); | 495 EXPECT_FALSE(state.ShouldUpgradeToSSL("EXample.coM")); |
| 519 bool include_subdomains = false; | 496 bool include_subdomains = false; |
| 520 state.AddHSTS("example.com", expiry, include_subdomains); | 497 state.AddHSTS("example.com", expiry, include_subdomains); |
| 521 EXPECT_TRUE(state.ShouldUpgradeToSSL("EXample.coM")); | 498 EXPECT_TRUE(state.ShouldUpgradeToSSL("EXample.coM")); |
| (...skipping 1810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2332 base::FieldTrialList::CreateFieldTrial("EnforceCTForProblematicRoots", | 2309 base::FieldTrialList::CreateFieldTrial("EnforceCTForProblematicRoots", |
| 2333 "disabled"); | 2310 "disabled"); |
| 2334 | 2311 |
| 2335 EXPECT_FALSE( | 2312 EXPECT_FALSE( |
| 2336 state.ShouldRequireCT("www.example.com", before_cert.get(), hashes)); | 2313 state.ShouldRequireCT("www.example.com", before_cert.get(), hashes)); |
| 2337 EXPECT_FALSE( | 2314 EXPECT_FALSE( |
| 2338 state.ShouldRequireCT("www.example.com", after_cert.get(), hashes)); | 2315 state.ShouldRequireCT("www.example.com", after_cert.get(), hashes)); |
| 2339 } | 2316 } |
| 2340 | 2317 |
| 2341 } // namespace net | 2318 } // namespace net |
| OLD | NEW |