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

Side by Side Diff: net/quic/crypto/cert_compressor_test.cc

Issue 2193073003: Move shared files in net/quic/ into net/quic/core/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: io_thread_unittest.cc Created 4 years, 4 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/quic/crypto/cert_compressor.cc ('k') | net/quic/crypto/chacha20_poly1305_decrypter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/quic/crypto/cert_compressor.h"
6
7 #include <memory>
8
9 #include "net/quic/quic_utils.h"
10 #include "net/quic/test_tools/crypto_test_utils.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 using base::StringPiece;
14 using std::string;
15 using std::vector;
16
17 namespace net {
18 namespace test {
19
20 TEST(CertCompressor, EmptyChain) {
21 vector<string> chain;
22 const string compressed = CertCompressor::CompressChain(
23 chain, StringPiece(), StringPiece(), nullptr);
24 EXPECT_EQ("00", QuicUtils::HexEncode(compressed));
25
26 vector<string> chain2, cached_certs;
27 ASSERT_TRUE(CertCompressor::DecompressChain(compressed, cached_certs, nullptr,
28 &chain2));
29 EXPECT_EQ(chain.size(), chain2.size());
30 }
31
32 TEST(CertCompressor, Compressed) {
33 vector<string> chain;
34 chain.push_back("testcert");
35 const string compressed = CertCompressor::CompressChain(
36 chain, StringPiece(), StringPiece(), nullptr);
37 ASSERT_GE(compressed.size(), 2u);
38 EXPECT_EQ("0100", QuicUtils::HexEncode(compressed.substr(0, 2)));
39
40 vector<string> chain2, cached_certs;
41 ASSERT_TRUE(CertCompressor::DecompressChain(compressed, cached_certs, nullptr,
42 &chain2));
43 EXPECT_EQ(chain.size(), chain2.size());
44 EXPECT_EQ(chain[0], chain2[0]);
45 }
46
47 TEST(CertCompressor, Common) {
48 vector<string> chain;
49 chain.push_back("testcert");
50 static const uint64_t set_hash = 42;
51 std::unique_ptr<CommonCertSets> common_sets(
52 CryptoTestUtils::MockCommonCertSets(chain[0], set_hash, 1));
53 const string compressed = CertCompressor::CompressChain(
54 chain,
55 StringPiece(reinterpret_cast<const char*>(&set_hash), sizeof(set_hash)),
56 StringPiece(), common_sets.get());
57 EXPECT_EQ(
58 "03" /* common */
59 "2A00000000000000" /* set hash 42 */
60 "01000000" /* index 1 */
61 "00" /* end of list */,
62 QuicUtils::HexEncode(compressed));
63
64 vector<string> chain2, cached_certs;
65 ASSERT_TRUE(CertCompressor::DecompressChain(compressed, cached_certs,
66 common_sets.get(), &chain2));
67 EXPECT_EQ(chain.size(), chain2.size());
68 EXPECT_EQ(chain[0], chain2[0]);
69 }
70
71 TEST(CertCompressor, Cached) {
72 vector<string> chain;
73 chain.push_back("testcert");
74 uint64_t hash = QuicUtils::FNV1a_64_Hash(chain[0].data(), chain[0].size());
75 StringPiece hash_bytes(reinterpret_cast<char*>(&hash), sizeof(hash));
76 const string compressed =
77 CertCompressor::CompressChain(chain, StringPiece(), hash_bytes, nullptr);
78
79 EXPECT_EQ("02" /* cached */ + QuicUtils::HexEncode(hash_bytes) +
80 "00" /* end of list */,
81 QuicUtils::HexEncode(compressed));
82
83 vector<string> cached_certs, chain2;
84 cached_certs.push_back(chain[0]);
85 ASSERT_TRUE(CertCompressor::DecompressChain(compressed, cached_certs, nullptr,
86 &chain2));
87 EXPECT_EQ(chain.size(), chain2.size());
88 EXPECT_EQ(chain[0], chain2[0]);
89 }
90
91 TEST(CertCompressor, BadInputs) {
92 vector<string> cached_certs, chain;
93
94 EXPECT_FALSE(CertCompressor::DecompressChain(
95 QuicUtils::HexEncode("04") /* bad entry type */, cached_certs, nullptr,
96 &chain));
97
98 EXPECT_FALSE(CertCompressor::DecompressChain(
99 QuicUtils::HexEncode("01") /* no terminator */, cached_certs, nullptr,
100 &chain));
101
102 EXPECT_FALSE(CertCompressor::DecompressChain(
103 QuicUtils::HexEncode("0200") /* hash truncated */, cached_certs, nullptr,
104 &chain));
105
106 EXPECT_FALSE(CertCompressor::DecompressChain(
107 QuicUtils::HexEncode("0300") /* hash and index truncated */, cached_certs,
108 nullptr, &chain));
109
110 /* without a CommonCertSets */
111 EXPECT_FALSE(
112 CertCompressor::DecompressChain(QuicUtils::HexEncode("03"
113 "0000000000000000"
114 "00000000"),
115 cached_certs, nullptr, &chain));
116
117 std::unique_ptr<CommonCertSets> common_sets(
118 CryptoTestUtils::MockCommonCertSets("foo", 42, 1));
119
120 /* incorrect hash and index */
121 EXPECT_FALSE(
122 CertCompressor::DecompressChain(QuicUtils::HexEncode("03"
123 "a200000000000000"
124 "00000000"),
125 cached_certs, nullptr, &chain));
126 }
127
128 } // namespace test
129 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/cert_compressor.cc ('k') | net/quic/crypto/chacha20_poly1305_decrypter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698