| 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 "base/base64.h" | 5 #include "base/base64.h" |
| 6 #include "base/sha1.h" | 6 #include "base/sha1.h" |
| 7 #include "base/string_piece.h" | 7 #include "base/string_piece.h" |
| 8 #include "crypto/sha2.h" | 8 #include "crypto/sha2.h" |
| 9 #include "net/base/net_log.h" | 9 #include "net/base/net_log.h" |
| 10 #include "net/base/test_completion_callback.h" | 10 #include "net/base/test_completion_callback.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 class HttpSecurityHeadersTest : public testing::Test { | 45 class HttpSecurityHeadersTest : public testing::Test { |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 | 48 |
| 49 TEST_F(HttpSecurityHeadersTest, BogusHeaders) { | 49 TEST_F(HttpSecurityHeadersTest, BogusHeaders) { |
| 50 base::Time now = base::Time::Now(); | 50 base::Time now = base::Time::Now(); |
| 51 base::Time expiry = now; | 51 base::Time expiry = now; |
| 52 bool include_subdomains = false; | 52 bool include_subdomains = false; |
| 53 | 53 |
| 54 EXPECT_FALSE(ParseHSTSHeader(now, "", &expiry, &include_subdomains)); | 54 EXPECT_FALSE( |
| 55 ParseHSTSHeader(now, std::string(), &expiry, &include_subdomains)); |
| 55 EXPECT_FALSE(ParseHSTSHeader(now, " ", &expiry, &include_subdomains)); | 56 EXPECT_FALSE(ParseHSTSHeader(now, " ", &expiry, &include_subdomains)); |
| 56 EXPECT_FALSE(ParseHSTSHeader(now, "abc", &expiry, &include_subdomains)); | 57 EXPECT_FALSE(ParseHSTSHeader(now, "abc", &expiry, &include_subdomains)); |
| 57 EXPECT_FALSE(ParseHSTSHeader(now, " abc", &expiry, &include_subdomains)); | 58 EXPECT_FALSE(ParseHSTSHeader(now, " abc", &expiry, &include_subdomains)); |
| 58 EXPECT_FALSE(ParseHSTSHeader(now, " abc ", &expiry, &include_subdomains)); | 59 EXPECT_FALSE(ParseHSTSHeader(now, " abc ", &expiry, &include_subdomains)); |
| 59 EXPECT_FALSE(ParseHSTSHeader(now, "max-age", &expiry, &include_subdomains)); | 60 EXPECT_FALSE(ParseHSTSHeader(now, "max-age", &expiry, &include_subdomains)); |
| 60 EXPECT_FALSE(ParseHSTSHeader(now, " max-age", &expiry, | 61 EXPECT_FALSE(ParseHSTSHeader(now, " max-age", &expiry, |
| 61 &include_subdomains)); | 62 &include_subdomains)); |
| 62 EXPECT_FALSE(ParseHSTSHeader(now, " max-age ", &expiry, | 63 EXPECT_FALSE(ParseHSTSHeader(now, " max-age ", &expiry, |
| 63 &include_subdomains)); | 64 &include_subdomains)); |
| 64 EXPECT_FALSE(ParseHSTSHeader(now, "max-age=", &expiry, &include_subdomains)); | 65 EXPECT_FALSE(ParseHSTSHeader(now, "max-age=", &expiry, &include_subdomains)); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 129 |
| 129 // Set some fake "chain" hashes | 130 // Set some fake "chain" hashes |
| 130 chain_hashes.push_back(GetTestHashValue(1, tag)); | 131 chain_hashes.push_back(GetTestHashValue(1, tag)); |
| 131 chain_hashes.push_back(GetTestHashValue(2, tag)); | 132 chain_hashes.push_back(GetTestHashValue(2, tag)); |
| 132 chain_hashes.push_back(GetTestHashValue(3, tag)); | 133 chain_hashes.push_back(GetTestHashValue(3, tag)); |
| 133 | 134 |
| 134 // The good pin must be in the chain, the backup pin must not be | 135 // The good pin must be in the chain, the backup pin must not be |
| 135 std::string good_pin = GetTestPin(2, tag); | 136 std::string good_pin = GetTestPin(2, tag); |
| 136 std::string backup_pin = GetTestPin(4, tag); | 137 std::string backup_pin = GetTestPin(4, tag); |
| 137 | 138 |
| 138 EXPECT_FALSE(ParseHPKPHeader(now, "", chain_hashes, &expiry, &hashes)); | 139 EXPECT_FALSE( |
| 140 ParseHPKPHeader(now, std::string(), chain_hashes, &expiry, &hashes)); |
| 139 EXPECT_FALSE(ParseHPKPHeader(now, " ", chain_hashes, &expiry, &hashes)); | 141 EXPECT_FALSE(ParseHPKPHeader(now, " ", chain_hashes, &expiry, &hashes)); |
| 140 EXPECT_FALSE(ParseHPKPHeader(now, "abc", chain_hashes, &expiry, &hashes)); | 142 EXPECT_FALSE(ParseHPKPHeader(now, "abc", chain_hashes, &expiry, &hashes)); |
| 141 EXPECT_FALSE(ParseHPKPHeader(now, " abc", chain_hashes, &expiry, &hashes)); | 143 EXPECT_FALSE(ParseHPKPHeader(now, " abc", chain_hashes, &expiry, &hashes)); |
| 142 EXPECT_FALSE(ParseHPKPHeader(now, " abc ", chain_hashes, &expiry, | 144 EXPECT_FALSE(ParseHPKPHeader(now, " abc ", chain_hashes, &expiry, |
| 143 &hashes)); | 145 &hashes)); |
| 144 EXPECT_FALSE(ParseHPKPHeader(now, "max-age", chain_hashes, &expiry, | 146 EXPECT_FALSE(ParseHPKPHeader(now, "max-age", chain_hashes, &expiry, |
| 145 &hashes)); | 147 &hashes)); |
| 146 EXPECT_FALSE(ParseHPKPHeader(now, " max-age", chain_hashes, &expiry, | 148 EXPECT_FALSE(ParseHPKPHeader(now, " max-age", chain_hashes, &expiry, |
| 147 &hashes)); | 149 &hashes)); |
| 148 EXPECT_FALSE(ParseHPKPHeader(now, " max-age ", chain_hashes, &expiry, | 150 EXPECT_FALSE(ParseHPKPHeader(now, " max-age ", chain_hashes, &expiry, |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 | 417 |
| 416 TEST_F(HttpSecurityHeadersTest, ValidPinsHeadersSHA1) { | 418 TEST_F(HttpSecurityHeadersTest, ValidPinsHeadersSHA1) { |
| 417 TestValidPinsHeaders(HASH_VALUE_SHA1); | 419 TestValidPinsHeaders(HASH_VALUE_SHA1); |
| 418 } | 420 } |
| 419 | 421 |
| 420 TEST_F(HttpSecurityHeadersTest, ValidPinsHeadersSHA256) { | 422 TEST_F(HttpSecurityHeadersTest, ValidPinsHeadersSHA256) { |
| 421 TestValidPinsHeaders(HASH_VALUE_SHA256); | 423 TestValidPinsHeaders(HASH_VALUE_SHA256); |
| 422 } | 424 } |
| 423 }; | 425 }; |
| 424 | 426 |
| OLD | NEW |