Chromium Code Reviews| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 EXPECT_TRUE(private_key.empty()); | 102 EXPECT_TRUE(private_key.empty()); |
| 103 EXPECT_TRUE(cert.empty()); | 103 EXPECT_TRUE(cert.empty()); |
| 104 EXPECT_TRUE(store->SetOriginBoundCert("https://www.verisign.com/", "i", "j")); | 104 EXPECT_TRUE(store->SetOriginBoundCert("https://www.verisign.com/", "i", "j")); |
| 105 EXPECT_TRUE(store->GetOriginBoundCert("https://www.verisign.com/", | 105 EXPECT_TRUE(store->GetOriginBoundCert("https://www.verisign.com/", |
| 106 &private_key, | 106 &private_key, |
| 107 &cert)); | 107 &cert)); |
| 108 EXPECT_EQ("i", private_key); | 108 EXPECT_EQ("i", private_key); |
| 109 EXPECT_EQ("j", cert); | 109 EXPECT_EQ("j", cert); |
| 110 } | 110 } |
| 111 | 111 |
| 112 TEST(DefaultOriginBoundCertStoreTest, TestDuplicateCerts) { | |
| 113 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); | |
| 114 scoped_ptr<DefaultOriginBoundCertStore> store( | |
| 115 new DefaultOriginBoundCertStore(persistent_store)); | |
|
wtc
2011/08/10 21:35:59
Consider using a local variable:
DefaultOriginBo
rkn
2011/08/16 21:11:45
I know this isn't exactly the change you were sugg
| |
| 116 | |
| 117 std::string private_key, cert; | |
| 118 EXPECT_EQ(0, store->GetCertCount()); | |
| 119 EXPECT_TRUE(store->SetOriginBoundCert("https://www.verisign.com/", "a", "b")); | |
| 120 EXPECT_TRUE(store->SetOriginBoundCert("https://www.verisign.com/", "c", "d")); | |
| 121 | |
| 122 EXPECT_EQ(1, store->GetCertCount()); | |
| 123 EXPECT_TRUE(store->GetOriginBoundCert("https://www.verisign.com/", | |
| 124 &private_key, | |
| 125 &cert)); | |
| 126 EXPECT_EQ("c", private_key); | |
| 127 EXPECT_EQ("d", cert); | |
| 128 } | |
| 129 | |
| 130 TEST(DefaultOriginBoundCertStoreTest, TestDeleteAll) { | |
| 131 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); | |
| 132 scoped_ptr<DefaultOriginBoundCertStore> store( | |
| 133 new DefaultOriginBoundCertStore(persistent_store)); | |
| 134 | |
| 135 EXPECT_EQ(0, store->GetCertCount()); | |
| 136 EXPECT_TRUE(store->SetOriginBoundCert("https://www.verisign.com/", "a", "b")); | |
| 137 EXPECT_TRUE(store->SetOriginBoundCert("https://www.google.com/", "c", "d")); | |
| 138 EXPECT_TRUE(store->SetOriginBoundCert("https://www.harvard.com/", "e", "f")); | |
| 139 | |
| 140 EXPECT_EQ(3, store->GetCertCount()); | |
| 141 store->DeleteAll(); | |
| 142 EXPECT_EQ(0, store->GetCertCount()); | |
| 143 } | |
| 144 | |
| 145 TEST(DefaultOriginBoundCertStoreTest, TestDelete) { | |
| 146 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); | |
| 147 scoped_ptr<DefaultOriginBoundCertStore> store( | |
| 148 new DefaultOriginBoundCertStore(persistent_store)); | |
| 149 | |
| 150 std::string private_key, cert; | |
| 151 EXPECT_EQ(0, store->GetCertCount()); | |
| 152 EXPECT_TRUE(store->SetOriginBoundCert("https://www.verisign.com/", "a", "b")); | |
| 153 EXPECT_TRUE(store->SetOriginBoundCert("https://www.google.com/", "c", "d")); | |
| 154 | |
| 155 EXPECT_EQ(2, store->GetCertCount()); | |
| 156 store->DeleteOriginBoundCert("https://www.verisign.com/"); | |
| 157 EXPECT_EQ(1, store->GetCertCount()); | |
| 158 EXPECT_FALSE(store->GetOriginBoundCert("https://www.verisign.com/", | |
| 159 &private_key, | |
| 160 &cert)); | |
| 161 EXPECT_TRUE(store->GetOriginBoundCert("https://www.google.com/", | |
| 162 &private_key, | |
| 163 &cert)); | |
| 164 store->DeleteOriginBoundCert("https://www.google.com/"); | |
| 165 EXPECT_EQ(0, store->GetCertCount()); | |
| 166 EXPECT_FALSE(store->GetOriginBoundCert("https://www.google.com/", | |
| 167 &private_key, | |
| 168 &cert)); | |
| 169 } | |
| 170 | |
| 171 TEST(DefaultOriginBoundCertStoreTest, TestGetAll) { | |
| 172 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); | |
| 173 scoped_ptr<DefaultOriginBoundCertStore> store( | |
| 174 new DefaultOriginBoundCertStore(persistent_store)); | |
| 175 | |
| 176 EXPECT_EQ(0, store->GetCertCount()); | |
| 177 EXPECT_TRUE(store->SetOriginBoundCert("https://www.verisign.com/", "a", "b")); | |
| 178 EXPECT_TRUE(store->SetOriginBoundCert("https://www.google.com/", "c", "d")); | |
| 179 EXPECT_TRUE(store->SetOriginBoundCert("https://www.harvard.com/", "e", "f")); | |
| 180 EXPECT_TRUE(store->SetOriginBoundCert("https://www.mit.com/", "g", "h")); | |
| 181 | |
| 182 EXPECT_EQ(4, store->GetCertCount()); | |
| 183 std::vector<OriginBoundCertStore::OriginBoundCertInfo> certs; | |
| 184 store->GetAllOriginBoundCerts(&certs); | |
| 185 EXPECT_EQ(4u, certs.size()); | |
| 186 } | |
| 187 | |
| 112 } // namespace net | 188 } // namespace net |
| OLD | NEW |