OLD | NEW |
---|---|
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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/disk_based_cert_cache.h" | 5 #include "net/http/disk_based_cert_cache.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "net/base/completion_callback.h" | 9 #include "net/base/completion_callback.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 ScopedMockTransaction trans1( | 261 ScopedMockTransaction trans1( |
262 CreateMockTransaction(kCert1.cache_key, TEST_MODE_NORMAL)); | 262 CreateMockTransaction(kCert1.cache_key, TEST_MODE_NORMAL)); |
263 MockDiskCache backend; | 263 MockDiskCache backend; |
264 ASSERT_NO_FATAL_FAILURE(ImportCert(&backend, kCert1, true /* corrupted */)); | 264 ASSERT_NO_FATAL_FAILURE(ImportCert(&backend, kCert1, true /* corrupted */)); |
265 DiskBasedCertCache cache(&backend); | 265 DiskBasedCertCache cache(&backend); |
266 TestGetCallback get_callback; | 266 TestGetCallback get_callback; |
267 | 267 |
268 cache.Get(kCert1.cache_key, get_callback.callback()); | 268 cache.Get(kCert1.cache_key, get_callback.callback()); |
269 get_callback.WaitForResult(); | 269 get_callback.WaitForResult(); |
270 | 270 |
271 scoped_refptr<X509Certificate> cert( | |
272 ImportCertFromFile(GetTestCertsDirectory(), kCert1.file_name)); | |
273 EXPECT_FALSE(get_callback.cert_handle()); | 271 EXPECT_FALSE(get_callback.cert_handle()); |
274 } | 272 } |
275 | 273 |
276 // Tests that attempting to retrieve a cert that is not in the cache will | 274 // Tests that attempting to retrieve a cert that is not in the cache will |
277 // return NULL. | 275 // return NULL. |
278 TEST(DiskBasedCertCache, GetUncachedCert) { | 276 TEST(DiskBasedCertCache, GetUncachedCert) { |
279 ScopedMockTransaction trans1( | 277 ScopedMockTransaction trans1( |
280 CreateMockTransaction(kCert1.cache_key, TEST_MODE_NORMAL)); | 278 CreateMockTransaction(kCert1.cache_key, TEST_MODE_NORMAL)); |
281 MockDiskCache backend; | 279 MockDiskCache backend; |
282 DiskBasedCertCache cache(&backend); | 280 DiskBasedCertCache cache(&backend); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 ImportCertFromFile(GetTestCertsDirectory(), kCert1.file_name)); | 466 ImportCertFromFile(GetTestCertsDirectory(), kCert1.file_name)); |
469 ASSERT_TRUE(cert.get()); | 467 ASSERT_TRUE(cert.get()); |
470 TestSetCallback set_callback; | 468 TestSetCallback set_callback; |
471 | 469 |
472 cache->Set(cert->os_cert_handle(), set_callback.callback()); | 470 cache->Set(cert->os_cert_handle(), set_callback.callback()); |
473 cache.reset(); | 471 cache.reset(); |
474 set_callback.WaitForResult(); | 472 set_callback.WaitForResult(); |
475 EXPECT_EQ(std::string(), set_callback.key()); | 473 EXPECT_EQ(std::string(), set_callback.key()); |
476 } | 474 } |
477 | 475 |
476 // Issues two successive read requests to the DBCC for a certificate, | |
wtc
2014/07/02 20:51:50
Nit: the DBCC abbreviation is not common. Also, yo
| |
477 // and then checks that the DiskBasedCertCache correctly read and recorded | |
478 // reading through the in-memory MRU cache. | |
479 TEST(DiskBasedCertCache, MemCacheGet) { | |
480 ScopedMockTransaction trans1( | |
481 CreateMockTransaction(kCert1.cache_key, TEST_MODE_NORMAL)); | |
482 MockDiskCache backend; | |
483 ASSERT_NO_FATAL_FAILURE( | |
484 (ImportCert(&backend, kCert1, false /* not corrupted */))); | |
wtc
2014/07/02 20:51:50
The outer most parentheses on this line don't seem
| |
485 DiskBasedCertCache cache(&backend); | |
486 | |
487 TestGetCallback get_callback1, get_callback2; | |
488 cache.Get(kCert1.cache_key, get_callback1.callback()); | |
489 get_callback1.WaitForResult(); | |
490 EXPECT_EQ(0, cache.MemCacheHits()); | |
491 cache.Get(kCert1.cache_key, get_callback2.callback()); | |
492 get_callback2.WaitForResult(); | |
493 EXPECT_EQ(1, cache.MemCacheHits()); | |
494 EXPECT_TRUE(X509Certificate::IsSameOSCert(get_callback1.cert_handle(), | |
495 get_callback2.cert_handle())); | |
496 } | |
497 | |
498 // Issues two successive write requests to the DBCC for a certificate, | |
499 // and then checks that the DiskBasedCertCache correctly recorded | |
500 // recorded an in-memory cache hit for the second. | |
wtc
2014/07/02 20:51:50
Delete the second "recorded".
| |
501 TEST(DiskBasedCertCache, MemCacheSet) { | |
502 ScopedMockTransaction trans1( | |
503 CreateMockTransaction(kCert1.cache_key, TEST_MODE_NORMAL)); | |
504 MockDiskCache backend; | |
505 DiskBasedCertCache cache(&backend); | |
506 scoped_refptr<X509Certificate> cert( | |
507 ImportCertFromFile(GetTestCertsDirectory(), kCert1.file_name)); | |
508 ASSERT_TRUE(cert.get()); | |
509 | |
510 TestSetCallback set_callback1, set_callback2; | |
511 cache.Set(cert->os_cert_handle(), set_callback1.callback()); | |
512 set_callback1.WaitForResult(); | |
513 EXPECT_EQ(kCert1.cache_key, set_callback1.key()); | |
514 EXPECT_EQ(0, cache.MemCacheHits()); | |
515 | |
516 cache.Set(cert->os_cert_handle(), set_callback2.callback()); | |
517 set_callback2.WaitForResult(); | |
518 EXPECT_EQ(1, cache.MemCacheHits()); | |
519 ASSERT_NO_FATAL_FAILURE(CheckCertCached(&backend, kCert1)); | |
520 } | |
521 | |
522 // Reads a corrupted certificate from the disk cache, and then overwrites | |
523 // it and checks that the uncorrupted version was stored in the in-memory | |
524 // cache. | |
525 TEST(DiskBasedCertCache, CorruptOverwrite) { | |
526 ScopedMockTransaction trans1( | |
527 CreateMockTransaction(kCert1.cache_key, TEST_MODE_NORMAL)); | |
528 MockDiskCache backend; | |
529 backend.set_double_create_check(false); | |
530 ASSERT_NO_FATAL_FAILURE(ImportCert(&backend, kCert1, true /* corrupted */)); | |
531 DiskBasedCertCache cache(&backend); | |
532 TestGetCallback get_callback1, get_callback2; | |
533 | |
534 cache.Get(kCert1.cache_key, get_callback1.callback()); | |
535 get_callback1.WaitForResult(); | |
536 EXPECT_FALSE(get_callback2.cert_handle()); | |
537 | |
538 scoped_refptr<X509Certificate> cert( | |
539 ImportCertFromFile(GetTestCertsDirectory(), kCert1.file_name)); | |
540 TestSetCallback set_callback; | |
541 | |
542 cache.Set(cert->os_cert_handle(), set_callback.callback()); | |
543 set_callback.WaitForResult(); | |
544 EXPECT_EQ(kCert1.cache_key, set_callback.key()); | |
545 EXPECT_EQ(0, cache.MemCacheHits()); | |
546 | |
547 cache.Get(kCert1.cache_key, get_callback2.callback()); | |
548 get_callback2.WaitForResult(); | |
549 EXPECT_TRUE(X509Certificate::IsSameOSCert(get_callback2.cert_handle(), | |
550 cert->os_cert_handle())); | |
551 EXPECT_EQ(1, cache.MemCacheHits()); | |
552 ASSERT_NO_FATAL_FAILURE(CheckCertCached(&backend, kCert1)); | |
553 } | |
554 | |
478 } // namespace net | 555 } // namespace net |
556 | |
wtc
2014/07/02 20:51:50
Nit: did you mean to add this blank line?
| |
OLD | NEW |