OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/default_origin_bound_cert_store.h" | 5 #include "net/base/default_origin_bound_cert_store.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); | 75 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); |
76 | 76 |
77 persistent_store->AddOriginBoundCert( | 77 persistent_store->AddOriginBoundCert( |
78 DefaultOriginBoundCertStore::OriginBoundCert( | 78 DefaultOriginBoundCertStore::OriginBoundCert( |
79 "https://encrypted.google.com/", "a", "b")); | 79 "https://encrypted.google.com/", "a", "b")); |
80 persistent_store->AddOriginBoundCert( | 80 persistent_store->AddOriginBoundCert( |
81 DefaultOriginBoundCertStore::OriginBoundCert( | 81 DefaultOriginBoundCertStore::OriginBoundCert( |
82 "https://www.verisign.com/", "c", "d")); | 82 "https://www.verisign.com/", "c", "d")); |
83 | 83 |
84 // Make sure certs load properly. | 84 // Make sure certs load properly. |
85 scoped_ptr<DefaultOriginBoundCertStore> store( | 85 DefaultOriginBoundCertStore store(persistent_store.get()); |
86 new DefaultOriginBoundCertStore(persistent_store)); | 86 EXPECT_EQ(2, store.GetCertCount()); |
87 EXPECT_EQ(2, store->GetCertCount()); | 87 store.SetOriginBoundCert("https://www.verisign.com/", "e", "f"); |
88 EXPECT_TRUE(store->SetOriginBoundCert("https://www.verisign.com/", "e", "f")); | 88 EXPECT_EQ(2, store.GetCertCount()); |
89 EXPECT_EQ(2, store->GetCertCount()); | 89 store.SetOriginBoundCert("https://www.twitter.com/", "g", "h"); |
90 EXPECT_TRUE(store->SetOriginBoundCert("https://www.twitter.com/", "g", "h")); | 90 EXPECT_EQ(3, store.GetCertCount()); |
91 EXPECT_EQ(3, store->GetCertCount()); | |
92 } | 91 } |
93 | 92 |
94 TEST(DefaultOriginBoundCertStoreTest, TestSettingAndGetting) { | 93 TEST(DefaultOriginBoundCertStoreTest, TestSettingAndGetting) { |
95 scoped_ptr<DefaultOriginBoundCertStore> store( | 94 DefaultOriginBoundCertStore store(NULL); |
96 new DefaultOriginBoundCertStore(NULL)); | |
97 std::string private_key, cert; | 95 std::string private_key, cert; |
98 EXPECT_EQ(0, store->GetCertCount()); | 96 EXPECT_EQ(0, store.GetCertCount()); |
99 EXPECT_FALSE(store->GetOriginBoundCert("https://www.verisign.com/", | 97 EXPECT_FALSE(store.GetOriginBoundCert("https://www.verisign.com/", |
100 &private_key, | 98 &private_key, |
101 &cert)); | 99 &cert)); |
102 EXPECT_TRUE(private_key.empty()); | 100 EXPECT_TRUE(private_key.empty()); |
103 EXPECT_TRUE(cert.empty()); | 101 EXPECT_TRUE(cert.empty()); |
104 EXPECT_TRUE(store->SetOriginBoundCert("https://www.verisign.com/", "i", "j")); | 102 store.SetOriginBoundCert("https://www.verisign.com/", "i", "j"); |
105 EXPECT_TRUE(store->GetOriginBoundCert("https://www.verisign.com/", | 103 EXPECT_TRUE(store.GetOriginBoundCert("https://www.verisign.com/", |
106 &private_key, | 104 &private_key, |
107 &cert)); | 105 &cert)); |
108 EXPECT_EQ("i", private_key); | 106 EXPECT_EQ("i", private_key); |
109 EXPECT_EQ("j", cert); | 107 EXPECT_EQ("j", cert); |
110 } | 108 } |
111 | 109 |
| 110 TEST(DefaultOriginBoundCertStoreTest, TestDuplicateCerts) { |
| 111 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); |
| 112 DefaultOriginBoundCertStore store(persistent_store.get()); |
| 113 |
| 114 std::string private_key, cert; |
| 115 EXPECT_EQ(0, store.GetCertCount()); |
| 116 store.SetOriginBoundCert("https://www.verisign.com/", "a", "b"); |
| 117 store.SetOriginBoundCert("https://www.verisign.com/", "c", "d"); |
| 118 |
| 119 EXPECT_EQ(1, store.GetCertCount()); |
| 120 EXPECT_TRUE(store.GetOriginBoundCert("https://www.verisign.com/", |
| 121 &private_key, |
| 122 &cert)); |
| 123 EXPECT_EQ("c", private_key); |
| 124 EXPECT_EQ("d", cert); |
| 125 } |
| 126 |
| 127 TEST(DefaultOriginBoundCertStoreTest, TestDeleteAll) { |
| 128 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); |
| 129 DefaultOriginBoundCertStore store(persistent_store.get()); |
| 130 |
| 131 EXPECT_EQ(0, store.GetCertCount()); |
| 132 store.SetOriginBoundCert("https://www.verisign.com/", "a", "b"); |
| 133 store.SetOriginBoundCert("https://www.google.com/", "c", "d"); |
| 134 store.SetOriginBoundCert("https://www.harvard.com/", "e", "f"); |
| 135 |
| 136 EXPECT_EQ(3, store.GetCertCount()); |
| 137 store.DeleteAll(); |
| 138 EXPECT_EQ(0, store.GetCertCount()); |
| 139 } |
| 140 |
| 141 TEST(DefaultOriginBoundCertStoreTest, TestDelete) { |
| 142 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); |
| 143 DefaultOriginBoundCertStore store(persistent_store.get()); |
| 144 |
| 145 std::string private_key, cert; |
| 146 EXPECT_EQ(0, store.GetCertCount()); |
| 147 store.SetOriginBoundCert("https://www.verisign.com/", "a", "b"); |
| 148 store.SetOriginBoundCert("https://www.google.com/", "c", "d"); |
| 149 |
| 150 EXPECT_EQ(2, store.GetCertCount()); |
| 151 store.DeleteOriginBoundCert("https://www.verisign.com/"); |
| 152 EXPECT_EQ(1, store.GetCertCount()); |
| 153 EXPECT_FALSE(store.GetOriginBoundCert("https://www.verisign.com/", |
| 154 &private_key, |
| 155 &cert)); |
| 156 EXPECT_TRUE(store.GetOriginBoundCert("https://www.google.com/", |
| 157 &private_key, |
| 158 &cert)); |
| 159 store.DeleteOriginBoundCert("https://www.google.com/"); |
| 160 EXPECT_EQ(0, store.GetCertCount()); |
| 161 EXPECT_FALSE(store.GetOriginBoundCert("https://www.google.com/", |
| 162 &private_key, |
| 163 &cert)); |
| 164 } |
| 165 |
| 166 TEST(DefaultOriginBoundCertStoreTest, TestGetAll) { |
| 167 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); |
| 168 DefaultOriginBoundCertStore store(persistent_store.get()); |
| 169 |
| 170 EXPECT_EQ(0, store.GetCertCount()); |
| 171 store.SetOriginBoundCert("https://www.verisign.com/", "a", "b"); |
| 172 store.SetOriginBoundCert("https://www.google.com/", "c", "d"); |
| 173 store.SetOriginBoundCert("https://www.harvard.com/", "e", "f"); |
| 174 store.SetOriginBoundCert("https://www.mit.com/", "g", "h"); |
| 175 |
| 176 EXPECT_EQ(4, store.GetCertCount()); |
| 177 std::vector<OriginBoundCertStore::OriginBoundCertInfo> certs; |
| 178 store.GetAllOriginBoundCerts(&certs); |
| 179 EXPECT_EQ(4u, certs.size()); |
| 180 } |
| 181 |
112 } // namespace net | 182 } // namespace net |
OLD | NEW |