OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/file_path.h" | 5 #include "base/file_path.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
9 #include "net/base/cert_status_flags.h" | 9 #include "net/base/cert_status_flags.h" |
10 #include "net/base/cert_test_util.h" | 10 #include "net/base/cert_test_util.h" |
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 TEST_P(X509CertificateParseTest, CanParseFormat) { | 696 TEST_P(X509CertificateParseTest, CanParseFormat) { |
697 FilePath certs_dir = GetTestCertsDirectory(); | 697 FilePath certs_dir = GetTestCertsDirectory(); |
698 CertificateList certs = CreateCertificateListFromFile( | 698 CertificateList certs = CreateCertificateListFromFile( |
699 certs_dir, test_data_.file_name, test_data_.format); | 699 certs_dir, test_data_.file_name, test_data_.format); |
700 ASSERT_FALSE(certs.empty()); | 700 ASSERT_FALSE(certs.empty()); |
701 ASSERT_LE(certs.size(), arraysize(test_data_.chain_fingerprints)); | 701 ASSERT_LE(certs.size(), arraysize(test_data_.chain_fingerprints)); |
702 CheckGoogleCert(certs.front(), google_parse_fingerprint, | 702 CheckGoogleCert(certs.front(), google_parse_fingerprint, |
703 kGoogleParseValidFrom, kGoogleParseValidTo); | 703 kGoogleParseValidFrom, kGoogleParseValidTo); |
704 | 704 |
705 size_t i; | 705 size_t i; |
706 for (i = 0; i < arraysize(test_data_.chain_fingerprints) && | 706 for (i = 0; i < arraysize(test_data_.chain_fingerprints); ++i) { |
707 i < certs.size() && test_data_.chain_fingerprints[i] != NULL; ++i) { | 707 if (test_data_.chain_fingerprints[i] == NULL) { |
| 708 // No more test certificates expected - make sure no more were |
| 709 // returned before marking this test a success. |
| 710 EXPECT_EQ(i, certs.size()); |
| 711 break; |
| 712 } |
| 713 |
| 714 // A cert is expected - make sure that one was parsed. |
| 715 ASSERT_LT(i, certs.size()); |
| 716 |
| 717 // Compare the parsed certificate with the expected certificate, by |
| 718 // comparing fingerprints. |
708 const X509Certificate* cert = certs[i]; | 719 const X509Certificate* cert = certs[i]; |
709 const SHA1Fingerprint& actual_fingerprint = cert->fingerprint(); | 720 const SHA1Fingerprint& actual_fingerprint = cert->fingerprint(); |
710 unsigned char* expected_fingerprint = test_data_.chain_fingerprints[i]; | 721 unsigned char* expected_fingerprint = test_data_.chain_fingerprints[i]; |
711 | 722 |
712 for (size_t j = 0; j < 20; ++j) | 723 for (size_t j = 0; j < 20; ++j) |
713 EXPECT_EQ(expected_fingerprint[j], actual_fingerprint.data[j]); | 724 EXPECT_EQ(expected_fingerprint[j], actual_fingerprint.data[j]); |
714 } | 725 } |
715 } | 726 } |
716 | 727 |
717 INSTANTIATE_TEST_CASE_P(, X509CertificateParseTest, | 728 INSTANTIATE_TEST_CASE_P(, X509CertificateParseTest, |
718 testing::ValuesIn(FormatTestData)); | 729 testing::ValuesIn(FormatTestData)); |
719 | 730 |
720 } // namespace net | 731 } // namespace net |
OLD | NEW |