Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: net/base/transport_security_state_unittest.cc

Issue 6500010: HSTS: add net-internals UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« net/base/dns_util.cc ('K') | « net/base/transport_security_state.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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"));
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
OLDNEW
« net/base/dns_util.cc ('K') | « net/base/transport_security_state.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698