symantec_certs_unittest.cc 2.1 KB

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