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

Side by Side Diff: net/cert/ct_serialization_unittest.cc

Issue 2604513002: Optimize CT & OCSP handling code (Closed)
Patch Set: Review feedback round two Created 3 years, 11 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/cert/ct_serialization.h" 5 #include "net/cert/ct_serialization.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 std::string expected_buffer( 134 std::string expected_buffer(
135 "\x0\x0\x0\x0\x1\x39\xFE\x35\x3C\xF5\x61\x62\x63\x0\x0", 15); 135 "\x0\x0\x0\x0\x1\x39\xFE\x35\x3C\xF5\x61\x62\x63\x0\x0", 15);
136 EXPECT_EQ(expected_buffer, encoded); 136 EXPECT_EQ(expected_buffer, encoded);
137 } 137 }
138 138
139 TEST_F(CtSerializationTest, DecodesSCTList) { 139 TEST_F(CtSerializationTest, DecodesSCTList) {
140 // Two items in the list: "abc", "def" 140 // Two items in the list: "abc", "def"
141 base::StringPiece encoded("\x0\xa\x0\x3\x61\x62\x63\x0\x3\x64\x65\x66", 12); 141 base::StringPiece encoded("\x0\xa\x0\x3\x61\x62\x63\x0\x3\x64\x65\x66", 12);
142 std::vector<base::StringPiece> decoded; 142 std::vector<base::StringPiece> decoded;
143 143
144 ASSERT_TRUE(ct::DecodeSCTList(&encoded, &decoded)); 144 ASSERT_TRUE(ct::DecodeSCTList(encoded, &decoded));
145 ASSERT_STREQ("abc", decoded[0].data()); 145 ASSERT_STREQ("abc", decoded[0].data());
146 ASSERT_STREQ("def", decoded[1].data()); 146 ASSERT_STREQ("def", decoded[1].data());
147 } 147 }
148 148
149 TEST_F(CtSerializationTest, FailsDecodingInvalidSCTList) { 149 TEST_F(CtSerializationTest, FailsDecodingInvalidSCTList) {
150 // A list with one item that's too short 150 // A list with one item that's too short
151 base::StringPiece encoded("\x0\xa\x0\x3\x61\x62\x63\x0\x5\x64\x65\x66", 12); 151 base::StringPiece encoded("\x0\xa\x0\x3\x61\x62\x63\x0\x5\x64\x65\x66", 12);
152 std::vector<base::StringPiece> decoded; 152 std::vector<base::StringPiece> decoded;
153 153
154 ASSERT_FALSE(ct::DecodeSCTList(&encoded, &decoded)); 154 ASSERT_FALSE(ct::DecodeSCTList(encoded, &decoded));
155 } 155 }
156 156
157 TEST_F(CtSerializationTest, DecodesSignedCertificateTimestamp) { 157 TEST_F(CtSerializationTest, DecodesSignedCertificateTimestamp) {
158 std::string encoded_test_sct(ct::GetTestSignedCertificateTimestamp()); 158 std::string encoded_test_sct(ct::GetTestSignedCertificateTimestamp());
159 base::StringPiece encoded_sct(encoded_test_sct); 159 base::StringPiece encoded_sct(encoded_test_sct);
160 160
161 scoped_refptr<ct::SignedCertificateTimestamp> sct; 161 scoped_refptr<ct::SignedCertificateTimestamp> sct;
162 ASSERT_TRUE(ct::DecodeSignedCertificateTimestamp(&encoded_sct, &sct)); 162 ASSERT_TRUE(ct::DecodeSignedCertificateTimestamp(&encoded_sct, &sct));
163 EXPECT_EQ(0, sct->version); 163 EXPECT_EQ(0, sct->version);
164 EXPECT_EQ(ct::GetTestPublicKeyId(), sct->log_id); 164 EXPECT_EQ(ct::GetTestPublicKeyId(), sct->log_id);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 // Bytes 10-17 are tree size 252 // Bytes 10-17 are tree size
253 // Bytes 18-49 are sha256 root hash 253 // Bytes 18-49 are sha256 root hash
254 ASSERT_EQ(50u, encoded.length()); 254 ASSERT_EQ(50u, encoded.length());
255 std::string expected_buffer( 255 std::string expected_buffer(
256 "\x0\x1\x0\x0\x1\x45\x3c\x5f\xb8\x35\x0\x0\x0\x0\x0\x0\x0\x15", 18); 256 "\x0\x1\x0\x0\x1\x45\x3c\x5f\xb8\x35\x0\x0\x0\x0\x0\x0\x0\x15", 18);
257 expected_buffer.append(ct::GetSampleSTHSHA256RootHash()); 257 expected_buffer.append(ct::GetSampleSTHSHA256RootHash());
258 ASSERT_EQ(expected_buffer, encoded); 258 ASSERT_EQ(expected_buffer, encoded);
259 } 259 }
260 260
261 } // namespace net 261 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698