| Index: net/http/http_security_headers_unittest.cc
|
| diff --git a/net/http/http_security_headers_unittest.cc b/net/http/http_security_headers_unittest.cc
|
| index 9aae8aecee6608b107fe8327901d400ea02602fb..100efd6aed5a5d7bb38771c38bed8632e33398f5 100644
|
| --- a/net/http/http_security_headers_unittest.cc
|
| +++ b/net/http/http_security_headers_unittest.cc
|
| @@ -29,8 +29,10 @@ HashValue GetTestHashValue(uint8 label, HashValueTag tag) {
|
| std::string GetTestPin(uint8 label, HashValueTag tag) {
|
| HashValue hash_value = GetTestHashValue(label, tag);
|
| std::string base64;
|
| - base::Base64Encode(base::StringPiece(
|
| - reinterpret_cast<char*>(hash_value.data()), hash_value.size()), &base64);
|
| + base::Base64Encode(
|
| + base::StringPiece(reinterpret_cast<char*>(hash_value.data()),
|
| + hash_value.size()),
|
| + &base64);
|
|
|
| switch (hash_value.tag) {
|
| case HASH_VALUE_SHA1:
|
| @@ -42,86 +44,74 @@ std::string GetTestPin(uint8 label, HashValueTag tag) {
|
| return std::string("ERROR");
|
| }
|
| }
|
| -
|
| -};
|
| -
|
| -
|
| -class HttpSecurityHeadersTest : public testing::Test {
|
| };
|
|
|
| +class HttpSecurityHeadersTest : public testing::Test {};
|
|
|
| TEST_F(HttpSecurityHeadersTest, BogusHeaders) {
|
| base::TimeDelta max_age;
|
| bool include_subdomains = false;
|
|
|
| - EXPECT_FALSE(
|
| - ParseHSTSHeader(std::string(), &max_age, &include_subdomains));
|
| + EXPECT_FALSE(ParseHSTSHeader(std::string(), &max_age, &include_subdomains));
|
| EXPECT_FALSE(ParseHSTSHeader(" ", &max_age, &include_subdomains));
|
| EXPECT_FALSE(ParseHSTSHeader("abc", &max_age, &include_subdomains));
|
| EXPECT_FALSE(ParseHSTSHeader(" abc", &max_age, &include_subdomains));
|
| EXPECT_FALSE(ParseHSTSHeader(" abc ", &max_age, &include_subdomains));
|
| EXPECT_FALSE(ParseHSTSHeader("max-age", &max_age, &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader(" max-age", &max_age,
|
| - &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader(" max-age ", &max_age,
|
| - &include_subdomains));
|
| + EXPECT_FALSE(ParseHSTSHeader(" max-age", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(ParseHSTSHeader(" max-age ", &max_age, &include_subdomains));
|
| EXPECT_FALSE(ParseHSTSHeader("max-age=", &max_age, &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader(" max-age=", &max_age,
|
| - &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader(" max-age =", &max_age,
|
| - &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader(" max-age= ", &max_age,
|
| - &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader(" max-age = ", &max_age,
|
| - &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader(" max-age = xy", &max_age,
|
| - &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader(" max-age = 3488a923", &max_age,
|
| - &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader("max-age=3488a923 ", &max_age,
|
| - &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader("max-ag=3488923", &max_age,
|
| - &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader("max-aged=3488923", &max_age,
|
| - &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader("max-age==3488923", &max_age,
|
| - &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader("amax-age=3488923", &max_age,
|
| - &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader("max-age=-3488923", &max_age,
|
| - &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader("max-age=3488923 e", &max_age,
|
| - &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader("max-age=3488923 includesubdomain",
|
| - &max_age, &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader("max-age=3488923includesubdomains",
|
| - &max_age, &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader("max-age=3488923=includesubdomains",
|
| - &max_age, &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader("max-age=3488923 includesubdomainx",
|
| - &max_age, &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader("max-age=3488923 includesubdomain=",
|
| - &max_age, &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader("max-age=3488923 includesubdomain=true",
|
| - &max_age, &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader("max-age=3488923 includesubdomainsx",
|
| - &max_age, &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader("max-age=3488923 includesubdomains x",
|
| - &max_age, &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader("max-age=34889.23 includesubdomains",
|
| - &max_age, &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader("max-age=34889 includesubdomains",
|
| - &max_age, &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader(";;;; ;;;",
|
| - &max_age, &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader(";;;; includeSubDomains;;;",
|
| - &max_age, &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader(" includeSubDomains; ",
|
| - &max_age, &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader(";",
|
| - &max_age, &include_subdomains));
|
| - EXPECT_FALSE(ParseHSTSHeader("max-age; ;",
|
| - &max_age, &include_subdomains));
|
| + EXPECT_FALSE(ParseHSTSHeader(" max-age=", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(ParseHSTSHeader(" max-age =", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(
|
| + ParseHSTSHeader(" max-age= ", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(
|
| + ParseHSTSHeader(" max-age = ", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(
|
| + ParseHSTSHeader(" max-age = xy", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(ParseHSTSHeader(
|
| + " max-age = 3488a923", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(
|
| + ParseHSTSHeader("max-age=3488a923 ", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(
|
| + ParseHSTSHeader("max-ag=3488923", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(
|
| + ParseHSTSHeader("max-aged=3488923", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(
|
| + ParseHSTSHeader("max-age==3488923", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(
|
| + ParseHSTSHeader("amax-age=3488923", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(
|
| + ParseHSTSHeader("max-age=-3488923", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(
|
| + ParseHSTSHeader("max-age=3488923 e", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(ParseHSTSHeader(
|
| + "max-age=3488923 includesubdomain", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(ParseHSTSHeader(
|
| + "max-age=3488923includesubdomains", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(ParseHSTSHeader(
|
| + "max-age=3488923=includesubdomains", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(ParseHSTSHeader(
|
| + "max-age=3488923 includesubdomainx", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(ParseHSTSHeader(
|
| + "max-age=3488923 includesubdomain=", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(ParseHSTSHeader(
|
| + "max-age=3488923 includesubdomain=true", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(ParseHSTSHeader(
|
| + "max-age=3488923 includesubdomainsx", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(ParseHSTSHeader(
|
| + "max-age=3488923 includesubdomains x", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(ParseHSTSHeader(
|
| + "max-age=34889.23 includesubdomains", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(ParseHSTSHeader(
|
| + "max-age=34889 includesubdomains", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(ParseHSTSHeader(";;;; ;;;", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(ParseHSTSHeader(
|
| + ";;;; includeSubDomains;;;", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(ParseHSTSHeader(
|
| + " includeSubDomains; ", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(ParseHSTSHeader(";", &max_age, &include_subdomains));
|
| + EXPECT_FALSE(ParseHSTSHeader("max-age; ;", &max_age, &include_subdomains));
|
|
|
| // Check the out args were not updated by checking the default
|
| // values for its predictable fields.
|
| @@ -144,75 +134,117 @@ static void TestBogusPinsHeaders(HashValueTag tag) {
|
| std::string good_pin = GetTestPin(2, tag);
|
| std::string backup_pin = GetTestPin(4, tag);
|
|
|
| - EXPECT_FALSE(ParseHPKPHeader(std::string(), chain_hashes, &max_age,
|
| - &include_subdomains, &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader(" ", chain_hashes, &max_age,
|
| - &include_subdomains, &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader("abc", chain_hashes, &max_age,
|
| - &include_subdomains, &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader(" abc", chain_hashes, &max_age,
|
| - &include_subdomains, &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader(" abc ", chain_hashes, &max_age,
|
| - &include_subdomains, &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader("max-age", chain_hashes, &max_age,
|
| - &include_subdomains, &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader(" max-age", chain_hashes, &max_age,
|
| - &include_subdomains, &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader(" max-age ", chain_hashes, &max_age,
|
| - &include_subdomains, &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader("max-age=", chain_hashes, &max_age,
|
| - &include_subdomains, &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader(" max-age=", chain_hashes, &max_age,
|
| - &include_subdomains, &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader(" max-age =", chain_hashes, &max_age,
|
| - &include_subdomains, &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader(" max-age= ", chain_hashes, &max_age,
|
| - &include_subdomains, &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader(" max-age = ", chain_hashes,
|
| - &max_age, &include_subdomains, &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader(" max-age = xy", chain_hashes,
|
| - &max_age, &include_subdomains, &hashes));
|
| + EXPECT_FALSE(ParseHPKPHeader(
|
| + std::string(), chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + EXPECT_FALSE(ParseHPKPHeader(
|
| + " ", chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + EXPECT_FALSE(ParseHPKPHeader(
|
| + "abc", chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + EXPECT_FALSE(ParseHPKPHeader(
|
| + " abc", chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + EXPECT_FALSE(ParseHPKPHeader(
|
| + " abc ", chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + EXPECT_FALSE(ParseHPKPHeader(
|
| + "max-age", chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + EXPECT_FALSE(ParseHPKPHeader(
|
| + " max-age", chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + EXPECT_FALSE(ParseHPKPHeader(
|
| + " max-age ", chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + EXPECT_FALSE(ParseHPKPHeader(
|
| + "max-age=", chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + EXPECT_FALSE(ParseHPKPHeader(
|
| + " max-age=", chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + EXPECT_FALSE(ParseHPKPHeader(
|
| + " max-age =", chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + EXPECT_FALSE(ParseHPKPHeader(
|
| + " max-age= ", chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + EXPECT_FALSE(ParseHPKPHeader(" max-age = ",
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| + &hashes));
|
| + EXPECT_FALSE(ParseHPKPHeader(" max-age = xy",
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| + &hashes));
|
| EXPECT_FALSE(ParseHPKPHeader(" max-age = 3488a923",
|
| - chain_hashes, &max_age, &include_subdomains,
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader("max-age=3488a923 ", chain_hashes,
|
| - &max_age, &include_subdomains, &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader("max-ag=3488923pins=" + good_pin + "," +
|
| - backup_pin,
|
| - chain_hashes, &max_age, &include_subdomains,
|
| + EXPECT_FALSE(ParseHPKPHeader("max-age=3488a923 ",
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| &hashes));
|
| + EXPECT_FALSE(
|
| + ParseHPKPHeader("max-ag=3488923pins=" + good_pin + "," + backup_pin,
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| + &hashes));
|
| EXPECT_FALSE(ParseHPKPHeader("max-aged=3488923" + backup_pin,
|
| - chain_hashes, &max_age, &include_subdomains,
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| &hashes));
|
| EXPECT_FALSE(ParseHPKPHeader("max-aged=3488923; " + backup_pin,
|
| - chain_hashes, &max_age, &include_subdomains,
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader("max-aged=3488923; " + backup_pin + ";" +
|
| - backup_pin,
|
| - chain_hashes, &max_age, &include_subdomains,
|
| - &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader("max-aged=3488923; " + good_pin + ";" +
|
| - good_pin,
|
| - chain_hashes, &max_age, &include_subdomains,
|
| + EXPECT_FALSE(
|
| + ParseHPKPHeader("max-aged=3488923; " + backup_pin + ";" + backup_pin,
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| + &hashes));
|
| + EXPECT_FALSE(ParseHPKPHeader("max-aged=3488923; " + good_pin + ";" + good_pin,
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| &hashes));
|
| EXPECT_FALSE(ParseHPKPHeader("max-aged=3488923; " + good_pin,
|
| - chain_hashes, &max_age, &include_subdomains,
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| + &hashes));
|
| + EXPECT_FALSE(ParseHPKPHeader("max-age==3488923",
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| + &hashes));
|
| + EXPECT_FALSE(ParseHPKPHeader("amax-age=3488923",
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| + &hashes));
|
| + EXPECT_FALSE(ParseHPKPHeader("max-age=-3488923",
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| + &hashes));
|
| + EXPECT_FALSE(ParseHPKPHeader("max-age=3488923;",
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| + &hashes));
|
| + EXPECT_FALSE(ParseHPKPHeader("max-age=3488923 e",
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader("max-age==3488923", chain_hashes, &max_age,
|
| - &include_subdomains, &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader("amax-age=3488923", chain_hashes, &max_age,
|
| - &include_subdomains, &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader("max-age=-3488923", chain_hashes, &max_age,
|
| - &include_subdomains, &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader("max-age=3488923;", chain_hashes, &max_age,
|
| - &include_subdomains, &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader("max-age=3488923 e", chain_hashes,
|
| - &max_age, &include_subdomains, &hashes));
|
| EXPECT_FALSE(ParseHPKPHeader("max-age=3488923 includesubdomain",
|
| - chain_hashes, &max_age, &include_subdomains,
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| + &hashes));
|
| + EXPECT_FALSE(ParseHPKPHeader("max-age=34889.23",
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| &hashes));
|
| - EXPECT_FALSE(ParseHPKPHeader("max-age=34889.23", chain_hashes, &max_age,
|
| - &include_subdomains, &hashes));
|
|
|
| // Check the out args were not updated by checking the default
|
| // values for its predictable fields.
|
| @@ -225,154 +257,155 @@ TEST_F(HttpSecurityHeadersTest, ValidSTSHeaders) {
|
| base::TimeDelta expect_max_age;
|
| bool include_subdomains = false;
|
|
|
| - EXPECT_TRUE(ParseHSTSHeader("max-age=243", &max_age,
|
| - &include_subdomains));
|
| + EXPECT_TRUE(ParseHSTSHeader("max-age=243", &max_age, &include_subdomains));
|
| expect_max_age = base::TimeDelta::FromSeconds(243);
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_FALSE(include_subdomains);
|
|
|
| - EXPECT_TRUE(ParseHSTSHeader("max-age=3488923;", &max_age,
|
| - &include_subdomains));
|
| + EXPECT_TRUE(
|
| + ParseHSTSHeader("max-age=3488923;", &max_age, &include_subdomains));
|
|
|
| - EXPECT_TRUE(ParseHSTSHeader(" Max-agE = 567", &max_age,
|
| - &include_subdomains));
|
| + EXPECT_TRUE(
|
| + ParseHSTSHeader(" Max-agE = 567", &max_age, &include_subdomains));
|
| expect_max_age = base::TimeDelta::FromSeconds(567);
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_FALSE(include_subdomains);
|
|
|
| - EXPECT_TRUE(ParseHSTSHeader(" mAx-aGe = 890 ", &max_age,
|
| - &include_subdomains));
|
| + EXPECT_TRUE(ParseHSTSHeader(
|
| + " mAx-aGe = 890 ", &max_age, &include_subdomains));
|
| expect_max_age = base::TimeDelta::FromSeconds(890);
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_FALSE(include_subdomains);
|
|
|
| - EXPECT_TRUE(ParseHSTSHeader("max-age=123;incLudesUbdOmains", &max_age,
|
| - &include_subdomains));
|
| + EXPECT_TRUE(ParseHSTSHeader(
|
| + "max-age=123;incLudesUbdOmains", &max_age, &include_subdomains));
|
| expect_max_age = base::TimeDelta::FromSeconds(123);
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_TRUE(include_subdomains);
|
|
|
| - EXPECT_TRUE(ParseHSTSHeader("incLudesUbdOmains; max-age=123", &max_age,
|
| - &include_subdomains));
|
| + EXPECT_TRUE(ParseHSTSHeader(
|
| + "incLudesUbdOmains; max-age=123", &max_age, &include_subdomains));
|
| expect_max_age = base::TimeDelta::FromSeconds(123);
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_TRUE(include_subdomains);
|
|
|
| - EXPECT_TRUE(ParseHSTSHeader(" incLudesUbdOmains; max-age=123",
|
| - &max_age, &include_subdomains));
|
| + EXPECT_TRUE(ParseHSTSHeader(
|
| + " incLudesUbdOmains; max-age=123", &max_age, &include_subdomains));
|
| expect_max_age = base::TimeDelta::FromSeconds(123);
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_TRUE(include_subdomains);
|
|
|
| - EXPECT_TRUE(ParseHSTSHeader(
|
| - " incLudesUbdOmains; max-age=123; pumpkin=kitten", &max_age,
|
| - &include_subdomains));
|
| + EXPECT_TRUE(
|
| + ParseHSTSHeader(" incLudesUbdOmains; max-age=123; pumpkin=kitten",
|
| + &max_age,
|
| + &include_subdomains));
|
| expect_max_age = base::TimeDelta::FromSeconds(123);
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_TRUE(include_subdomains);
|
|
|
| - EXPECT_TRUE(ParseHSTSHeader(
|
| - " pumpkin=894; incLudesUbdOmains; max-age=123 ", &max_age,
|
| - &include_subdomains));
|
| + EXPECT_TRUE(
|
| + ParseHSTSHeader(" pumpkin=894; incLudesUbdOmains; max-age=123 ",
|
| + &max_age,
|
| + &include_subdomains));
|
| expect_max_age = base::TimeDelta::FromSeconds(123);
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_TRUE(include_subdomains);
|
|
|
| - EXPECT_TRUE(ParseHSTSHeader(
|
| - " pumpkin; incLudesUbdOmains; max-age=123 ", &max_age,
|
| - &include_subdomains));
|
| + EXPECT_TRUE(ParseHSTSHeader(" pumpkin; incLudesUbdOmains; max-age=123 ",
|
| + &max_age,
|
| + &include_subdomains));
|
| expect_max_age = base::TimeDelta::FromSeconds(123);
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_TRUE(include_subdomains);
|
|
|
| - EXPECT_TRUE(ParseHSTSHeader(
|
| - " pumpkin; incLudesUbdOmains; max-age=\"123\" ", &max_age,
|
| - &include_subdomains));
|
| + EXPECT_TRUE(
|
| + ParseHSTSHeader(" pumpkin; incLudesUbdOmains; max-age=\"123\" ",
|
| + &max_age,
|
| + &include_subdomains));
|
| expect_max_age = base::TimeDelta::FromSeconds(123);
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_TRUE(include_subdomains);
|
|
|
| EXPECT_TRUE(ParseHSTSHeader(
|
| "animal=\"squirrel; distinguished\"; incLudesUbdOmains; max-age=123",
|
| - &max_age, &include_subdomains));
|
| + &max_age,
|
| + &include_subdomains));
|
| expect_max_age = base::TimeDelta::FromSeconds(123);
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_TRUE(include_subdomains);
|
|
|
| - EXPECT_TRUE(ParseHSTSHeader("max-age=394082; incLudesUbdOmains",
|
| - &max_age, &include_subdomains));
|
| + EXPECT_TRUE(ParseHSTSHeader(
|
| + "max-age=394082; incLudesUbdOmains", &max_age, &include_subdomains));
|
| expect_max_age = base::TimeDelta::FromSeconds(394082);
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_TRUE(include_subdomains);
|
|
|
| EXPECT_TRUE(ParseHSTSHeader(
|
| - "max-age=39408299 ;incLudesUbdOmains", &max_age,
|
| - &include_subdomains));
|
| + "max-age=39408299 ;incLudesUbdOmains", &max_age, &include_subdomains));
|
| expect_max_age = base::TimeDelta::FromSeconds(
|
| std::min(kMaxHSTSAgeSecs, static_cast<int64>(GG_INT64_C(39408299))));
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_TRUE(include_subdomains);
|
|
|
| EXPECT_TRUE(ParseHSTSHeader(
|
| - "max-age=394082038 ; incLudesUbdOmains", &max_age,
|
| - &include_subdomains));
|
| + "max-age=394082038 ; incLudesUbdOmains", &max_age, &include_subdomains));
|
| expect_max_age = base::TimeDelta::FromSeconds(
|
| std::min(kMaxHSTSAgeSecs, static_cast<int64>(GG_INT64_C(394082038))));
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_TRUE(include_subdomains);
|
|
|
| - EXPECT_TRUE(ParseHSTSHeader(
|
| - "max-age=394082038 ; incLudesUbdOmains;", &max_age,
|
| - &include_subdomains));
|
| + EXPECT_TRUE(ParseHSTSHeader("max-age=394082038 ; incLudesUbdOmains;",
|
| + &max_age,
|
| + &include_subdomains));
|
| expect_max_age = base::TimeDelta::FromSeconds(
|
| std::min(kMaxHSTSAgeSecs, static_cast<int64>(GG_INT64_C(394082038))));
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_TRUE(include_subdomains);
|
|
|
| - EXPECT_TRUE(ParseHSTSHeader(
|
| - ";; max-age=394082038 ; incLudesUbdOmains; ;", &max_age,
|
| - &include_subdomains));
|
| + EXPECT_TRUE(ParseHSTSHeader(";; max-age=394082038 ; incLudesUbdOmains; ;",
|
| + &max_age,
|
| + &include_subdomains));
|
| expect_max_age = base::TimeDelta::FromSeconds(
|
| std::min(kMaxHSTSAgeSecs, static_cast<int64>(GG_INT64_C(394082038))));
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_TRUE(include_subdomains);
|
|
|
| EXPECT_TRUE(ParseHSTSHeader(
|
| - ";; max-age=394082038 ;", &max_age,
|
| - &include_subdomains));
|
| + ";; max-age=394082038 ;", &max_age, &include_subdomains));
|
| expect_max_age = base::TimeDelta::FromSeconds(
|
| std::min(kMaxHSTSAgeSecs, static_cast<int64>(GG_INT64_C(394082038))));
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_FALSE(include_subdomains);
|
|
|
| EXPECT_TRUE(ParseHSTSHeader(
|
| - ";; ; ; max-age=394082038;;; includeSubdomains ;; ;", &max_age,
|
| + ";; ; ; max-age=394082038;;; includeSubdomains ;; ;",
|
| + &max_age,
|
| &include_subdomains));
|
| expect_max_age = base::TimeDelta::FromSeconds(
|
| std::min(kMaxHSTSAgeSecs, static_cast<int64>(GG_INT64_C(394082038))));
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_TRUE(include_subdomains);
|
|
|
| - EXPECT_TRUE(ParseHSTSHeader(
|
| - "incLudesUbdOmains ; max-age=394082038 ;;", &max_age,
|
| - &include_subdomains));
|
| + EXPECT_TRUE(ParseHSTSHeader("incLudesUbdOmains ; max-age=394082038 ;;",
|
| + &max_age,
|
| + &include_subdomains));
|
| expect_max_age = base::TimeDelta::FromSeconds(
|
| std::min(kMaxHSTSAgeSecs, static_cast<int64>(GG_INT64_C(394082038))));
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_TRUE(include_subdomains);
|
|
|
| EXPECT_TRUE(ParseHSTSHeader(
|
| - " max-age=0 ; incLudesUbdOmains ", &max_age,
|
| - &include_subdomains));
|
| + " max-age=0 ; incLudesUbdOmains ", &max_age, &include_subdomains));
|
| expect_max_age = base::TimeDelta::FromSeconds(0);
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_TRUE(include_subdomains);
|
|
|
| EXPECT_TRUE(ParseHSTSHeader(
|
| " max-age=999999999999999999999999999999999999999999999 ;"
|
| - " incLudesUbdOmains ", &max_age, &include_subdomains));
|
| - expect_max_age = base::TimeDelta::FromSeconds(
|
| - kMaxHSTSAgeSecs);
|
| + " incLudesUbdOmains ",
|
| + &max_age,
|
| + &include_subdomains));
|
| + expect_max_age = base::TimeDelta::FromSeconds(kMaxHSTSAgeSecs);
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_TRUE(include_subdomains);
|
| }
|
| @@ -393,45 +426,61 @@ static void TestValidPKPHeaders(HashValueTag tag) {
|
| std::string good_pin = GetTestPin(2, tag);
|
| std::string backup_pin = GetTestPin(4, tag);
|
|
|
| - EXPECT_TRUE(ParseHPKPHeader(
|
| - "max-age=243; " + good_pin + ";" + backup_pin,
|
| - chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + EXPECT_TRUE(ParseHPKPHeader("max-age=243; " + good_pin + ";" + backup_pin,
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| + &hashes));
|
| expect_max_age = base::TimeDelta::FromSeconds(243);
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_FALSE(include_subdomains);
|
|
|
| EXPECT_TRUE(ParseHPKPHeader(
|
| " " + good_pin + "; " + backup_pin + " ; Max-agE = 567",
|
| - chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| + &hashes));
|
| expect_max_age = base::TimeDelta::FromSeconds(567);
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_FALSE(include_subdomains);
|
|
|
| - EXPECT_TRUE(ParseHPKPHeader(
|
| - "includeSubDOMAINS;" + good_pin + ";" + backup_pin +
|
| - " ; mAx-aGe = 890 ",
|
| - chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + EXPECT_TRUE(ParseHPKPHeader("includeSubDOMAINS;" + good_pin + ";" +
|
| + backup_pin + " ; mAx-aGe = 890 ",
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| + &hashes));
|
| expect_max_age = base::TimeDelta::FromSeconds(890);
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_TRUE(include_subdomains);
|
|
|
| - EXPECT_TRUE(ParseHPKPHeader(
|
| - good_pin + ";" + backup_pin + "; max-age=123;IGNORED;",
|
| - chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + EXPECT_TRUE(
|
| + ParseHPKPHeader(good_pin + ";" + backup_pin + "; max-age=123;IGNORED;",
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| + &hashes));
|
| expect_max_age = base::TimeDelta::FromSeconds(123);
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_FALSE(include_subdomains);
|
|
|
| - EXPECT_TRUE(ParseHPKPHeader(
|
| - "max-age=394082;" + backup_pin + ";" + good_pin + "; ",
|
| - chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + EXPECT_TRUE(
|
| + ParseHPKPHeader("max-age=394082;" + backup_pin + ";" + good_pin + "; ",
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| + &hashes));
|
| expect_max_age = base::TimeDelta::FromSeconds(394082);
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_FALSE(include_subdomains);
|
|
|
| EXPECT_TRUE(ParseHPKPHeader(
|
| "max-age=39408299 ;" + backup_pin + ";" + good_pin + "; ",
|
| - chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| + &hashes));
|
| expect_max_age = base::TimeDelta::FromSeconds(
|
| std::min(kMaxHSTSAgeSecs, static_cast<int64>(GG_INT64_C(39408299))));
|
| EXPECT_EQ(expect_max_age, max_age);
|
| @@ -440,22 +489,30 @@ static void TestValidPKPHeaders(HashValueTag tag) {
|
| EXPECT_TRUE(ParseHPKPHeader(
|
| "max-age=39408038 ; cybers=39408038 ; includeSubdomains; " +
|
| good_pin + ";" + backup_pin + "; ",
|
| - chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| + &hashes));
|
| expect_max_age = base::TimeDelta::FromSeconds(
|
| std::min(kMaxHSTSAgeSecs, static_cast<int64>(GG_INT64_C(394082038))));
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_TRUE(include_subdomains);
|
|
|
| - EXPECT_TRUE(ParseHPKPHeader(
|
| - " max-age=0 ; " + good_pin + ";" + backup_pin,
|
| - chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + EXPECT_TRUE(ParseHPKPHeader(" max-age=0 ; " + good_pin + ";" + backup_pin,
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| + &hashes));
|
| expect_max_age = base::TimeDelta::FromSeconds(0);
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_FALSE(include_subdomains);
|
|
|
| EXPECT_TRUE(ParseHPKPHeader(
|
| " max-age=0 ; includeSubdomains; " + good_pin + ";" + backup_pin,
|
| - chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| + &hashes));
|
| expect_max_age = base::TimeDelta::FromSeconds(0);
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_TRUE(include_subdomains);
|
| @@ -463,7 +520,10 @@ static void TestValidPKPHeaders(HashValueTag tag) {
|
| EXPECT_TRUE(ParseHPKPHeader(
|
| " max-age=999999999999999999999999999999999999999999999 ; " +
|
| backup_pin + ";" + good_pin + "; ",
|
| - chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| + &hashes));
|
| expect_max_age = base::TimeDelta::FromSeconds(kMaxHSTSAgeSecs);
|
| EXPECT_EQ(expect_max_age, max_age);
|
| EXPECT_FALSE(include_subdomains);
|
| @@ -471,15 +531,19 @@ static void TestValidPKPHeaders(HashValueTag tag) {
|
| // Test that parsing the same header twice doesn't duplicate the recorded
|
| // hashes.
|
| hashes.clear();
|
| - EXPECT_TRUE(ParseHPKPHeader(
|
| - " max-age=999; " +
|
| - backup_pin + ";" + good_pin + "; ",
|
| - chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + EXPECT_TRUE(
|
| + ParseHPKPHeader(" max-age=999; " + backup_pin + ";" + good_pin + "; ",
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| + &hashes));
|
| EXPECT_EQ(2u, hashes.size());
|
| - EXPECT_TRUE(ParseHPKPHeader(
|
| - " max-age=999; " +
|
| - backup_pin + ";" + good_pin + "; ",
|
| - chain_hashes, &max_age, &include_subdomains, &hashes));
|
| + EXPECT_TRUE(
|
| + ParseHPKPHeader(" max-age=999; " + backup_pin + ";" + good_pin + "; ",
|
| + chain_hashes,
|
| + &max_age,
|
| + &include_subdomains,
|
| + &hashes));
|
| EXPECT_EQ(2u, hashes.size());
|
| }
|
|
|
| @@ -523,15 +587,14 @@ TEST_F(HttpSecurityHeadersTest, UpdateDynamicPKPOnly) {
|
| EXPECT_TRUE(state.AddHPKPHeader(domain, header, ssl_info));
|
|
|
| // Expect the preloaded state to remain unchanged.
|
| - std::string canonicalized_host = TransportSecurityState::CanonicalizeHost(
|
| - domain);
|
| + std::string canonicalized_host =
|
| + TransportSecurityState::CanonicalizeHost(domain);
|
| TransportSecurityState::DomainState static_domain_state;
|
| - EXPECT_TRUE(state.GetStaticDomainState(canonicalized_host,
|
| - true,
|
| - &static_domain_state));
|
| + EXPECT_TRUE(state.GetStaticDomainState(
|
| + canonicalized_host, true, &static_domain_state));
|
| for (size_t i = 0; i < saved_hashes.size(); ++i) {
|
| - EXPECT_TRUE(HashValuesEqual(
|
| - saved_hashes[i])(static_domain_state.static_spki_hashes[i]));
|
| + EXPECT_TRUE(HashValuesEqual(saved_hashes[i])(
|
| + static_domain_state.static_spki_hashes[i]));
|
| }
|
|
|
| // Expect the dynamic state to reflect the header.
|
| @@ -539,16 +602,15 @@ TEST_F(HttpSecurityHeadersTest, UpdateDynamicPKPOnly) {
|
| EXPECT_TRUE(state.GetDynamicDomainState(domain, &dynamic_domain_state));
|
| EXPECT_EQ(2UL, dynamic_domain_state.dynamic_spki_hashes.size());
|
|
|
| - HashValueVector::const_iterator hash = std::find_if(
|
| - dynamic_domain_state.dynamic_spki_hashes.begin(),
|
| - dynamic_domain_state.dynamic_spki_hashes.end(),
|
| - HashValuesEqual(good_hash));
|
| + HashValueVector::const_iterator hash =
|
| + std::find_if(dynamic_domain_state.dynamic_spki_hashes.begin(),
|
| + dynamic_domain_state.dynamic_spki_hashes.end(),
|
| + HashValuesEqual(good_hash));
|
| EXPECT_NE(dynamic_domain_state.dynamic_spki_hashes.end(), hash);
|
|
|
| - hash = std::find_if(
|
| - dynamic_domain_state.dynamic_spki_hashes.begin(),
|
| - dynamic_domain_state.dynamic_spki_hashes.end(),
|
| - HashValuesEqual(backup_hash));
|
| + hash = std::find_if(dynamic_domain_state.dynamic_spki_hashes.begin(),
|
| + dynamic_domain_state.dynamic_spki_hashes.end(),
|
| + HashValuesEqual(backup_hash));
|
| EXPECT_NE(dynamic_domain_state.dynamic_spki_hashes.end(), hash);
|
|
|
| // Expect the overall state to reflect the header, too.
|
| @@ -560,11 +622,10 @@ TEST_F(HttpSecurityHeadersTest, UpdateDynamicPKPOnly) {
|
| HashValuesEqual(good_hash));
|
| EXPECT_NE(domain_state.dynamic_spki_hashes.end(), hash);
|
|
|
| - hash = std::find_if(
|
| - domain_state.dynamic_spki_hashes.begin(),
|
| - domain_state.dynamic_spki_hashes.end(),
|
| - HashValuesEqual(backup_hash));
|
| + hash = std::find_if(domain_state.dynamic_spki_hashes.begin(),
|
| + domain_state.dynamic_spki_hashes.end(),
|
| + HashValuesEqual(backup_hash));
|
| EXPECT_NE(domain_state.dynamic_spki_hashes.end(), hash);
|
| }
|
|
|
| -}; // namespace net
|
| +}; // namespace net
|
|
|