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/transport_security_state.h" | 5 #include "net/base/transport_security_state.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 | 7 |
8 namespace net { | 8 namespace net { |
9 | 9 |
10 class TransportSecurityStateTest : public testing::Test { | 10 class TransportSecurityStateTest : public testing::Test { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 EXPECT_EQ(max_age, 123); | 109 EXPECT_EQ(max_age, 123); |
110 EXPECT_TRUE(include_subdomains); | 110 EXPECT_TRUE(include_subdomains); |
111 | 111 |
112 EXPECT_TRUE(TransportSecurityState::ParseHeader( | 112 EXPECT_TRUE(TransportSecurityState::ParseHeader( |
113 "max-age=394082; incLudesUbdOmains", &max_age, &include_subdomains)); | 113 "max-age=394082; incLudesUbdOmains", &max_age, &include_subdomains)); |
114 EXPECT_EQ(max_age, 394082); | 114 EXPECT_EQ(max_age, 394082); |
115 EXPECT_TRUE(include_subdomains); | 115 EXPECT_TRUE(include_subdomains); |
116 | 116 |
117 EXPECT_TRUE(TransportSecurityState::ParseHeader( | 117 EXPECT_TRUE(TransportSecurityState::ParseHeader( |
118 "max-age=39408299 ;incLudesUbdOmains", &max_age, &include_subdomains)); | 118 "max-age=39408299 ;incLudesUbdOmains", &max_age, &include_subdomains)); |
119 EXPECT_EQ(max_age, 39408299); | 119 EXPECT_EQ(max_age, |
| 120 std::min(TransportSecurityState::kMaxHSTSAgeSecs, 39408299l)); |
120 EXPECT_TRUE(include_subdomains); | 121 EXPECT_TRUE(include_subdomains); |
121 | 122 |
122 EXPECT_TRUE(TransportSecurityState::ParseHeader( | 123 EXPECT_TRUE(TransportSecurityState::ParseHeader( |
123 "max-age=394082038 ; incLudesUbdOmains", &max_age, &include_subdomains))
; | 124 "max-age=394082038 ; incLudesUbdOmains", &max_age, &include_subdomains))
; |
124 EXPECT_EQ(max_age, 394082038); | 125 EXPECT_EQ(max_age, |
| 126 std::min(TransportSecurityState::kMaxHSTSAgeSecs, 394082038l)); |
125 EXPECT_TRUE(include_subdomains); | 127 EXPECT_TRUE(include_subdomains); |
126 | 128 |
127 EXPECT_TRUE(TransportSecurityState::ParseHeader( | 129 EXPECT_TRUE(TransportSecurityState::ParseHeader( |
128 " max-age=0 ; incLudesUbdOmains ", &max_age, &include_subdomains)); | 130 " max-age=0 ; incLudesUbdOmains ", &max_age, &include_subdomains)); |
129 EXPECT_EQ(max_age, 0); | 131 EXPECT_EQ(max_age, 0); |
130 EXPECT_TRUE(include_subdomains); | 132 EXPECT_TRUE(include_subdomains); |
| 133 |
| 134 EXPECT_TRUE(TransportSecurityState::ParseHeader( |
| 135 " max-age=999999999999999999999999999999999999999999999 ;" |
| 136 " incLudesUbdOmains ", |
| 137 &max_age, &include_subdomains)); |
| 138 EXPECT_EQ(max_age, TransportSecurityState::kMaxHSTSAgeSecs); |
| 139 EXPECT_TRUE(include_subdomains); |
131 } | 140 } |
132 | 141 |
133 TEST_F(TransportSecurityStateTest, SimpleMatches) { | 142 TEST_F(TransportSecurityStateTest, SimpleMatches) { |
134 scoped_refptr<TransportSecurityState> state( | 143 scoped_refptr<TransportSecurityState> state( |
135 new TransportSecurityState); | 144 new TransportSecurityState); |
136 TransportSecurityState::DomainState domain_state; | 145 TransportSecurityState::DomainState domain_state; |
137 const base::Time current_time(base::Time::Now()); | 146 const base::Time current_time(base::Time::Now()); |
138 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); | 147 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); |
139 | 148 |
140 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, "google.com")); | 149 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, "google.com")); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 new TransportSecurityState); | 361 new TransportSecurityState); |
353 const char kLongName[] = | 362 const char kLongName[] = |
354 "lookupByWaveIdHashAndWaveIdIdAndWaveIdDomainAndWaveletIdIdAnd" | 363 "lookupByWaveIdHashAndWaveIdIdAndWaveIdDomainAndWaveletIdIdAnd" |
355 "WaveletIdDomainAndBlipBlipid"; | 364 "WaveletIdDomainAndBlipBlipid"; |
356 TransportSecurityState::DomainState domain_state; | 365 TransportSecurityState::DomainState domain_state; |
357 // Just checks that we don't hit a NOTREACHED. | 366 // Just checks that we don't hit a NOTREACHED. |
358 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, kLongName)); | 367 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, kLongName)); |
359 } | 368 } |
360 | 369 |
361 } // namespace net | 370 } // namespace net |
OLD | NEW |