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

Side by Side Diff: net/http/disk_based_cert_cache_unittest.cc

Issue 361513003: Improving and adding an in-memory MRU cache to DiskBasedCertCache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@DBCC_Implement
Patch Set: Revisions based on review of patch set 3. 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
« no previous file with comments | « net/http/disk_based_cert_cache.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 for a certificate, and then
477 // 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 */));
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(static_cast<size_t>(0), cache.mem_cache_hits_for_testing());
Ryan Sleevi 2014/07/02 22:49:23 Use "0U" instead
491 cache.Get(kCert1.cache_key, get_callback2.callback());
492 get_callback2.WaitForResult();
493 EXPECT_EQ(static_cast<size_t>(1), cache.mem_cache_hits_for_testing());
Ryan Sleevi 2014/07/02 22:49:23 Use "1U" instead
494 EXPECT_TRUE(X509Certificate::IsSameOSCert(get_callback1.cert_handle(),
495 get_callback2.cert_handle()));
496 }
497
498 // Reads a corrupted certificate from the disk cache, and then overwrites
499 // it and checks that the uncorrupted version was stored in the in-memory
500 // cache.
501 TEST(DiskBasedCertCache, CorruptOverwrite) {
502 ScopedMockTransaction trans1(
503 CreateMockTransaction(kCert1.cache_key, TEST_MODE_NORMAL));
504 MockDiskCache backend;
505 backend.set_double_create_check(false);
506 ASSERT_NO_FATAL_FAILURE(ImportCert(&backend, kCert1, true /* corrupted */));
507 DiskBasedCertCache cache(&backend);
508 TestGetCallback get_callback1, get_callback2;
509
510 cache.Get(kCert1.cache_key, get_callback1.callback());
511 get_callback1.WaitForResult();
512 EXPECT_FALSE(get_callback2.cert_handle());
513
514 scoped_refptr<X509Certificate> cert(
515 ImportCertFromFile(GetTestCertsDirectory(), kCert1.file_name));
516 TestSetCallback set_callback;
517
518 cache.Set(cert->os_cert_handle(), set_callback.callback());
519 set_callback.WaitForResult();
520 EXPECT_EQ(kCert1.cache_key, set_callback.key());
521 EXPECT_EQ(static_cast<size_t>(0), cache.mem_cache_hits_for_testing());
Ryan Sleevi 2014/07/02 22:49:23 Use "0U" instead
522
523 cache.Get(kCert1.cache_key, get_callback2.callback());
524 get_callback2.WaitForResult();
525 EXPECT_TRUE(X509Certificate::IsSameOSCert(get_callback2.cert_handle(),
526 cert->os_cert_handle()));
527 EXPECT_EQ(static_cast<size_t>(1), cache.mem_cache_hits_for_testing());
Ryan Sleevi 2014/07/02 22:49:23 Use "1U" instead
528 ASSERT_NO_FATAL_FAILURE(CheckCertCached(&backend, kCert1));
529 }
530
478 } // namespace net 531 } // namespace net
OLDNEW
« no previous file with comments | « net/http/disk_based_cert_cache.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698