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

Side by Side Diff: net/ssl/default_channel_id_store_unittest.cc

Issue 356713005: Rename ServerBoundCert => ChannelID to reflect the current name (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 5 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
OLDNEW
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/ssl/default_server_bound_cert_store.h" 5 #include "net/ssl/default_channel_id_store.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 int err_; 52 int err_;
53 std::string server_identifier_; 53 std::string server_identifier_;
54 base::Time expiration_time_; 54 base::Time expiration_time_;
55 std::string private_key_; 55 std::string private_key_;
56 std::string cert_; 56 std::string cert_;
57 bool called_; 57 bool called_;
58 }; 58 };
59 59
60 void GetAllCallback( 60 void GetAllCallback(
61 ServerBoundCertStore::ServerBoundCertList* dest, 61 ChannelIDStore::ChannelIDList* dest,
62 const ServerBoundCertStore::ServerBoundCertList& result) { 62 const ChannelIDStore::ChannelIDList& result) {
63 *dest = result; 63 *dest = result;
64 } 64 }
65 65
66 class MockPersistentStore 66 class MockPersistentStore
67 : public DefaultServerBoundCertStore::PersistentStore { 67 : public DefaultChannelIDStore::PersistentStore {
68 public: 68 public:
69 MockPersistentStore(); 69 MockPersistentStore();
70 70
71 // DefaultServerBoundCertStore::PersistentStore implementation. 71 // DefaultChannelIDStore::PersistentStore implementation.
72 virtual void Load(const LoadedCallback& loaded_callback) OVERRIDE; 72 virtual void Load(const LoadedCallback& loaded_callback) OVERRIDE;
73 virtual void AddServerBoundCert( 73 virtual void AddChannelID(
74 const DefaultServerBoundCertStore::ServerBoundCert& cert) OVERRIDE; 74 const DefaultChannelIDStore::ChannelID& cert) OVERRIDE;
75 virtual void DeleteServerBoundCert( 75 virtual void DeleteChannelID(
76 const DefaultServerBoundCertStore::ServerBoundCert& cert) OVERRIDE; 76 const DefaultChannelIDStore::ChannelID& cert) OVERRIDE;
wtc 2014/07/01 19:50:56 cert => channel_id in these two methods.
Ryan Hamilton 2014/07/21 19:12:12 Done.
77 virtual void SetForceKeepSessionState() OVERRIDE; 77 virtual void SetForceKeepSessionState() OVERRIDE;
78 78
79 protected: 79 protected:
80 virtual ~MockPersistentStore(); 80 virtual ~MockPersistentStore();
81 81
82 private: 82 private:
83 typedef std::map<std::string, DefaultServerBoundCertStore::ServerBoundCert> 83 typedef std::map<std::string, DefaultChannelIDStore::ChannelID>
84 ServerBoundCertMap; 84 ChannelIDMap;
85 85
86 ServerBoundCertMap origin_certs_; 86 ChannelIDMap origin_certs_;
wtc 2014/07/01 19:50:56 origin_certs_ => channel_ids_
Ryan Hamilton 2014/07/21 19:12:13 Done.
87 }; 87 };
88 88
89 MockPersistentStore::MockPersistentStore() {} 89 MockPersistentStore::MockPersistentStore() {}
90 90
91 void MockPersistentStore::Load(const LoadedCallback& loaded_callback) { 91 void MockPersistentStore::Load(const LoadedCallback& loaded_callback) {
92 scoped_ptr<ScopedVector<DefaultServerBoundCertStore::ServerBoundCert> > 92 scoped_ptr<ScopedVector<DefaultChannelIDStore::ChannelID> >
93 certs(new ScopedVector<DefaultServerBoundCertStore::ServerBoundCert>()); 93 certs(new ScopedVector<DefaultChannelIDStore::ChannelID>());
94 ServerBoundCertMap::iterator it; 94 ChannelIDMap::iterator it;
95 95
96 for (it = origin_certs_.begin(); it != origin_certs_.end(); ++it) { 96 for (it = origin_certs_.begin(); it != origin_certs_.end(); ++it) {
97 certs->push_back( 97 certs->push_back(
98 new DefaultServerBoundCertStore::ServerBoundCert(it->second)); 98 new DefaultChannelIDStore::ChannelID(it->second));
99 } 99 }
100 100
101 base::MessageLoop::current()->PostTask( 101 base::MessageLoop::current()->PostTask(
102 FROM_HERE, base::Bind(loaded_callback, base::Passed(&certs))); 102 FROM_HERE, base::Bind(loaded_callback, base::Passed(&certs)));
103 } 103 }
104 104
105 void MockPersistentStore::AddServerBoundCert( 105 void MockPersistentStore::AddChannelID(
106 const DefaultServerBoundCertStore::ServerBoundCert& cert) { 106 const DefaultChannelIDStore::ChannelID& cert) {
107 origin_certs_[cert.server_identifier()] = cert; 107 origin_certs_[cert.server_identifier()] = cert;
108 } 108 }
109 109
110 void MockPersistentStore::DeleteServerBoundCert( 110 void MockPersistentStore::DeleteChannelID(
111 const DefaultServerBoundCertStore::ServerBoundCert& cert) { 111 const DefaultChannelIDStore::ChannelID& cert) {
wtc 2014/07/01 19:50:56 cert => channel_id in these two methods.
Ryan Hamilton 2014/07/21 19:12:13 Done.
112 origin_certs_.erase(cert.server_identifier()); 112 origin_certs_.erase(cert.server_identifier());
113 } 113 }
114 114
115 void MockPersistentStore::SetForceKeepSessionState() {} 115 void MockPersistentStore::SetForceKeepSessionState() {}
116 116
117 MockPersistentStore::~MockPersistentStore() {} 117 MockPersistentStore::~MockPersistentStore() {}
118 118
119 } // namespace 119 } // namespace
120 120
121 TEST(DefaultServerBoundCertStoreTest, TestLoading) { 121 TEST(DefaultChannelIDStoreTest, TestLoading) {
122 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); 122 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore);
123 123
124 persistent_store->AddServerBoundCert( 124 persistent_store->AddChannelID(
125 DefaultServerBoundCertStore::ServerBoundCert( 125 DefaultChannelIDStore::ChannelID(
126 "google.com", 126 "google.com",
127 base::Time(), 127 base::Time(),
128 base::Time(), 128 base::Time(),
129 "a", "b")); 129 "a", "b"));
130 persistent_store->AddServerBoundCert( 130 persistent_store->AddChannelID(
131 DefaultServerBoundCertStore::ServerBoundCert( 131 DefaultChannelIDStore::ChannelID(
132 "verisign.com", 132 "verisign.com",
133 base::Time(), 133 base::Time(),
134 base::Time(), 134 base::Time(),
135 "c", "d")); 135 "c", "d"));
136 136
137 // Make sure certs load properly. 137 // Make sure certs load properly.
138 DefaultServerBoundCertStore store(persistent_store.get()); 138 DefaultChannelIDStore store(persistent_store.get());
139 // Load has not occurred yet. 139 // Load has not occurred yet.
140 EXPECT_EQ(0, store.GetCertCount()); 140 EXPECT_EQ(0, store.GetCertCount());
141 store.SetServerBoundCert( 141 store.SetChannelID(
142 "verisign.com", 142 "verisign.com",
143 base::Time(), 143 base::Time(),
144 base::Time(), 144 base::Time(),
145 "e", "f"); 145 "e", "f");
146 // Wait for load & queued set task. 146 // Wait for load & queued set task.
147 base::MessageLoop::current()->RunUntilIdle(); 147 base::MessageLoop::current()->RunUntilIdle();
148 EXPECT_EQ(2, store.GetCertCount()); 148 EXPECT_EQ(2, store.GetCertCount());
149 store.SetServerBoundCert( 149 store.SetChannelID(
150 "twitter.com", 150 "twitter.com",
151 base::Time(), 151 base::Time(),
152 base::Time(), 152 base::Time(),
153 "g", "h"); 153 "g", "h");
154 // Set should be synchronous now that load is done. 154 // Set should be synchronous now that load is done.
155 EXPECT_EQ(3, store.GetCertCount()); 155 EXPECT_EQ(3, store.GetCertCount());
156 } 156 }
157 157
158 //TODO(mattm): add more tests of without a persistent store? 158 //TODO(mattm): add more tests of without a persistent store?
159 TEST(DefaultServerBoundCertStoreTest, TestSettingAndGetting) { 159 TEST(DefaultChannelIDStoreTest, TestSettingAndGetting) {
160 // No persistent store, all calls will be synchronous. 160 // No persistent store, all calls will be synchronous.
161 DefaultServerBoundCertStore store(NULL); 161 DefaultChannelIDStore store(NULL);
162 base::Time expiration_time; 162 base::Time expiration_time;
163 std::string private_key, cert; 163 std::string private_key, cert;
164 EXPECT_EQ(0, store.GetCertCount()); 164 EXPECT_EQ(0, store.GetCertCount());
165 EXPECT_EQ(ERR_FILE_NOT_FOUND, 165 EXPECT_EQ(ERR_FILE_NOT_FOUND,
166 store.GetServerBoundCert("verisign.com", 166 store.GetChannelID("verisign.com",
167 &expiration_time, 167 &expiration_time,
168 &private_key, 168 &private_key,
169 &cert, 169 &cert,
170 base::Bind(&GetCertCallbackNotCalled))); 170 base::Bind(&GetCertCallbackNotCalled)));
171 EXPECT_TRUE(private_key.empty()); 171 EXPECT_TRUE(private_key.empty());
172 EXPECT_TRUE(cert.empty()); 172 EXPECT_TRUE(cert.empty());
173 store.SetServerBoundCert( 173 store.SetChannelID(
174 "verisign.com", 174 "verisign.com",
175 base::Time::FromInternalValue(123), 175 base::Time::FromInternalValue(123),
176 base::Time::FromInternalValue(456), 176 base::Time::FromInternalValue(456),
177 "i", "j"); 177 "i", "j");
178 EXPECT_EQ(OK, 178 EXPECT_EQ(OK,
179 store.GetServerBoundCert("verisign.com", 179 store.GetChannelID("verisign.com",
180 &expiration_time, 180 &expiration_time,
181 &private_key, 181 &private_key,
182 &cert, 182 &cert,
183 base::Bind(&GetCertCallbackNotCalled))); 183 base::Bind(&GetCertCallbackNotCalled)));
wtc 2014/07/01 19:50:56 Fix indentation of the two GetChannelID calls.
Ryan Hamilton 2014/07/21 19:12:13 Done.
184 EXPECT_EQ(456, expiration_time.ToInternalValue()); 184 EXPECT_EQ(456, expiration_time.ToInternalValue());
185 EXPECT_EQ("i", private_key); 185 EXPECT_EQ("i", private_key);
186 EXPECT_EQ("j", cert); 186 EXPECT_EQ("j", cert);
187 } 187 }
188 188
189 TEST(DefaultServerBoundCertStoreTest, TestDuplicateCerts) { 189 TEST(DefaultChannelIDStoreTest, TestDuplicateCerts) {
wtc 2014/07/01 19:50:56 TestDuplicateCerts => TestDuplicateChannelIDs
Ryan Hamilton 2014/07/21 19:12:13 Done.
190 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); 190 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore);
191 DefaultServerBoundCertStore store(persistent_store.get()); 191 DefaultChannelIDStore store(persistent_store.get());
192 192
193 base::Time expiration_time; 193 base::Time expiration_time;
194 std::string private_key, cert; 194 std::string private_key, cert;
195 EXPECT_EQ(0, store.GetCertCount()); 195 EXPECT_EQ(0, store.GetCertCount());
196 store.SetServerBoundCert( 196 store.SetChannelID(
197 "verisign.com", 197 "verisign.com",
198 base::Time::FromInternalValue(123), 198 base::Time::FromInternalValue(123),
199 base::Time::FromInternalValue(1234), 199 base::Time::FromInternalValue(1234),
200 "a", "b"); 200 "a", "b");
201 store.SetServerBoundCert( 201 store.SetChannelID(
202 "verisign.com", 202 "verisign.com",
203 base::Time::FromInternalValue(456), 203 base::Time::FromInternalValue(456),
204 base::Time::FromInternalValue(4567), 204 base::Time::FromInternalValue(4567),
205 "c", "d"); 205 "c", "d");
206 206
207 // Wait for load & queued set tasks. 207 // Wait for load & queued set tasks.
208 base::MessageLoop::current()->RunUntilIdle(); 208 base::MessageLoop::current()->RunUntilIdle();
209 EXPECT_EQ(1, store.GetCertCount()); 209 EXPECT_EQ(1, store.GetCertCount());
210 EXPECT_EQ(OK, 210 EXPECT_EQ(OK,
211 store.GetServerBoundCert("verisign.com", 211 store.GetChannelID("verisign.com",
212 &expiration_time, 212 &expiration_time,
213 &private_key, 213 &private_key,
214 &cert, 214 &cert,
215 base::Bind(&GetCertCallbackNotCalled))); 215 base::Bind(&GetCertCallbackNotCalled)));
wtc 2014/07/01 19:50:56 Fix the indentation of the arguments.
Ryan Hamilton 2014/07/21 19:12:12 Done.
216 EXPECT_EQ(4567, expiration_time.ToInternalValue()); 216 EXPECT_EQ(4567, expiration_time.ToInternalValue());
217 EXPECT_EQ("c", private_key); 217 EXPECT_EQ("c", private_key);
218 EXPECT_EQ("d", cert); 218 EXPECT_EQ("d", cert);
219 } 219 }
220 220
221 TEST(DefaultServerBoundCertStoreTest, TestAsyncGet) { 221 TEST(DefaultChannelIDStoreTest, TestAsyncGet) {
222 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); 222 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore);
223 persistent_store->AddServerBoundCert(ServerBoundCertStore::ServerBoundCert( 223 persistent_store->AddChannelID(ChannelIDStore::ChannelID(
224 "verisign.com", 224 "verisign.com",
225 base::Time::FromInternalValue(123), 225 base::Time::FromInternalValue(123),
226 base::Time::FromInternalValue(1234), 226 base::Time::FromInternalValue(1234),
227 "a", "b")); 227 "a", "b"));
228 228
229 DefaultServerBoundCertStore store(persistent_store.get()); 229 DefaultChannelIDStore store(persistent_store.get());
230 AsyncGetCertHelper helper; 230 AsyncGetCertHelper helper;
231 base::Time expiration_time; 231 base::Time expiration_time;
232 std::string private_key; 232 std::string private_key;
233 std::string cert = "not set"; 233 std::string cert = "not set";
234 EXPECT_EQ(0, store.GetCertCount()); 234 EXPECT_EQ(0, store.GetCertCount());
235 EXPECT_EQ(ERR_IO_PENDING, 235 EXPECT_EQ(ERR_IO_PENDING,
236 store.GetServerBoundCert("verisign.com", 236 store.GetChannelID("verisign.com",
237 &expiration_time, 237 &expiration_time,
238 &private_key, 238 &private_key,
239 &cert, 239 &cert,
240 base::Bind(&AsyncGetCertHelper::Callback, 240 base::Bind(&AsyncGetCertHelper::Callback,
241 base::Unretained(&helper)))); 241 base::Unretained(&helper))));
242 242
243 // Wait for load & queued get tasks. 243 // Wait for load & queued get tasks.
244 base::MessageLoop::current()->RunUntilIdle(); 244 base::MessageLoop::current()->RunUntilIdle();
245 EXPECT_EQ(1, store.GetCertCount()); 245 EXPECT_EQ(1, store.GetCertCount());
246 EXPECT_EQ("not set", cert); 246 EXPECT_EQ("not set", cert);
247 EXPECT_TRUE(helper.called_); 247 EXPECT_TRUE(helper.called_);
248 EXPECT_EQ(OK, helper.err_); 248 EXPECT_EQ(OK, helper.err_);
249 EXPECT_EQ("verisign.com", helper.server_identifier_); 249 EXPECT_EQ("verisign.com", helper.server_identifier_);
250 EXPECT_EQ(1234, helper.expiration_time_.ToInternalValue()); 250 EXPECT_EQ(1234, helper.expiration_time_.ToInternalValue());
251 EXPECT_EQ("a", helper.private_key_); 251 EXPECT_EQ("a", helper.private_key_);
252 EXPECT_EQ("b", helper.cert_); 252 EXPECT_EQ("b", helper.cert_);
253 } 253 }
254 254
255 TEST(DefaultServerBoundCertStoreTest, TestDeleteAll) { 255 TEST(DefaultChannelIDStoreTest, TestDeleteAll) {
256 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); 256 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore);
257 DefaultServerBoundCertStore store(persistent_store.get()); 257 DefaultChannelIDStore store(persistent_store.get());
258 258
259 store.SetServerBoundCert( 259 store.SetChannelID(
260 "verisign.com", 260 "verisign.com",
261 base::Time(), 261 base::Time(),
262 base::Time(), 262 base::Time(),
263 "a", "b"); 263 "a", "b");
264 store.SetServerBoundCert( 264 store.SetChannelID(
265 "google.com", 265 "google.com",
266 base::Time(), 266 base::Time(),
267 base::Time(), 267 base::Time(),
268 "c", "d"); 268 "c", "d");
269 store.SetServerBoundCert( 269 store.SetChannelID(
270 "harvard.com", 270 "harvard.com",
271 base::Time(), 271 base::Time(),
272 base::Time(), 272 base::Time(),
273 "e", "f"); 273 "e", "f");
274 // Wait for load & queued set tasks. 274 // Wait for load & queued set tasks.
275 base::MessageLoop::current()->RunUntilIdle(); 275 base::MessageLoop::current()->RunUntilIdle();
276 276
277 EXPECT_EQ(3, store.GetCertCount()); 277 EXPECT_EQ(3, store.GetCertCount());
278 int delete_finished = 0; 278 int delete_finished = 0;
279 store.DeleteAll(base::Bind(&CallCounter, &delete_finished)); 279 store.DeleteAll(base::Bind(&CallCounter, &delete_finished));
280 ASSERT_EQ(1, delete_finished); 280 ASSERT_EQ(1, delete_finished);
281 EXPECT_EQ(0, store.GetCertCount()); 281 EXPECT_EQ(0, store.GetCertCount());
282 } 282 }
283 283
284 TEST(DefaultServerBoundCertStoreTest, TestAsyncGetAndDeleteAll) { 284 TEST(DefaultChannelIDStoreTest, TestAsyncGetAndDeleteAll) {
285 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); 285 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore);
286 persistent_store->AddServerBoundCert(ServerBoundCertStore::ServerBoundCert( 286 persistent_store->AddChannelID(ChannelIDStore::ChannelID(
287 "verisign.com", 287 "verisign.com",
288 base::Time(), 288 base::Time(),
289 base::Time(), 289 base::Time(),
290 "a", "b")); 290 "a", "b"));
291 persistent_store->AddServerBoundCert(ServerBoundCertStore::ServerBoundCert( 291 persistent_store->AddChannelID(ChannelIDStore::ChannelID(
292 "google.com", 292 "google.com",
293 base::Time(), 293 base::Time(),
294 base::Time(), 294 base::Time(),
295 "c", "d")); 295 "c", "d"));
296 296
297 ServerBoundCertStore::ServerBoundCertList pre_certs; 297 ChannelIDStore::ChannelIDList pre_certs;
298 ServerBoundCertStore::ServerBoundCertList post_certs; 298 ChannelIDStore::ChannelIDList post_certs;
wtc 2014/07/01 19:50:56 pre_certs => pre_channel_ids post_certs => post_c
Ryan Hamilton 2014/07/21 19:12:13 Done.
299 int delete_finished = 0; 299 int delete_finished = 0;
300 DefaultServerBoundCertStore store(persistent_store.get()); 300 DefaultChannelIDStore store(persistent_store.get());
301 301
302 store.GetAllServerBoundCerts(base::Bind(GetAllCallback, &pre_certs)); 302 store.GetAllChannelIDs(base::Bind(GetAllCallback, &pre_certs));
303 store.DeleteAll(base::Bind(&CallCounter, &delete_finished)); 303 store.DeleteAll(base::Bind(&CallCounter, &delete_finished));
304 store.GetAllServerBoundCerts(base::Bind(GetAllCallback, &post_certs)); 304 store.GetAllChannelIDs(base::Bind(GetAllCallback, &post_certs));
305 // Tasks have not run yet. 305 // Tasks have not run yet.
306 EXPECT_EQ(0u, pre_certs.size()); 306 EXPECT_EQ(0u, pre_certs.size());
307 // Wait for load & queued tasks. 307 // Wait for load & queued tasks.
308 base::MessageLoop::current()->RunUntilIdle(); 308 base::MessageLoop::current()->RunUntilIdle();
309 EXPECT_EQ(0, store.GetCertCount()); 309 EXPECT_EQ(0, store.GetCertCount());
310 EXPECT_EQ(2u, pre_certs.size()); 310 EXPECT_EQ(2u, pre_certs.size());
311 EXPECT_EQ(0u, post_certs.size()); 311 EXPECT_EQ(0u, post_certs.size());
312 } 312 }
313 313
314 TEST(DefaultServerBoundCertStoreTest, TestDelete) { 314 TEST(DefaultChannelIDStoreTest, TestDelete) {
315 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); 315 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore);
316 DefaultServerBoundCertStore store(persistent_store.get()); 316 DefaultChannelIDStore store(persistent_store.get());
317 317
318 base::Time expiration_time; 318 base::Time expiration_time;
319 std::string private_key, cert; 319 std::string private_key, cert;
320 EXPECT_EQ(0, store.GetCertCount()); 320 EXPECT_EQ(0, store.GetCertCount());
321 store.SetServerBoundCert( 321 store.SetChannelID(
322 "verisign.com", 322 "verisign.com",
323 base::Time(), 323 base::Time(),
324 base::Time(), 324 base::Time(),
325 "a", "b"); 325 "a", "b");
326 // Wait for load & queued set task. 326 // Wait for load & queued set task.
327 base::MessageLoop::current()->RunUntilIdle(); 327 base::MessageLoop::current()->RunUntilIdle();
328 328
329 store.SetServerBoundCert( 329 store.SetChannelID(
330 "google.com", 330 "google.com",
331 base::Time(), 331 base::Time(),
332 base::Time(), 332 base::Time(),
333 "c", "d"); 333 "c", "d");
334 334
335 EXPECT_EQ(2, store.GetCertCount()); 335 EXPECT_EQ(2, store.GetCertCount());
336 int delete_finished = 0; 336 int delete_finished = 0;
337 store.DeleteServerBoundCert("verisign.com", 337 store.DeleteChannelID("verisign.com",
338 base::Bind(&CallCounter, &delete_finished)); 338 base::Bind(&CallCounter, &delete_finished));
339 ASSERT_EQ(1, delete_finished); 339 ASSERT_EQ(1, delete_finished);
340 EXPECT_EQ(1, store.GetCertCount()); 340 EXPECT_EQ(1, store.GetCertCount());
341 EXPECT_EQ(ERR_FILE_NOT_FOUND, 341 EXPECT_EQ(ERR_FILE_NOT_FOUND,
342 store.GetServerBoundCert("verisign.com", 342 store.GetChannelID("verisign.com",
343 &expiration_time, 343 &expiration_time,
344 &private_key, 344 &private_key,
345 &cert, 345 &cert,
346 base::Bind(&GetCertCallbackNotCalled))); 346 base::Bind(&GetCertCallbackNotCalled)));
347 EXPECT_EQ(OK, 347 EXPECT_EQ(OK,
348 store.GetServerBoundCert("google.com", 348 store.GetChannelID("google.com",
349 &expiration_time, 349 &expiration_time,
350 &private_key, 350 &private_key,
351 &cert, 351 &cert,
352 base::Bind(&GetCertCallbackNotCalled))); 352 base::Bind(&GetCertCallbackNotCalled)));
353 int delete2_finished = 0; 353 int delete2_finished = 0;
354 store.DeleteServerBoundCert("google.com", 354 store.DeleteChannelID("google.com",
355 base::Bind(&CallCounter, &delete2_finished)); 355 base::Bind(&CallCounter, &delete2_finished));
356 ASSERT_EQ(1, delete2_finished); 356 ASSERT_EQ(1, delete2_finished);
357 EXPECT_EQ(0, store.GetCertCount()); 357 EXPECT_EQ(0, store.GetCertCount());
358 EXPECT_EQ(ERR_FILE_NOT_FOUND, 358 EXPECT_EQ(ERR_FILE_NOT_FOUND,
359 store.GetServerBoundCert("google.com", 359 store.GetChannelID("google.com",
360 &expiration_time, 360 &expiration_time,
361 &private_key, 361 &private_key,
362 &cert, 362 &cert,
363 base::Bind(&GetCertCallbackNotCalled))); 363 base::Bind(&GetCertCallbackNotCalled)));
wtc 2014/07/01 19:50:56 Fix the indentation of the three GetChannelID call
Ryan Hamilton 2014/07/21 19:12:13 Done.
364 } 364 }
365 365
366 TEST(DefaultServerBoundCertStoreTest, TestAsyncDelete) { 366 TEST(DefaultChannelIDStoreTest, TestAsyncDelete) {
367 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); 367 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore);
368 persistent_store->AddServerBoundCert(ServerBoundCertStore::ServerBoundCert( 368 persistent_store->AddChannelID(ChannelIDStore::ChannelID(
369 "a.com", 369 "a.com",
370 base::Time::FromInternalValue(1), 370 base::Time::FromInternalValue(1),
371 base::Time::FromInternalValue(2), 371 base::Time::FromInternalValue(2),
372 "a", "b")); 372 "a", "b"));
373 persistent_store->AddServerBoundCert(ServerBoundCertStore::ServerBoundCert( 373 persistent_store->AddChannelID(ChannelIDStore::ChannelID(
374 "b.com", 374 "b.com",
375 base::Time::FromInternalValue(3), 375 base::Time::FromInternalValue(3),
376 base::Time::FromInternalValue(4), 376 base::Time::FromInternalValue(4),
377 "c", "d")); 377 "c", "d"));
378 DefaultServerBoundCertStore store(persistent_store.get()); 378 DefaultChannelIDStore store(persistent_store.get());
379 int delete_finished = 0; 379 int delete_finished = 0;
380 store.DeleteServerBoundCert("a.com", 380 store.DeleteChannelID("a.com",
381 base::Bind(&CallCounter, &delete_finished)); 381 base::Bind(&CallCounter, &delete_finished));
wtc 2014/07/01 19:50:56 Fix the indentation.
Ryan Hamilton 2014/07/21 19:12:13 Done.
382 382
383 AsyncGetCertHelper a_helper; 383 AsyncGetCertHelper a_helper;
384 AsyncGetCertHelper b_helper; 384 AsyncGetCertHelper b_helper;
385 base::Time expiration_time; 385 base::Time expiration_time;
386 std::string private_key; 386 std::string private_key;
387 std::string cert = "not set"; 387 std::string cert = "not set";
388 EXPECT_EQ(0, store.GetCertCount()); 388 EXPECT_EQ(0, store.GetCertCount());
389 EXPECT_EQ(ERR_IO_PENDING, 389 EXPECT_EQ(ERR_IO_PENDING,
390 store.GetServerBoundCert( 390 store.GetChannelID(
391 "a.com", &expiration_time, &private_key, &cert, 391 "a.com", &expiration_time, &private_key, &cert,
392 base::Bind(&AsyncGetCertHelper::Callback, 392 base::Bind(&AsyncGetCertHelper::Callback,
393 base::Unretained(&a_helper)))); 393 base::Unretained(&a_helper))));
394 EXPECT_EQ(ERR_IO_PENDING, 394 EXPECT_EQ(ERR_IO_PENDING,
395 store.GetServerBoundCert( 395 store.GetChannelID(
396 "b.com", &expiration_time, &private_key, &cert, 396 "b.com", &expiration_time, &private_key, &cert,
397 base::Bind(&AsyncGetCertHelper::Callback, 397 base::Bind(&AsyncGetCertHelper::Callback,
398 base::Unretained(&b_helper)))); 398 base::Unretained(&b_helper))));
399 399
400 EXPECT_EQ(0, delete_finished); 400 EXPECT_EQ(0, delete_finished);
401 EXPECT_FALSE(a_helper.called_); 401 EXPECT_FALSE(a_helper.called_);
402 EXPECT_FALSE(b_helper.called_); 402 EXPECT_FALSE(b_helper.called_);
403 // Wait for load & queued tasks. 403 // Wait for load & queued tasks.
404 base::MessageLoop::current()->RunUntilIdle(); 404 base::MessageLoop::current()->RunUntilIdle();
405 EXPECT_EQ(1, delete_finished); 405 EXPECT_EQ(1, delete_finished);
406 EXPECT_EQ(1, store.GetCertCount()); 406 EXPECT_EQ(1, store.GetCertCount());
407 EXPECT_EQ("not set", cert); 407 EXPECT_EQ("not set", cert);
408 EXPECT_TRUE(a_helper.called_); 408 EXPECT_TRUE(a_helper.called_);
409 EXPECT_EQ(ERR_FILE_NOT_FOUND, a_helper.err_); 409 EXPECT_EQ(ERR_FILE_NOT_FOUND, a_helper.err_);
410 EXPECT_EQ("a.com", a_helper.server_identifier_); 410 EXPECT_EQ("a.com", a_helper.server_identifier_);
411 EXPECT_EQ(0, a_helper.expiration_time_.ToInternalValue()); 411 EXPECT_EQ(0, a_helper.expiration_time_.ToInternalValue());
412 EXPECT_EQ("", a_helper.private_key_); 412 EXPECT_EQ("", a_helper.private_key_);
413 EXPECT_EQ("", a_helper.cert_); 413 EXPECT_EQ("", a_helper.cert_);
414 EXPECT_TRUE(b_helper.called_); 414 EXPECT_TRUE(b_helper.called_);
415 EXPECT_EQ(OK, b_helper.err_); 415 EXPECT_EQ(OK, b_helper.err_);
416 EXPECT_EQ("b.com", b_helper.server_identifier_); 416 EXPECT_EQ("b.com", b_helper.server_identifier_);
417 EXPECT_EQ(4, b_helper.expiration_time_.ToInternalValue()); 417 EXPECT_EQ(4, b_helper.expiration_time_.ToInternalValue());
418 EXPECT_EQ("c", b_helper.private_key_); 418 EXPECT_EQ("c", b_helper.private_key_);
419 EXPECT_EQ("d", b_helper.cert_); 419 EXPECT_EQ("d", b_helper.cert_);
420 } 420 }
421 421
422 TEST(DefaultServerBoundCertStoreTest, TestGetAll) { 422 TEST(DefaultChannelIDStoreTest, TestGetAll) {
423 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); 423 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore);
424 DefaultServerBoundCertStore store(persistent_store.get()); 424 DefaultChannelIDStore store(persistent_store.get());
425 425
426 EXPECT_EQ(0, store.GetCertCount()); 426 EXPECT_EQ(0, store.GetCertCount());
427 store.SetServerBoundCert( 427 store.SetChannelID(
428 "verisign.com", 428 "verisign.com",
429 base::Time(), 429 base::Time(),
430 base::Time(), 430 base::Time(),
431 "a", "b"); 431 "a", "b");
432 store.SetServerBoundCert( 432 store.SetChannelID(
433 "google.com", 433 "google.com",
434 base::Time(), 434 base::Time(),
435 base::Time(), 435 base::Time(),
436 "c", "d"); 436 "c", "d");
437 store.SetServerBoundCert( 437 store.SetChannelID(
438 "harvard.com", 438 "harvard.com",
439 base::Time(), 439 base::Time(),
440 base::Time(), 440 base::Time(),
441 "e", "f"); 441 "e", "f");
442 store.SetServerBoundCert( 442 store.SetChannelID(
443 "mit.com", 443 "mit.com",
444 base::Time(), 444 base::Time(),
445 base::Time(), 445 base::Time(),
446 "g", "h"); 446 "g", "h");
447 // Wait for load & queued set tasks. 447 // Wait for load & queued set tasks.
448 base::MessageLoop::current()->RunUntilIdle(); 448 base::MessageLoop::current()->RunUntilIdle();
449 449
450 EXPECT_EQ(4, store.GetCertCount()); 450 EXPECT_EQ(4, store.GetCertCount());
451 ServerBoundCertStore::ServerBoundCertList certs; 451 ChannelIDStore::ChannelIDList certs;
wtc 2014/07/01 19:50:56 certs => channel_ids
Ryan Hamilton 2014/07/21 19:12:13 Done.
452 store.GetAllServerBoundCerts(base::Bind(GetAllCallback, &certs)); 452 store.GetAllChannelIDs(base::Bind(GetAllCallback, &certs));
453 EXPECT_EQ(4u, certs.size()); 453 EXPECT_EQ(4u, certs.size());
454 } 454 }
455 455
456 TEST(DefaultServerBoundCertStoreTest, TestInitializeFrom) { 456 TEST(DefaultChannelIDStoreTest, TestInitializeFrom) {
457 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); 457 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore);
458 DefaultServerBoundCertStore store(persistent_store.get()); 458 DefaultChannelIDStore store(persistent_store.get());
459 459
460 store.SetServerBoundCert( 460 store.SetChannelID(
461 "preexisting.com", 461 "preexisting.com",
462 base::Time(), 462 base::Time(),
463 base::Time(), 463 base::Time(),
464 "a", "b"); 464 "a", "b");
465 store.SetServerBoundCert( 465 store.SetChannelID(
466 "both.com", 466 "both.com",
467 base::Time(), 467 base::Time(),
468 base::Time(), 468 base::Time(),
469 "c", "d"); 469 "c", "d");
470 // Wait for load & queued set tasks. 470 // Wait for load & queued set tasks.
471 base::MessageLoop::current()->RunUntilIdle(); 471 base::MessageLoop::current()->RunUntilIdle();
472 EXPECT_EQ(2, store.GetCertCount()); 472 EXPECT_EQ(2, store.GetCertCount());
473 473
474 ServerBoundCertStore::ServerBoundCertList source_certs; 474 ChannelIDStore::ChannelIDList source_certs;
wtc 2014/07/01 19:50:56 source_certs => source_channel_ids
Ryan Hamilton 2014/07/21 19:12:13 Done.
475 source_certs.push_back(ServerBoundCertStore::ServerBoundCert( 475 source_certs.push_back(ChannelIDStore::ChannelID(
476 "both.com", 476 "both.com",
477 base::Time(), 477 base::Time(),
478 base::Time(), 478 base::Time(),
479 // Key differs from above to test that existing entries are overwritten. 479 // Key differs from above to test that existing entries are overwritten.
480 "e", "f")); 480 "e", "f"));
481 source_certs.push_back(ServerBoundCertStore::ServerBoundCert( 481 source_certs.push_back(ChannelIDStore::ChannelID(
482 "copied.com", 482 "copied.com",
483 base::Time(), 483 base::Time(),
484 base::Time(), 484 base::Time(),
485 "g", "h")); 485 "g", "h"));
486 store.InitializeFrom(source_certs); 486 store.InitializeFrom(source_certs);
487 EXPECT_EQ(3, store.GetCertCount()); 487 EXPECT_EQ(3, store.GetCertCount());
488 488
489 ServerBoundCertStore::ServerBoundCertList certs; 489 ChannelIDStore::ChannelIDList certs;
wtc 2014/07/01 19:50:56 certs => channel_ids
Ryan Hamilton 2014/07/21 19:12:13 Done.
490 store.GetAllServerBoundCerts(base::Bind(GetAllCallback, &certs)); 490 store.GetAllChannelIDs(base::Bind(GetAllCallback, &certs));
491 ASSERT_EQ(3u, certs.size()); 491 ASSERT_EQ(3u, certs.size());
492 492
493 ServerBoundCertStore::ServerBoundCertList::iterator cert = certs.begin(); 493 ChannelIDStore::ChannelIDList::iterator cert = certs.begin();
wtc 2014/07/01 19:50:56 cert => channel_id If you decide to rename these
Ryan Hamilton 2014/07/21 19:12:12 Done.
494 EXPECT_EQ("both.com", cert->server_identifier()); 494 EXPECT_EQ("both.com", cert->server_identifier());
495 EXPECT_EQ("e", cert->private_key()); 495 EXPECT_EQ("e", cert->private_key());
496 496
497 ++cert; 497 ++cert;
498 EXPECT_EQ("copied.com", cert->server_identifier()); 498 EXPECT_EQ("copied.com", cert->server_identifier());
499 EXPECT_EQ("g", cert->private_key()); 499 EXPECT_EQ("g", cert->private_key());
500 500
501 ++cert; 501 ++cert;
502 EXPECT_EQ("preexisting.com", cert->server_identifier()); 502 EXPECT_EQ("preexisting.com", cert->server_identifier());
503 EXPECT_EQ("a", cert->private_key()); 503 EXPECT_EQ("a", cert->private_key());
504 } 504 }
505 505
506 TEST(DefaultServerBoundCertStoreTest, TestAsyncInitializeFrom) { 506 TEST(DefaultChannelIDStoreTest, TestAsyncInitializeFrom) {
507 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore); 507 scoped_refptr<MockPersistentStore> persistent_store(new MockPersistentStore);
508 persistent_store->AddServerBoundCert(ServerBoundCertStore::ServerBoundCert( 508 persistent_store->AddChannelID(ChannelIDStore::ChannelID(
509 "preexisting.com", 509 "preexisting.com",
510 base::Time(), 510 base::Time(),
511 base::Time(), 511 base::Time(),
512 "a", "b")); 512 "a", "b"));
513 persistent_store->AddServerBoundCert(ServerBoundCertStore::ServerBoundCert( 513 persistent_store->AddChannelID(ChannelIDStore::ChannelID(
514 "both.com", 514 "both.com",
515 base::Time(), 515 base::Time(),
516 base::Time(), 516 base::Time(),
517 "c", "d")); 517 "c", "d"));
518 518
519 DefaultServerBoundCertStore store(persistent_store.get()); 519 DefaultChannelIDStore store(persistent_store.get());
520 ServerBoundCertStore::ServerBoundCertList source_certs; 520 ChannelIDStore::ChannelIDList source_certs;
521 source_certs.push_back(ServerBoundCertStore::ServerBoundCert( 521 source_certs.push_back(ChannelIDStore::ChannelID(
522 "both.com", 522 "both.com",
523 base::Time(), 523 base::Time(),
524 base::Time(), 524 base::Time(),
525 // Key differs from above to test that existing entries are overwritten. 525 // Key differs from above to test that existing entries are overwritten.
526 "e", "f")); 526 "e", "f"));
527 source_certs.push_back(ServerBoundCertStore::ServerBoundCert( 527 source_certs.push_back(ChannelIDStore::ChannelID(
528 "copied.com", 528 "copied.com",
529 base::Time(), 529 base::Time(),
530 base::Time(), 530 base::Time(),
531 "g", "h")); 531 "g", "h"));
532 store.InitializeFrom(source_certs); 532 store.InitializeFrom(source_certs);
533 EXPECT_EQ(0, store.GetCertCount()); 533 EXPECT_EQ(0, store.GetCertCount());
534 // Wait for load & queued tasks. 534 // Wait for load & queued tasks.
535 base::MessageLoop::current()->RunUntilIdle(); 535 base::MessageLoop::current()->RunUntilIdle();
536 EXPECT_EQ(3, store.GetCertCount()); 536 EXPECT_EQ(3, store.GetCertCount());
537 537
538 ServerBoundCertStore::ServerBoundCertList certs; 538 ChannelIDStore::ChannelIDList certs;
539 store.GetAllServerBoundCerts(base::Bind(GetAllCallback, &certs)); 539 store.GetAllChannelIDs(base::Bind(GetAllCallback, &certs));
540 ASSERT_EQ(3u, certs.size()); 540 ASSERT_EQ(3u, certs.size());
541 541
542 ServerBoundCertStore::ServerBoundCertList::iterator cert = certs.begin(); 542 ChannelIDStore::ChannelIDList::iterator cert = certs.begin();
543 EXPECT_EQ("both.com", cert->server_identifier()); 543 EXPECT_EQ("both.com", cert->server_identifier());
544 EXPECT_EQ("e", cert->private_key()); 544 EXPECT_EQ("e", cert->private_key());
545 545
546 ++cert; 546 ++cert;
547 EXPECT_EQ("copied.com", cert->server_identifier()); 547 EXPECT_EQ("copied.com", cert->server_identifier());
548 EXPECT_EQ("g", cert->private_key()); 548 EXPECT_EQ("g", cert->private_key());
549 549
550 ++cert; 550 ++cert;
551 EXPECT_EQ("preexisting.com", cert->server_identifier()); 551 EXPECT_EQ("preexisting.com", cert->server_identifier());
552 EXPECT_EQ("a", cert->private_key()); 552 EXPECT_EQ("a", cert->private_key());
553 } 553 }
554 554
555 } // namespace net 555 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698