OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/http/transport_security_persister.h" | 5 #include "net/http/transport_security_persister.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 EXPECT_TRUE(persister_->LoadEntries(output, &dirty)); | 50 EXPECT_TRUE(persister_->LoadEntries(output, &dirty)); |
51 EXPECT_FALSE(dirty); | 51 EXPECT_FALSE(dirty); |
52 } | 52 } |
53 | 53 |
54 TEST_F(TransportSecurityPersisterTest, SerializeData2) { | 54 TEST_F(TransportSecurityPersisterTest, SerializeData2) { |
55 TransportSecurityState::DomainState domain_state; | 55 TransportSecurityState::DomainState domain_state; |
56 const base::Time current_time(base::Time::Now()); | 56 const base::Time current_time(base::Time::Now()); |
57 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); | 57 const base::Time expiry = current_time + base::TimeDelta::FromSeconds(1000); |
58 static const char kYahooDomain[] = "yahoo.com"; | 58 static const char kYahooDomain[] = "yahoo.com"; |
59 | 59 |
60 EXPECT_FALSE(state_.GetStaticDomainState(kYahooDomain, true, &domain_state)); | 60 EXPECT_FALSE(state_.GetStaticDomainState(kYahooDomain, &domain_state)); |
61 EXPECT_FALSE(state_.GetDynamicDomainState(kYahooDomain, &domain_state)); | 61 EXPECT_FALSE(state_.GetDynamicDomainState(kYahooDomain, &domain_state)); |
62 | 62 |
63 bool include_subdomains = true; | 63 bool include_subdomains = true; |
64 state_.AddHSTS(kYahooDomain, expiry, include_subdomains); | 64 state_.AddHSTS(kYahooDomain, expiry, include_subdomains); |
65 | 65 |
66 std::string output; | 66 std::string output; |
67 bool dirty; | 67 bool dirty; |
68 EXPECT_TRUE(persister_->SerializeData(&output)); | 68 EXPECT_TRUE(persister_->SerializeData(&output)); |
69 EXPECT_TRUE(persister_->LoadEntries(output, &dirty)); | 69 EXPECT_TRUE(persister_->LoadEntries(output, &dirty)); |
70 | 70 |
71 EXPECT_TRUE(state_.GetDynamicDomainState(kYahooDomain, &domain_state)); | 71 EXPECT_TRUE(state_.GetDynamicDomainState(kYahooDomain, &domain_state)); |
72 EXPECT_EQ(domain_state.sts.upgrade_mode, | 72 EXPECT_EQ(domain_state.sts.upgrade_mode, |
73 TransportSecurityState::DomainState::MODE_FORCE_HTTPS); | 73 TransportSecurityState::DomainState::MODE_FORCE_HTTPS); |
74 EXPECT_TRUE(state_.GetDynamicDomainState("foo.yahoo.com", &domain_state)); | 74 EXPECT_TRUE(state_.GetDynamicDomainState("foo.yahoo.com", &domain_state)); |
75 EXPECT_EQ(domain_state.sts.upgrade_mode, | 75 EXPECT_EQ(domain_state.sts.upgrade_mode, |
76 TransportSecurityState::DomainState::MODE_FORCE_HTTPS); | 76 TransportSecurityState::DomainState::MODE_FORCE_HTTPS); |
77 EXPECT_TRUE(state_.GetDynamicDomainState("foo.bar.yahoo.com", &domain_state)); | 77 EXPECT_TRUE(state_.GetDynamicDomainState("foo.bar.yahoo.com", &domain_state)); |
78 EXPECT_EQ(domain_state.sts.upgrade_mode, | 78 EXPECT_EQ(domain_state.sts.upgrade_mode, |
79 TransportSecurityState::DomainState::MODE_FORCE_HTTPS); | 79 TransportSecurityState::DomainState::MODE_FORCE_HTTPS); |
80 EXPECT_TRUE( | 80 EXPECT_TRUE( |
81 state_.GetDynamicDomainState("foo.bar.baz.yahoo.com", &domain_state)); | 81 state_.GetDynamicDomainState("foo.bar.baz.yahoo.com", &domain_state)); |
82 EXPECT_EQ(domain_state.sts.upgrade_mode, | 82 EXPECT_EQ(domain_state.sts.upgrade_mode, |
83 TransportSecurityState::DomainState::MODE_FORCE_HTTPS); | 83 TransportSecurityState::DomainState::MODE_FORCE_HTTPS); |
84 EXPECT_FALSE(state_.GetStaticDomainState("com", true, &domain_state)); | 84 EXPECT_FALSE(state_.GetStaticDomainState("com", &domain_state)); |
85 } | 85 } |
86 | 86 |
87 TEST_F(TransportSecurityPersisterTest, SerializeData3) { | 87 TEST_F(TransportSecurityPersisterTest, SerializeData3) { |
88 // Add an entry. | 88 // Add an entry. |
89 net::HashValue fp1(net::HASH_VALUE_SHA1); | 89 net::HashValue fp1(net::HASH_VALUE_SHA1); |
90 memset(fp1.data(), 0, fp1.size()); | 90 memset(fp1.data(), 0, fp1.size()); |
91 net::HashValue fp2(net::HASH_VALUE_SHA1); | 91 net::HashValue fp2(net::HASH_VALUE_SHA1); |
92 memset(fp2.data(), 1, fp2.size()); | 92 memset(fp2.data(), 1, fp2.size()); |
93 base::Time expiry = | 93 base::Time expiry = |
94 base::Time::Now() + base::TimeDelta::FromSeconds(1000); | 94 base::Time::Now() + base::TimeDelta::FromSeconds(1000); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 | 197 |
198 TransportSecurityState::DomainState new_domain_state; | 198 TransportSecurityState::DomainState new_domain_state; |
199 EXPECT_TRUE(state_.GetDynamicDomainState(kTestDomain, &new_domain_state)); | 199 EXPECT_TRUE(state_.GetDynamicDomainState(kTestDomain, &new_domain_state)); |
200 EXPECT_EQ(1u, new_domain_state.pkp.spki_hashes.size()); | 200 EXPECT_EQ(1u, new_domain_state.pkp.spki_hashes.size()); |
201 EXPECT_EQ(sha1.tag, new_domain_state.pkp.spki_hashes[0].tag); | 201 EXPECT_EQ(sha1.tag, new_domain_state.pkp.spki_hashes[0].tag); |
202 EXPECT_EQ(0, | 202 EXPECT_EQ(0, |
203 memcmp(new_domain_state.pkp.spki_hashes[0].data(), | 203 memcmp(new_domain_state.pkp.spki_hashes[0].data(), |
204 sha1.data(), | 204 sha1.data(), |
205 sha1.size())); | 205 sha1.size())); |
206 } | 206 } |
OLD | NEW |