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/known_roots.h"
6
7 #include <string.h>
8
9 #include <algorithm>
10
11 #include "net/base/hash_value.h"
12 #include "net/cert/root_cert_list_generated.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace net {
16
17 namespace {
18
TEST(KnownRootsTest,RootCertDataIsSorted)19 TEST(KnownRootsTest, RootCertDataIsSorted) {
20 EXPECT_TRUE(std::is_sorted(
21 std::begin(kRootCerts), std::end(kRootCerts),
22 [](const RootCertData& lhs, const RootCertData& rhs) {
23 return memcmp(lhs.sha256_spki_hash, rhs.sha256_spki_hash, 32) < 0;
24 }));
25 }
26
TEST(KnownRootsTest,UnknownHashReturnsNotFound)27 TEST(KnownRootsTest, UnknownHashReturnsNotFound) {
28 SHA256HashValue empty_hash = {{0}};
29 EXPECT_EQ(0, GetNetTrustAnchorHistogramIdForSPKI(HashValue(empty_hash)));
30 }
31
TEST(KnownRootsTest,FindsKnownRoot)32 TEST(KnownRootsTest, FindsKnownRoot) {
33 SHA256HashValue gts_root_r3_hash = {
34 {0x41, 0x79, 0xed, 0xd9, 0x81, 0xef, 0x74, 0x74, 0x77, 0xb4, 0x96,
35 0x26, 0x40, 0x8a, 0xf4, 0x3d, 0xaa, 0x2c, 0xa7, 0xab, 0x7f, 0x9e,
36 0x08, 0x2c, 0x10, 0x60, 0xf8, 0x40, 0x96, 0x77, 0x43, 0x48}};
37 EXPECT_EQ(485,
38 GetNetTrustAnchorHistogramIdForSPKI(HashValue(gts_root_r3_hash)));
39 }
40
41 } // namespace
42
43 } // namespace net
44