| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/base/strict_transport_security_state.h" | 5 #include "net/base/strict_transport_security_state.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 | 7 |
| 8 namespace { | 8 namespace { |
| 9 | 9 |
| 10 class StrictTransportSecurityStateTest : public testing::Test { | 10 class StrictTransportSecurityStateTest : public testing::Test { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 EXPECT_FALSE(net::StrictTransportSecurityState::ParseHeader( | 71 EXPECT_FALSE(net::StrictTransportSecurityState::ParseHeader( |
| 72 "max-age=3488923 includesubdomain=", &max_age, &include_subdomains)); | 72 "max-age=3488923 includesubdomain=", &max_age, &include_subdomains)); |
| 73 EXPECT_FALSE(net::StrictTransportSecurityState::ParseHeader( | 73 EXPECT_FALSE(net::StrictTransportSecurityState::ParseHeader( |
| 74 "max-age=3488923 includesubdomain=true", &max_age, &include_subdomains)); | 74 "max-age=3488923 includesubdomain=true", &max_age, &include_subdomains)); |
| 75 EXPECT_FALSE(net::StrictTransportSecurityState::ParseHeader( | 75 EXPECT_FALSE(net::StrictTransportSecurityState::ParseHeader( |
| 76 "max-age=3488923 includesubdomainsx", &max_age, &include_subdomains)); | 76 "max-age=3488923 includesubdomainsx", &max_age, &include_subdomains)); |
| 77 EXPECT_FALSE(net::StrictTransportSecurityState::ParseHeader( | 77 EXPECT_FALSE(net::StrictTransportSecurityState::ParseHeader( |
| 78 "max-age=3488923 includesubdomains x", &max_age, &include_subdomains)); | 78 "max-age=3488923 includesubdomains x", &max_age, &include_subdomains)); |
| 79 EXPECT_FALSE(net::StrictTransportSecurityState::ParseHeader( | 79 EXPECT_FALSE(net::StrictTransportSecurityState::ParseHeader( |
| 80 "max-age=34889.23 includesubdomains", &max_age, &include_subdomains)); | 80 "max-age=34889.23 includesubdomains", &max_age, &include_subdomains)); |
| 81 EXPECT_FALSE(net::StrictTransportSecurityState::ParseHeader( |
| 82 "max-age=34889 includesubdomains", &max_age, &include_subdomains)); |
| 81 | 83 |
| 82 EXPECT_EQ(max_age, 42); | 84 EXPECT_EQ(max_age, 42); |
| 83 EXPECT_FALSE(include_subdomains); | 85 EXPECT_FALSE(include_subdomains); |
| 84 } | 86 } |
| 85 | 87 |
| 86 TEST_F(StrictTransportSecurityStateTest, ValidHeaders) { | 88 TEST_F(StrictTransportSecurityStateTest, ValidHeaders) { |
| 87 int max_age = 42; | 89 int max_age = 42; |
| 88 bool include_subdomains = true; | 90 bool include_subdomains = true; |
| 89 | 91 |
| 90 EXPECT_TRUE(net::StrictTransportSecurityState::ParseHeader( | 92 EXPECT_TRUE(net::StrictTransportSecurityState::ParseHeader( |
| 91 "max-age=243", &max_age, &include_subdomains)); | 93 "max-age=243", &max_age, &include_subdomains)); |
| 92 EXPECT_EQ(max_age, 243); | 94 EXPECT_EQ(max_age, 243); |
| 93 EXPECT_FALSE(include_subdomains); | 95 EXPECT_FALSE(include_subdomains); |
| 94 | 96 |
| 95 EXPECT_TRUE(net::StrictTransportSecurityState::ParseHeader( | 97 EXPECT_TRUE(net::StrictTransportSecurityState::ParseHeader( |
| 96 " Max-agE = 567", &max_age, &include_subdomains)); | 98 " Max-agE = 567", &max_age, &include_subdomains)); |
| 97 EXPECT_EQ(max_age, 567); | 99 EXPECT_EQ(max_age, 567); |
| 98 EXPECT_FALSE(include_subdomains); | 100 EXPECT_FALSE(include_subdomains); |
| 99 | 101 |
| 100 EXPECT_TRUE(net::StrictTransportSecurityState::ParseHeader( | 102 EXPECT_TRUE(net::StrictTransportSecurityState::ParseHeader( |
| 101 " mAx-aGe = 890 ", &max_age, &include_subdomains)); | 103 " mAx-aGe = 890 ", &max_age, &include_subdomains)); |
| 102 EXPECT_EQ(max_age, 890); | 104 EXPECT_EQ(max_age, 890); |
| 103 EXPECT_FALSE(include_subdomains); | 105 EXPECT_FALSE(include_subdomains); |
| 104 | 106 |
| 105 EXPECT_TRUE(net::StrictTransportSecurityState::ParseHeader( | 107 EXPECT_TRUE(net::StrictTransportSecurityState::ParseHeader( |
| 106 "max-age=123 incLudesUbdOmains", &max_age, &include_subdomains)); | 108 "max-age=123;incLudesUbdOmains", &max_age, &include_subdomains)); |
| 107 EXPECT_EQ(max_age, 123); | 109 EXPECT_EQ(max_age, 123); |
| 108 EXPECT_TRUE(include_subdomains); | 110 EXPECT_TRUE(include_subdomains); |
| 109 | 111 |
| 110 EXPECT_TRUE(net::StrictTransportSecurityState::ParseHeader( | 112 EXPECT_TRUE(net::StrictTransportSecurityState::ParseHeader( |
| 111 "max-age=394082038 incLudesUbdOmains", &max_age, &include_subdomains)); | 113 "max-age=394082; incLudesUbdOmains", &max_age, &include_subdomains)); |
| 114 EXPECT_EQ(max_age, 394082); |
| 115 EXPECT_TRUE(include_subdomains); |
| 116 |
| 117 EXPECT_TRUE(net::StrictTransportSecurityState::ParseHeader( |
| 118 "max-age=39408299 ;incLudesUbdOmains", &max_age, &include_subdomains)); |
| 119 EXPECT_EQ(max_age, 39408299); |
| 120 EXPECT_TRUE(include_subdomains); |
| 121 |
| 122 EXPECT_TRUE(net::StrictTransportSecurityState::ParseHeader( |
| 123 "max-age=394082038 ; incLudesUbdOmains", &max_age, &include_subdomains))
; |
| 112 EXPECT_EQ(max_age, 394082038); | 124 EXPECT_EQ(max_age, 394082038); |
| 113 EXPECT_TRUE(include_subdomains); | 125 EXPECT_TRUE(include_subdomains); |
| 114 | 126 |
| 115 EXPECT_TRUE(net::StrictTransportSecurityState::ParseHeader( | 127 EXPECT_TRUE(net::StrictTransportSecurityState::ParseHeader( |
| 116 " max-age=0 incLudesUbdOmains ", &max_age, &include_subdomains)); | 128 " max-age=0 ; incLudesUbdOmains ", &max_age, &include_subdomains)); |
| 117 EXPECT_EQ(max_age, 0); | 129 EXPECT_EQ(max_age, 0); |
| 118 EXPECT_TRUE(include_subdomains); | 130 EXPECT_TRUE(include_subdomains); |
| 119 } | 131 } |
| 120 | 132 |
| 121 } // namespace | 133 } // namespace |
| OLD | NEW |