1 // Copyright 2017 The Chromium Authors
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/cert/symantec_certs.h"
6
7 #include <algorithm>
8
9 #include "net/base/hash_value.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace net {
13
14 // Tests that IsLegacySymantecCert() returns false for non-Symantec hash values.
TEST(SymantecCertsTest,IsUnrelatedCertSymantecLegacyCert)15 TEST(SymantecCertsTest, IsUnrelatedCertSymantecLegacyCert) {
16 SHA256HashValue unrelated_hash_value = {{0x01, 0x02}};
17 HashValueVector unrelated_hashes;
18 unrelated_hashes.push_back(HashValue(unrelated_hash_value));
19 EXPECT_FALSE(IsLegacySymantecCert(unrelated_hashes));
20 }
21
22 // Tests that IsLegacySymantecCert() works correctly for excluded and
23 // non-excluded Symantec roots.
TEST(SymantecCertsTest,IsLegacySymantecCert)24 TEST(SymantecCertsTest, IsLegacySymantecCert) {
25 SHA256HashValue symantec_hash_value = {
26 {0xb2, 0xde, 0xf5, 0x36, 0x2a, 0xd3, 0xfa, 0xcd, 0x04, 0xbd, 0x29,
27 0x04, 0x7a, 0x43, 0x84, 0x4f, 0x76, 0x70, 0x34, 0xea, 0x48, 0x92,
28 0xf8, 0x0e, 0x56, 0xbe, 0xe6, 0x90, 0x24, 0x3e, 0x25, 0x02}};
29 SHA256HashValue google_hash_value = {
30 {0xec, 0x72, 0x29, 0x69, 0xcb, 0x64, 0x20, 0x0a, 0xb6, 0x63, 0x8f,
31 0x68, 0xac, 0x53, 0x8e, 0x40, 0xab, 0xab, 0x5b, 0x19, 0xa6, 0x48,
32 0x56, 0x61, 0x04, 0x2a, 0x10, 0x61, 0xc4, 0x61, 0x27, 0x76}};
33
34 // Test that IsLegacySymantecCert returns true for a Symantec root.
35 HashValueVector hashes;
36 hashes.push_back(HashValue(symantec_hash_value));
37 EXPECT_TRUE(IsLegacySymantecCert(hashes));
38
39 // ... but false when the chain includes a root on the exceptions list.
40 hashes.push_back(HashValue(google_hash_value));
41 EXPECT_FALSE(IsLegacySymantecCert(hashes));
42 }
43
TEST(SymantecCertsTest,AreSortedArrays)44 TEST(SymantecCertsTest, AreSortedArrays) {
45 ASSERT_TRUE(
46 std::is_sorted(kSymantecRoots, kSymantecRoots + kSymantecRootsLength));
47 ASSERT_TRUE(std::is_sorted(kSymantecExceptions,
48 kSymantecExceptions + kSymantecExceptionsLength));
49 ASSERT_TRUE(std::is_sorted(kSymantecManagedCAs,
50 kSymantecManagedCAs + kSymantecManagedCAsLength));
51 }
52
53 } // namespace net
54