known_roots_unittest.cc 1.2 KB

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