Chromium Code Reviews| 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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 domain_state.mode = TransportSecurityState::DomainState::MODE_STRICT; | 274 domain_state.mode = TransportSecurityState::DomainState::MODE_STRICT; |
| 275 domain_state.expiry = expiry; | 275 domain_state.expiry = expiry; |
| 276 state->EnableHost("google.com", domain_state); | 276 state->EnableHost("google.com", domain_state); |
| 277 | 277 |
| 278 state->DeleteSince(expiry); | 278 state->DeleteSince(expiry); |
| 279 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "google.com")); | 279 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "google.com")); |
| 280 state->DeleteSince(older); | 280 state->DeleteSince(older); |
| 281 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, "google.com")); | 281 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, "google.com")); |
| 282 } | 282 } |
| 283 | 283 |
| 284 TEST_F(TransportSecurityStateTest, DeleteHost) { | |
| 285 scoped_refptr<TransportSecurityState> state( | |
| 286 new TransportSecurityState); | |
| 287 | |
| 288 TransportSecurityState::DomainState domain_state; | |
| 289 const base::Time current_time(base::Time::Now()); | |
| 290 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); | |
| 291 domain_state.mode = TransportSecurityState::DomainState::MODE_STRICT; | |
| 292 domain_state.expiry = expiry; | |
| 293 state->EnableHost("google.com", domain_state); | |
| 294 | |
| 295 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "google.com")); | |
| 296 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, "example.com")); | |
| 297 EXPECT_TRUE(state->DeleteHost("google.com")); | |
| 298 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, "google.com")); | |
| 299 } | |
| 300 | |
| 284 TEST_F(TransportSecurityStateTest, SerialiseOld) { | 301 TEST_F(TransportSecurityStateTest, SerialiseOld) { |
| 285 scoped_refptr<TransportSecurityState> state( | 302 scoped_refptr<TransportSecurityState> state( |
| 286 new TransportSecurityState); | 303 new TransportSecurityState); |
| 287 // This is an old-style piece of transport state JSON, which has no creation | 304 // This is an old-style piece of transport state JSON, which has no creation |
| 288 // date. | 305 // date. |
| 289 std::string output = | 306 std::string output = |
| 290 "{ " | 307 "{ " |
| 291 "\"NiyD+3J1r6z1wjl2n1ALBu94Zj9OsEAMo0kCN8js0Uk=\": {" | 308 "\"NiyD+3J1r6z1wjl2n1ALBu94Zj9OsEAMo0kCN8js0Uk=\": {" |
| 292 "\"expiry\": 1266815027.983453, " | 309 "\"expiry\": 1266815027.983453, " |
| 293 "\"include_subdomains\": false, " | 310 "\"include_subdomains\": false, " |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 324 } | 341 } |
| 325 | 342 |
| 326 TEST_F(TransportSecurityStateTest, Preloaded) { | 343 TEST_F(TransportSecurityStateTest, Preloaded) { |
| 327 scoped_refptr<TransportSecurityState> state( | 344 scoped_refptr<TransportSecurityState> state( |
| 328 new TransportSecurityState); | 345 new TransportSecurityState); |
| 329 TransportSecurityState::DomainState domain_state; | 346 TransportSecurityState::DomainState domain_state; |
| 330 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, "paypal.com")); | 347 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, "paypal.com")); |
| 331 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "www.paypal.com")); | 348 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "www.paypal.com")); |
| 332 EXPECT_EQ(domain_state.mode, | 349 EXPECT_EQ(domain_state.mode, |
| 333 TransportSecurityState::DomainState::MODE_STRICT); | 350 TransportSecurityState::DomainState::MODE_STRICT); |
| 351 EXPECT_TRUE(domain_state.preloaded); | |
| 334 EXPECT_FALSE(domain_state.include_subdomains); | 352 EXPECT_FALSE(domain_state.include_subdomains); |
| 335 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, "www2.paypal.com")); | 353 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, "www2.paypal.com")); |
| 336 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, "a.www.paypal.com")); | 354 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, "a.www.paypal.com")); |
| 337 | 355 |
| 338 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, "elanex.biz")); | 356 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, "elanex.biz")); |
| 339 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "www.elanex.biz")); | 357 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "www.elanex.biz")); |
| 340 EXPECT_EQ(domain_state.mode, | 358 EXPECT_EQ(domain_state.mode, |
| 341 TransportSecurityState::DomainState::MODE_STRICT); | 359 TransportSecurityState::DomainState::MODE_STRICT); |
| 342 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, "foo.elanex.biz")); | 360 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, "foo.elanex.biz")); |
| 343 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, "a.foo.elanex.biz")); | 361 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, "a.foo.elanex.biz")); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 363 | 381 |
| 364 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "members.mayfirst.org")); | 382 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "members.mayfirst.org")); |
| 365 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "support.mayfirst.org")); | 383 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "support.mayfirst.org")); |
| 366 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "id.mayfirst.org")); | 384 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "id.mayfirst.org")); |
| 367 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "lists.mayfirst.org")); | 385 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "lists.mayfirst.org")); |
| 368 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, "www.mayfirst.org")); | 386 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, "www.mayfirst.org")); |
| 369 | 387 |
| 370 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "splendidbacon.com")); | 388 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "splendidbacon.com")); |
| 371 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "www.splendidbacon.com")); | 389 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "www.splendidbacon.com")); |
| 372 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "foo.splendidbacon.com")); | 390 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "foo.splendidbacon.com")); |
| 391 | |
| 392 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "chrome.google.com")); | |
|
agl
2011/02/11 21:10:17
These are unrelated to this change, but should hav
| |
| 393 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "checkout.google.com")); | |
| 394 EXPECT_TRUE(state->IsEnabledForHost(&domain_state, "health.google.com")); | |
| 373 } | 395 } |
| 374 | 396 |
| 375 TEST_F(TransportSecurityStateTest, LongNames) { | 397 TEST_F(TransportSecurityStateTest, LongNames) { |
| 376 scoped_refptr<TransportSecurityState> state( | 398 scoped_refptr<TransportSecurityState> state( |
| 377 new TransportSecurityState); | 399 new TransportSecurityState); |
| 378 const char kLongName[] = | 400 const char kLongName[] = |
| 379 "lookupByWaveIdHashAndWaveIdIdAndWaveIdDomainAndWaveletIdIdAnd" | 401 "lookupByWaveIdHashAndWaveIdIdAndWaveIdDomainAndWaveletIdIdAnd" |
| 380 "WaveletIdDomainAndBlipBlipid"; | 402 "WaveletIdDomainAndBlipBlipid"; |
| 381 TransportSecurityState::DomainState domain_state; | 403 TransportSecurityState::DomainState domain_state; |
| 382 // Just checks that we don't hit a NOTREACHED. | 404 // Just checks that we don't hit a NOTREACHED. |
| 383 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, kLongName)); | 405 EXPECT_FALSE(state->IsEnabledForHost(&domain_state, kLongName)); |
| 384 } | 406 } |
| 385 | 407 |
| 386 } // namespace net | 408 } // namespace net |
| OLD | NEW |