OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/quic/core/crypto/quic_compressed_certs_cache.h" | 5 #include "net/quic/core/crypto/quic_compressed_certs_cache.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "net/quic/core/crypto/cert_compressor.h" | 10 #include "net/quic/core/crypto/cert_compressor.h" |
11 #include "net/quic/test_tools/crypto_test_utils.h" | 11 #include "net/quic/test_tools/crypto_test_utils.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
| 14 using base::IntToString; |
14 using std::string; | 15 using std::string; |
15 | 16 |
16 namespace net { | 17 namespace net { |
17 | 18 |
18 namespace test { | 19 namespace test { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 class QuicCompressedCertsCacheTest : public testing::Test { | 23 class QuicCompressedCertsCacheTest : public testing::Test { |
23 public: | 24 public: |
(...skipping 27 matching lines...) Expand all Loading... |
51 string common_certs = "common certs"; | 52 string common_certs = "common certs"; |
52 string cached_certs = "cached certs"; | 53 string cached_certs = "cached certs"; |
53 string compressed = "compressed cert"; | 54 string compressed = "compressed cert"; |
54 | 55 |
55 certs_cache_.Insert(chain, common_certs, cached_certs, compressed); | 56 certs_cache_.Insert(chain, common_certs, cached_certs, compressed); |
56 | 57 |
57 EXPECT_EQ(nullptr, certs_cache_.GetCompressedCert( | 58 EXPECT_EQ(nullptr, certs_cache_.GetCompressedCert( |
58 chain, "mismatched common certs", cached_certs)); | 59 chain, "mismatched common certs", cached_certs)); |
59 EXPECT_EQ(nullptr, certs_cache_.GetCompressedCert(chain, common_certs, | 60 EXPECT_EQ(nullptr, certs_cache_.GetCompressedCert(chain, common_certs, |
60 "mismatched cached certs")); | 61 "mismatched cached certs")); |
| 62 |
| 63 // A different chain though with equivalent certs should get a cache miss. |
61 QuicReferenceCountedPointer<ProofSource::Chain> chain2( | 64 QuicReferenceCountedPointer<ProofSource::Chain> chain2( |
62 new ProofSource::Chain(certs)); | 65 new ProofSource::Chain(certs)); |
63 EXPECT_EQ(nullptr, | 66 EXPECT_EQ(nullptr, |
64 certs_cache_.GetCompressedCert(chain2, common_certs, cached_certs)); | 67 certs_cache_.GetCompressedCert(chain2, common_certs, cached_certs)); |
65 } | 68 } |
66 | 69 |
67 TEST_F(QuicCompressedCertsCacheTest, CacheMissDueToEviction) { | 70 TEST_F(QuicCompressedCertsCacheTest, CacheMissDueToEviction) { |
68 // Test cache returns a miss when a queried uncompressed certs was cached but | 71 // Test cache returns a miss when a queried uncompressed certs was cached but |
69 // then evicted. | 72 // then evicted. |
70 std::vector<string> certs = {"leaf cert", "intermediate cert", "root cert"}; | 73 std::vector<string> certs = {"leaf cert", "intermediate cert", "root cert"}; |
71 QuicReferenceCountedPointer<ProofSource::Chain> chain( | 74 QuicReferenceCountedPointer<ProofSource::Chain> chain( |
72 new ProofSource::Chain(certs)); | 75 new ProofSource::Chain(certs)); |
73 | 76 |
74 string common_certs = "common certs"; | 77 string common_certs = "common certs"; |
75 string cached_certs = "cached certs"; | 78 string cached_certs = "cached certs"; |
76 string compressed = "compressed cert"; | 79 string compressed = "compressed cert"; |
77 certs_cache_.Insert(chain, common_certs, cached_certs, compressed); | 80 certs_cache_.Insert(chain, common_certs, cached_certs, compressed); |
78 | 81 |
79 // Insert another kQuicCompressedCertsCacheSize certs to evict the first | 82 // Insert another kQuicCompressedCertsCacheSize certs to evict the first |
80 // cached cert. | 83 // cached cert. |
81 for (unsigned int i = 0; | 84 for (unsigned int i = 0; |
82 i < QuicCompressedCertsCache::kQuicCompressedCertsCacheSize; i++) { | 85 i < QuicCompressedCertsCache::kQuicCompressedCertsCacheSize; i++) { |
83 EXPECT_EQ(certs_cache_.Size(), i + 1); | 86 EXPECT_EQ(certs_cache_.Size(), i + 1); |
84 certs_cache_.Insert(chain, base::IntToString(i), "", base::IntToString(i)); | 87 certs_cache_.Insert(chain, IntToString(i), "", IntToString(i)); |
85 } | 88 } |
86 EXPECT_EQ(certs_cache_.MaxSize(), certs_cache_.Size()); | 89 EXPECT_EQ(certs_cache_.MaxSize(), certs_cache_.Size()); |
87 | 90 |
88 EXPECT_EQ(nullptr, | 91 EXPECT_EQ(nullptr, |
89 certs_cache_.GetCompressedCert(chain, common_certs, cached_certs)); | 92 certs_cache_.GetCompressedCert(chain, common_certs, cached_certs)); |
90 } | 93 } |
91 | 94 |
92 } // namespace | 95 } // namespace |
93 } // namespace test | 96 } // namespace test |
94 } // namespace net | 97 } // namespace net |
OLD | NEW |