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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 db_thread_.Start(); | 61 db_thread_.Start(); |
62 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 62 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
63 store_ = new SQLiteOriginBoundCertStore( | 63 store_ = new SQLiteOriginBoundCertStore( |
64 temp_dir_.path().Append(chrome::kOBCertFilename)); | 64 temp_dir_.path().Append(chrome::kOBCertFilename)); |
65 ScopedVector<net::DefaultOriginBoundCertStore::OriginBoundCert> certs; | 65 ScopedVector<net::DefaultOriginBoundCertStore::OriginBoundCert> certs; |
66 ASSERT_TRUE(store_->Load(&certs.get())); | 66 ASSERT_TRUE(store_->Load(&certs.get())); |
67 ASSERT_EQ(0u, certs.size()); | 67 ASSERT_EQ(0u, certs.size()); |
68 // Make sure the store gets written at least once. | 68 // Make sure the store gets written at least once. |
69 store_->AddOriginBoundCert( | 69 store_->AddOriginBoundCert( |
70 net::DefaultOriginBoundCertStore::OriginBoundCert( | 70 net::DefaultOriginBoundCertStore::OriginBoundCert( |
71 "https://encrypted.google.com:8443", | 71 "google.com", |
72 net::CLIENT_CERT_RSA_SIGN, | 72 net::CLIENT_CERT_RSA_SIGN, |
73 base::Time::FromInternalValue(1), | 73 base::Time::FromInternalValue(1), |
74 base::Time::FromInternalValue(2), | 74 base::Time::FromInternalValue(2), |
75 "a", "b")); | 75 "a", "b")); |
76 } | 76 } |
77 | 77 |
78 content::TestBrowserThread db_thread_; | 78 content::TestBrowserThread db_thread_; |
79 ScopedTempDir temp_dir_; | 79 ScopedTempDir temp_dir_; |
80 scoped_refptr<SQLiteOriginBoundCertStore> store_; | 80 scoped_refptr<SQLiteOriginBoundCertStore> store_; |
81 }; | 81 }; |
(...skipping 26 matching lines...) Expand all Loading... |
108 ASSERT_TRUE(helper->Run()); | 108 ASSERT_TRUE(helper->Run()); |
109 | 109 |
110 ASSERT_FALSE(file_util::PathExists( | 110 ASSERT_FALSE(file_util::PathExists( |
111 temp_dir_.path().Append(chrome::kOBCertFilename))); | 111 temp_dir_.path().Append(chrome::kOBCertFilename))); |
112 } | 112 } |
113 | 113 |
114 // Test if data is stored as expected in the SQLite database. | 114 // Test if data is stored as expected in the SQLite database. |
115 TEST_F(SQLiteOriginBoundCertStoreTest, TestPersistence) { | 115 TEST_F(SQLiteOriginBoundCertStoreTest, TestPersistence) { |
116 store_->AddOriginBoundCert( | 116 store_->AddOriginBoundCert( |
117 net::DefaultOriginBoundCertStore::OriginBoundCert( | 117 net::DefaultOriginBoundCertStore::OriginBoundCert( |
118 "https://www.google.com/", | 118 "foo.com", |
119 net::CLIENT_CERT_ECDSA_SIGN, | 119 net::CLIENT_CERT_ECDSA_SIGN, |
120 base::Time::FromInternalValue(3), | 120 base::Time::FromInternalValue(3), |
121 base::Time::FromInternalValue(4), | 121 base::Time::FromInternalValue(4), |
122 "c", "d")); | 122 "c", "d")); |
123 | 123 |
124 ScopedVector<net::DefaultOriginBoundCertStore::OriginBoundCert> certs; | 124 ScopedVector<net::DefaultOriginBoundCertStore::OriginBoundCert> certs; |
125 // Replace the store effectively destroying the current one and forcing it | 125 // Replace the store effectively destroying the current one and forcing it |
126 // to write it's data to disk. Then we can see if after loading it again it | 126 // to write it's data to disk. Then we can see if after loading it again it |
127 // is still there. | 127 // is still there. |
128 store_ = NULL; | 128 store_ = NULL; |
(...skipping 10 matching lines...) Expand all Loading... |
139 ASSERT_EQ(2U, certs.size()); | 139 ASSERT_EQ(2U, certs.size()); |
140 net::DefaultOriginBoundCertStore::OriginBoundCert* ec_cert; | 140 net::DefaultOriginBoundCertStore::OriginBoundCert* ec_cert; |
141 net::DefaultOriginBoundCertStore::OriginBoundCert* rsa_cert; | 141 net::DefaultOriginBoundCertStore::OriginBoundCert* rsa_cert; |
142 if (net::CLIENT_CERT_RSA_SIGN == certs[0]->type()) { | 142 if (net::CLIENT_CERT_RSA_SIGN == certs[0]->type()) { |
143 rsa_cert = certs[0]; | 143 rsa_cert = certs[0]; |
144 ec_cert = certs[1]; | 144 ec_cert = certs[1]; |
145 } else { | 145 } else { |
146 rsa_cert = certs[1]; | 146 rsa_cert = certs[1]; |
147 ec_cert = certs[0]; | 147 ec_cert = certs[0]; |
148 } | 148 } |
149 ASSERT_STREQ("https://encrypted.google.com:8443", rsa_cert->origin().c_str()); | 149 ASSERT_STREQ("google.com", rsa_cert->domain().c_str()); |
150 ASSERT_EQ(net::CLIENT_CERT_RSA_SIGN, rsa_cert->type()); | 150 ASSERT_EQ(net::CLIENT_CERT_RSA_SIGN, rsa_cert->type()); |
151 ASSERT_STREQ("a", rsa_cert->private_key().c_str()); | 151 ASSERT_STREQ("a", rsa_cert->private_key().c_str()); |
152 ASSERT_STREQ("b", rsa_cert->cert().c_str()); | 152 ASSERT_STREQ("b", rsa_cert->cert().c_str()); |
153 ASSERT_EQ(1, rsa_cert->creation_time().ToInternalValue()); | 153 ASSERT_EQ(1, rsa_cert->creation_time().ToInternalValue()); |
154 ASSERT_EQ(2, rsa_cert->expiration_time().ToInternalValue()); | 154 ASSERT_EQ(2, rsa_cert->expiration_time().ToInternalValue()); |
155 ASSERT_STREQ("https://www.google.com/", ec_cert->origin().c_str()); | 155 ASSERT_STREQ("foo.com", ec_cert->domain().c_str()); |
156 ASSERT_EQ(net::CLIENT_CERT_ECDSA_SIGN, ec_cert->type()); | 156 ASSERT_EQ(net::CLIENT_CERT_ECDSA_SIGN, ec_cert->type()); |
157 ASSERT_STREQ("c", ec_cert->private_key().c_str()); | 157 ASSERT_STREQ("c", ec_cert->private_key().c_str()); |
158 ASSERT_STREQ("d", ec_cert->cert().c_str()); | 158 ASSERT_STREQ("d", ec_cert->cert().c_str()); |
159 ASSERT_EQ(3, ec_cert->creation_time().ToInternalValue()); | 159 ASSERT_EQ(3, ec_cert->creation_time().ToInternalValue()); |
160 ASSERT_EQ(4, ec_cert->expiration_time().ToInternalValue()); | 160 ASSERT_EQ(4, ec_cert->expiration_time().ToInternalValue()); |
161 | 161 |
162 // Now delete the cert and check persistence again. | 162 // Now delete the cert and check persistence again. |
163 store_->DeleteOriginBoundCert(*certs[0]); | 163 store_->DeleteOriginBoundCert(*certs[0]); |
164 store_->DeleteOriginBoundCert(*certs[1]); | 164 store_->DeleteOriginBoundCert(*certs[1]); |
165 store_ = NULL; | 165 store_ = NULL; |
(...skipping 27 matching lines...) Expand all Loading... |
193 "value LONGVARCHAR);" | 193 "value LONGVARCHAR);" |
194 "INSERT INTO \"meta\" VALUES('version','1');" | 194 "INSERT INTO \"meta\" VALUES('version','1');" |
195 "INSERT INTO \"meta\" VALUES('last_compatible_version','1');" | 195 "INSERT INTO \"meta\" VALUES('last_compatible_version','1');" |
196 "CREATE TABLE origin_bound_certs (" | 196 "CREATE TABLE origin_bound_certs (" |
197 "origin TEXT NOT NULL UNIQUE PRIMARY KEY," | 197 "origin TEXT NOT NULL UNIQUE PRIMARY KEY," |
198 "private_key BLOB NOT NULL,cert BLOB NOT NULL);")); | 198 "private_key BLOB NOT NULL,cert BLOB NOT NULL);")); |
199 | 199 |
200 sql::Statement add_smt(db.GetUniqueStatement( | 200 sql::Statement add_smt(db.GetUniqueStatement( |
201 "INSERT INTO origin_bound_certs (origin, private_key, cert) " | 201 "INSERT INTO origin_bound_certs (origin, private_key, cert) " |
202 "VALUES (?,?,?)")); | 202 "VALUES (?,?,?)")); |
203 add_smt.BindString(0, "https://www.google.com:443"); | 203 add_smt.BindString(0, "google.com"); |
204 add_smt.BindBlob(1, key_data.data(), key_data.size()); | 204 add_smt.BindBlob(1, key_data.data(), key_data.size()); |
205 add_smt.BindBlob(2, cert_data.data(), cert_data.size()); | 205 add_smt.BindBlob(2, cert_data.data(), cert_data.size()); |
206 ASSERT_TRUE(add_smt.Run()); | 206 ASSERT_TRUE(add_smt.Run()); |
207 | 207 |
208 ASSERT_TRUE(db.Execute( | 208 ASSERT_TRUE(db.Execute( |
209 "INSERT INTO \"origin_bound_certs\" VALUES(" | 209 "INSERT INTO \"origin_bound_certs\" VALUES(" |
210 "'https://foo.com',X'AA',X'BB');" | 210 "'foo.com',X'AA',X'BB');" |
211 )); | 211 )); |
212 } | 212 } |
213 | 213 |
214 // Load and test the DB contents twice. First time ensures that we can use | 214 // Load and test the DB contents twice. First time ensures that we can use |
215 // the updated values immediately. Second time ensures that the updated | 215 // the updated values immediately. Second time ensures that the updated |
216 // values are stored and read correctly on next load. | 216 // values are stored and read correctly on next load. |
217 for (int i = 0; i < 2; ++i) { | 217 for (int i = 0; i < 2; ++i) { |
218 SCOPED_TRACE(i); | 218 SCOPED_TRACE(i); |
219 | 219 |
220 ScopedVector<net::DefaultOriginBoundCertStore::OriginBoundCert> certs; | 220 ScopedVector<net::DefaultOriginBoundCertStore::OriginBoundCert> certs; |
221 store_ = new SQLiteOriginBoundCertStore(v1_db_path); | 221 store_ = new SQLiteOriginBoundCertStore(v1_db_path); |
222 | 222 |
223 // Load the database and ensure the certs can be read and are marked as RSA. | 223 // Load the database and ensure the certs can be read and are marked as RSA. |
224 ASSERT_TRUE(store_->Load(&certs.get())); | 224 ASSERT_TRUE(store_->Load(&certs.get())); |
225 ASSERT_EQ(2U, certs.size()); | 225 ASSERT_EQ(2U, certs.size()); |
226 | 226 |
227 ASSERT_STREQ("https://www.google.com:443", certs[0]->origin().c_str()); | 227 ASSERT_STREQ("google.com", certs[0]->domain().c_str()); |
228 ASSERT_EQ(net::CLIENT_CERT_RSA_SIGN, certs[0]->type()); | 228 ASSERT_EQ(net::CLIENT_CERT_RSA_SIGN, certs[0]->type()); |
229 ASSERT_EQ(GetTestCertExpirationTime(), | 229 ASSERT_EQ(GetTestCertExpirationTime(), |
230 certs[0]->expiration_time()); | 230 certs[0]->expiration_time()); |
231 ASSERT_EQ(key_data, certs[0]->private_key()); | 231 ASSERT_EQ(key_data, certs[0]->private_key()); |
232 ASSERT_EQ(cert_data, certs[0]->cert()); | 232 ASSERT_EQ(cert_data, certs[0]->cert()); |
233 | 233 |
234 ASSERT_STREQ("https://foo.com", certs[1]->origin().c_str()); | 234 ASSERT_STREQ("foo.com", certs[1]->domain().c_str()); |
235 ASSERT_EQ(net::CLIENT_CERT_RSA_SIGN, certs[1]->type()); | 235 ASSERT_EQ(net::CLIENT_CERT_RSA_SIGN, certs[1]->type()); |
236 // Undecodable cert, expiration time will be uninitialized. | 236 // Undecodable cert, expiration time will be uninitialized. |
237 ASSERT_EQ(base::Time(), certs[1]->expiration_time()); | 237 ASSERT_EQ(base::Time(), certs[1]->expiration_time()); |
238 ASSERT_STREQ("\xaa", certs[1]->private_key().c_str()); | 238 ASSERT_STREQ("\xaa", certs[1]->private_key().c_str()); |
239 ASSERT_STREQ("\xbb", certs[1]->cert().c_str()); | 239 ASSERT_STREQ("\xbb", certs[1]->cert().c_str()); |
240 | 240 |
241 store_ = NULL; | 241 store_ = NULL; |
242 // Make sure we wait until the destructor has run. | 242 // Make sure we wait until the destructor has run. |
243 scoped_refptr<base::ThreadTestHelper> helper( | 243 scoped_refptr<base::ThreadTestHelper> helper( |
244 new base::ThreadTestHelper( | 244 new base::ThreadTestHelper( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 "CREATE TABLE origin_bound_certs (" | 280 "CREATE TABLE origin_bound_certs (" |
281 "origin TEXT NOT NULL UNIQUE PRIMARY KEY," | 281 "origin TEXT NOT NULL UNIQUE PRIMARY KEY," |
282 "private_key BLOB NOT NULL," | 282 "private_key BLOB NOT NULL," |
283 "cert BLOB NOT NULL," | 283 "cert BLOB NOT NULL," |
284 "cert_type INTEGER);" | 284 "cert_type INTEGER);" |
285 )); | 285 )); |
286 | 286 |
287 sql::Statement add_smt(db.GetUniqueStatement( | 287 sql::Statement add_smt(db.GetUniqueStatement( |
288 "INSERT INTO origin_bound_certs (origin, private_key, cert, cert_type) " | 288 "INSERT INTO origin_bound_certs (origin, private_key, cert, cert_type) " |
289 "VALUES (?,?,?,?)")); | 289 "VALUES (?,?,?,?)")); |
290 add_smt.BindString(0, "https://www.google.com:443"); | 290 add_smt.BindString(0, "google.com"); |
291 add_smt.BindBlob(1, key_data.data(), key_data.size()); | 291 add_smt.BindBlob(1, key_data.data(), key_data.size()); |
292 add_smt.BindBlob(2, cert_data.data(), cert_data.size()); | 292 add_smt.BindBlob(2, cert_data.data(), cert_data.size()); |
293 add_smt.BindInt64(3, 1); | 293 add_smt.BindInt64(3, 1); |
294 ASSERT_TRUE(add_smt.Run()); | 294 ASSERT_TRUE(add_smt.Run()); |
295 | 295 |
296 ASSERT_TRUE(db.Execute( | 296 ASSERT_TRUE(db.Execute( |
297 "INSERT INTO \"origin_bound_certs\" VALUES(" | 297 "INSERT INTO \"origin_bound_certs\" VALUES(" |
298 "'https://foo.com',X'AA',X'BB',64);" | 298 "'foo.com',X'AA',X'BB',64);" |
299 )); | 299 )); |
300 } | 300 } |
301 | 301 |
302 // Load and test the DB contents twice. First time ensures that we can use | 302 // Load and test the DB contents twice. First time ensures that we can use |
303 // the updated values immediately. Second time ensures that the updated | 303 // the updated values immediately. Second time ensures that the updated |
304 // values are saved and read correctly on next load. | 304 // values are saved and read correctly on next load. |
305 for (int i = 0; i < 2; ++i) { | 305 for (int i = 0; i < 2; ++i) { |
306 SCOPED_TRACE(i); | 306 SCOPED_TRACE(i); |
307 | 307 |
308 ScopedVector<net::DefaultOriginBoundCertStore::OriginBoundCert> certs; | 308 ScopedVector<net::DefaultOriginBoundCertStore::OriginBoundCert> certs; |
309 store_ = new SQLiteOriginBoundCertStore(v2_db_path); | 309 store_ = new SQLiteOriginBoundCertStore(v2_db_path); |
310 | 310 |
311 // Load the database and ensure the certs can be read and are marked as RSA. | 311 // Load the database and ensure the certs can be read and are marked as RSA. |
312 ASSERT_TRUE(store_->Load(&certs.get())); | 312 ASSERT_TRUE(store_->Load(&certs.get())); |
313 ASSERT_EQ(2U, certs.size()); | 313 ASSERT_EQ(2U, certs.size()); |
314 | 314 |
315 ASSERT_STREQ("https://www.google.com:443", certs[0]->origin().c_str()); | 315 ASSERT_STREQ("google.com", certs[0]->domain().c_str()); |
316 ASSERT_EQ(net::CLIENT_CERT_RSA_SIGN, certs[0]->type()); | 316 ASSERT_EQ(net::CLIENT_CERT_RSA_SIGN, certs[0]->type()); |
317 ASSERT_EQ(GetTestCertExpirationTime(), | 317 ASSERT_EQ(GetTestCertExpirationTime(), |
318 certs[0]->expiration_time()); | 318 certs[0]->expiration_time()); |
319 ASSERT_EQ(key_data, certs[0]->private_key()); | 319 ASSERT_EQ(key_data, certs[0]->private_key()); |
320 ASSERT_EQ(cert_data, certs[0]->cert()); | 320 ASSERT_EQ(cert_data, certs[0]->cert()); |
321 | 321 |
322 ASSERT_STREQ("https://foo.com", certs[1]->origin().c_str()); | 322 ASSERT_STREQ("foo.com", certs[1]->domain().c_str()); |
323 ASSERT_EQ(net::CLIENT_CERT_ECDSA_SIGN, certs[1]->type()); | 323 ASSERT_EQ(net::CLIENT_CERT_ECDSA_SIGN, certs[1]->type()); |
324 // Undecodable cert, expiration time will be uninitialized. | 324 // Undecodable cert, expiration time will be uninitialized. |
325 ASSERT_EQ(base::Time(), certs[1]->expiration_time()); | 325 ASSERT_EQ(base::Time(), certs[1]->expiration_time()); |
326 ASSERT_STREQ("\xaa", certs[1]->private_key().c_str()); | 326 ASSERT_STREQ("\xaa", certs[1]->private_key().c_str()); |
327 ASSERT_STREQ("\xbb", certs[1]->cert().c_str()); | 327 ASSERT_STREQ("\xbb", certs[1]->cert().c_str()); |
328 | 328 |
329 store_ = NULL; | 329 store_ = NULL; |
330 // Make sure we wait until the destructor has run. | 330 // Make sure we wait until the destructor has run. |
331 scoped_refptr<base::ThreadTestHelper> helper( | 331 scoped_refptr<base::ThreadTestHelper> helper( |
332 new base::ThreadTestHelper( | 332 new base::ThreadTestHelper( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 "origin TEXT NOT NULL UNIQUE PRIMARY KEY," | 369 "origin TEXT NOT NULL UNIQUE PRIMARY KEY," |
370 "private_key BLOB NOT NULL," | 370 "private_key BLOB NOT NULL," |
371 "cert BLOB NOT NULL," | 371 "cert BLOB NOT NULL," |
372 "cert_type INTEGER," | 372 "cert_type INTEGER," |
373 "expiration_time INTEGER);" | 373 "expiration_time INTEGER);" |
374 )); | 374 )); |
375 | 375 |
376 sql::Statement add_smt(db.GetUniqueStatement( | 376 sql::Statement add_smt(db.GetUniqueStatement( |
377 "INSERT INTO origin_bound_certs (origin, private_key, cert, cert_type, " | 377 "INSERT INTO origin_bound_certs (origin, private_key, cert, cert_type, " |
378 "expiration_time) VALUES (?,?,?,?,?)")); | 378 "expiration_time) VALUES (?,?,?,?,?)")); |
379 add_smt.BindString(0, "https://www.google.com:443"); | 379 add_smt.BindString(0, "google.com"); |
380 add_smt.BindBlob(1, key_data.data(), key_data.size()); | 380 add_smt.BindBlob(1, key_data.data(), key_data.size()); |
381 add_smt.BindBlob(2, cert_data.data(), cert_data.size()); | 381 add_smt.BindBlob(2, cert_data.data(), cert_data.size()); |
382 add_smt.BindInt64(3, 1); | 382 add_smt.BindInt64(3, 1); |
383 add_smt.BindInt64(4, 1000); | 383 add_smt.BindInt64(4, 1000); |
384 ASSERT_TRUE(add_smt.Run()); | 384 ASSERT_TRUE(add_smt.Run()); |
385 | 385 |
386 ASSERT_TRUE(db.Execute( | 386 ASSERT_TRUE(db.Execute( |
387 "INSERT INTO \"origin_bound_certs\" VALUES(" | 387 "INSERT INTO \"origin_bound_certs\" VALUES(" |
388 "'https://foo.com',X'AA',X'BB',64,2000);" | 388 "'foo.com',X'AA',X'BB',64,2000);" |
389 )); | 389 )); |
390 } | 390 } |
391 | 391 |
392 // Load and test the DB contents twice. First time ensures that we can use | 392 // Load and test the DB contents twice. First time ensures that we can use |
393 // the updated values immediately. Second time ensures that the updated | 393 // the updated values immediately. Second time ensures that the updated |
394 // values are saved and read correctly on next load. | 394 // values are saved and read correctly on next load. |
395 for (int i = 0; i < 2; ++i) { | 395 for (int i = 0; i < 2; ++i) { |
396 SCOPED_TRACE(i); | 396 SCOPED_TRACE(i); |
397 | 397 |
398 ScopedVector<net::DefaultOriginBoundCertStore::OriginBoundCert> certs; | 398 ScopedVector<net::DefaultOriginBoundCertStore::OriginBoundCert> certs; |
399 store_ = new SQLiteOriginBoundCertStore(v3_db_path); | 399 store_ = new SQLiteOriginBoundCertStore(v3_db_path); |
400 | 400 |
401 // Load the database and ensure the certs can be read and are marked as RSA. | 401 // Load the database and ensure the certs can be read and are marked as RSA. |
402 ASSERT_TRUE(store_->Load(&certs.get())); | 402 ASSERT_TRUE(store_->Load(&certs.get())); |
403 ASSERT_EQ(2U, certs.size()); | 403 ASSERT_EQ(2U, certs.size()); |
404 | 404 |
405 ASSERT_STREQ("https://www.google.com:443", certs[0]->origin().c_str()); | 405 ASSERT_STREQ("google.com", certs[0]->domain().c_str()); |
406 ASSERT_EQ(net::CLIENT_CERT_RSA_SIGN, certs[0]->type()); | 406 ASSERT_EQ(net::CLIENT_CERT_RSA_SIGN, certs[0]->type()); |
407 ASSERT_EQ(1000, certs[0]->expiration_time().ToInternalValue()); | 407 ASSERT_EQ(1000, certs[0]->expiration_time().ToInternalValue()); |
408 ASSERT_EQ(GetTestCertCreationTime(), | 408 ASSERT_EQ(GetTestCertCreationTime(), |
409 certs[0]->creation_time()); | 409 certs[0]->creation_time()); |
410 ASSERT_EQ(key_data, certs[0]->private_key()); | 410 ASSERT_EQ(key_data, certs[0]->private_key()); |
411 ASSERT_EQ(cert_data, certs[0]->cert()); | 411 ASSERT_EQ(cert_data, certs[0]->cert()); |
412 | 412 |
413 ASSERT_STREQ("https://foo.com", certs[1]->origin().c_str()); | 413 ASSERT_STREQ("foo.com", certs[1]->domain().c_str()); |
414 ASSERT_EQ(net::CLIENT_CERT_ECDSA_SIGN, certs[1]->type()); | 414 ASSERT_EQ(net::CLIENT_CERT_ECDSA_SIGN, certs[1]->type()); |
415 ASSERT_EQ(2000, certs[1]->expiration_time().ToInternalValue()); | 415 ASSERT_EQ(2000, certs[1]->expiration_time().ToInternalValue()); |
416 // Undecodable cert, creation time will be uninitialized. | 416 // Undecodable cert, creation time will be uninitialized. |
417 ASSERT_EQ(base::Time(), certs[1]->creation_time()); | 417 ASSERT_EQ(base::Time(), certs[1]->creation_time()); |
418 ASSERT_STREQ("\xaa", certs[1]->private_key().c_str()); | 418 ASSERT_STREQ("\xaa", certs[1]->private_key().c_str()); |
419 ASSERT_STREQ("\xbb", certs[1]->cert().c_str()); | 419 ASSERT_STREQ("\xbb", certs[1]->cert().c_str()); |
420 | 420 |
421 store_ = NULL; | 421 store_ = NULL; |
422 // Make sure we wait until the destructor has run. | 422 // Make sure we wait until the destructor has run. |
423 scoped_refptr<base::ThreadTestHelper> helper( | 423 scoped_refptr<base::ThreadTestHelper> helper( |
(...skipping 18 matching lines...) Expand all Loading... |
442 TEST_F(SQLiteOriginBoundCertStoreTest, TestFlush) { | 442 TEST_F(SQLiteOriginBoundCertStoreTest, TestFlush) { |
443 // File timestamps don't work well on all platforms, so we'll determine | 443 // File timestamps don't work well on all platforms, so we'll determine |
444 // whether the DB file has been modified by checking its size. | 444 // whether the DB file has been modified by checking its size. |
445 FilePath path = temp_dir_.path().Append(chrome::kOBCertFilename); | 445 FilePath path = temp_dir_.path().Append(chrome::kOBCertFilename); |
446 base::PlatformFileInfo info; | 446 base::PlatformFileInfo info; |
447 ASSERT_TRUE(file_util::GetFileInfo(path, &info)); | 447 ASSERT_TRUE(file_util::GetFileInfo(path, &info)); |
448 int64 base_size = info.size; | 448 int64 base_size = info.size; |
449 | 449 |
450 // Write some certs, so the DB will have to expand by several KB. | 450 // Write some certs, so the DB will have to expand by several KB. |
451 for (char c = 'a'; c < 'z'; ++c) { | 451 for (char c = 'a'; c < 'z'; ++c) { |
452 std::string origin(1, c); | 452 std::string domain(1, c); |
453 std::string private_key(1000, c); | 453 std::string private_key(1000, c); |
454 std::string cert(1000, c); | 454 std::string cert(1000, c); |
455 store_->AddOriginBoundCert( | 455 store_->AddOriginBoundCert( |
456 net::DefaultOriginBoundCertStore::OriginBoundCert( | 456 net::DefaultOriginBoundCertStore::OriginBoundCert( |
457 origin, | 457 domain, |
458 net::CLIENT_CERT_RSA_SIGN, | 458 net::CLIENT_CERT_RSA_SIGN, |
459 base::Time(), | 459 base::Time(), |
460 base::Time(), | 460 base::Time(), |
461 private_key, | 461 private_key, |
462 cert)); | 462 cert)); |
463 } | 463 } |
464 | 464 |
465 // Call Flush() and wait until the DB thread is idle. | 465 // Call Flush() and wait until the DB thread is idle. |
466 store_->Flush(base::Closure()); | 466 store_->Flush(base::Closure()); |
467 scoped_refptr<base::ThreadTestHelper> helper( | 467 scoped_refptr<base::ThreadTestHelper> helper( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 | 501 |
502 store_->Flush(base::Bind(&CallbackCounter::Callback, counter.get())); | 502 store_->Flush(base::Bind(&CallbackCounter::Callback, counter.get())); |
503 | 503 |
504 scoped_refptr<base::ThreadTestHelper> helper( | 504 scoped_refptr<base::ThreadTestHelper> helper( |
505 new base::ThreadTestHelper( | 505 new base::ThreadTestHelper( |
506 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); | 506 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); |
507 ASSERT_TRUE(helper->Run()); | 507 ASSERT_TRUE(helper->Run()); |
508 | 508 |
509 ASSERT_EQ(1, counter->callback_count()); | 509 ASSERT_EQ(1, counter->callback_count()); |
510 } | 510 } |
OLD | NEW |