OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/net/packed_ct_ev_whitelist.h" | 5 #include "components/packed_ct_ev_whitelist/packed_ct_ev_whitelist.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/big_endian.h" | 10 #include "base/big_endian.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 const uint8_t kFirstHashRaw[] = | 15 const uint8_t kFirstHashRaw[] = |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 std::string GetPartialWhitelistData(uint8_t num_bytes) { | 47 std::string GetPartialWhitelistData(uint8_t num_bytes) { |
48 return std::string(reinterpret_cast<const char*>(kWhitelistData), num_bytes); | 48 return std::string(reinterpret_cast<const char*>(kWhitelistData), num_bytes); |
49 } | 49 } |
50 | 50 |
51 std::string GetAllWhitelistData() { | 51 std::string GetAllWhitelistData() { |
52 return GetPartialWhitelistData(arraysize(kWhitelistData)); | 52 return GetPartialWhitelistData(arraysize(kWhitelistData)); |
53 } | 53 } |
54 | 54 |
55 } // namespace | 55 } // namespace |
56 | 56 |
| 57 namespace packed_ct_ev_whitelist { |
| 58 |
57 TEST(PackedEVCertsWhitelistTest, UncompressFailsForTooShortList) { | 59 TEST(PackedEVCertsWhitelistTest, UncompressFailsForTooShortList) { |
58 // This list does not contain enough bytes even for the first hash. | 60 // This list does not contain enough bytes even for the first hash. |
59 std::vector<uint64_t> res; | 61 std::vector<uint64_t> res; |
60 EXPECT_FALSE(PackedEVCertsWhitelist::UncompressEVWhitelist( | 62 EXPECT_FALSE(PackedEVCertsWhitelist::UncompressEVWhitelist( |
61 std::string(reinterpret_cast<const char*>(kWhitelistData), 7), &res)); | 63 std::string(reinterpret_cast<const char*>(kWhitelistData), 7), &res)); |
62 } | 64 } |
63 | 65 |
64 TEST(PackedEVCertsWhitelistTest, UncompressFailsForTruncatedList) { | 66 TEST(PackedEVCertsWhitelistTest, UncompressFailsForTruncatedList) { |
65 // This list is missing bits for the second part of the diff. | 67 // This list is missing bits for the second part of the diff. |
66 std::vector<uint64_t> res; | 68 std::vector<uint64_t> res; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 142 |
141 EXPECT_FALSE(whitelist->IsValid()); | 143 EXPECT_FALSE(whitelist->IsValid()); |
142 } | 144 } |
143 | 145 |
144 TEST(PackedEVCertsWhitelistTest, CorrectlyIdentifiesWhitelistIsValid) { | 146 TEST(PackedEVCertsWhitelistTest, CorrectlyIdentifiesWhitelistIsValid) { |
145 scoped_refptr<PackedEVCertsWhitelist> whitelist( | 147 scoped_refptr<PackedEVCertsWhitelist> whitelist( |
146 new PackedEVCertsWhitelist(GetAllWhitelistData(), base::Version())); | 148 new PackedEVCertsWhitelist(GetAllWhitelistData(), base::Version())); |
147 | 149 |
148 EXPECT_TRUE(whitelist->IsValid()); | 150 EXPECT_TRUE(whitelist->IsValid()); |
149 } | 151 } |
| 152 |
| 153 } // namespace packed_ct_ev_whitelist |
OLD | NEW |