Chromium Code Reviews| 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 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 626 google_handle, X509Certificate::SOURCE_FROM_NETWORK, intermediates3); | 626 google_handle, X509Certificate::SOURCE_FROM_NETWORK, intermediates3); |
| 627 | 627 |
| 628 // The cache should have returned cert2 'cause it has more intermediates: | 628 // The cache should have returned cert2 'cause it has more intermediates: |
| 629 EXPECT_EQ(cert3, cert2); | 629 EXPECT_EQ(cert3, cert2); |
| 630 | 630 |
| 631 // Cleanup | 631 // Cleanup |
| 632 X509Certificate::FreeOSCertHandle(google_handle); | 632 X509Certificate::FreeOSCertHandle(google_handle); |
| 633 } | 633 } |
| 634 #endif | 634 #endif |
| 635 | 635 |
| 636 #if defined(OS_MACOSX) | |
|
wtc
2010/08/03 01:26:58
Is this unit test ifdef'd with OS_MACOSX because
t
| |
| 637 TEST(X509CertificateTest, IsIssuedBy) { | |
| 638 FilePath certs_dir = GetTestCertsDirectory(); | |
| 639 | |
| 640 // Test a client certificate from MIT. | |
| 641 scoped_refptr<X509Certificate> mit_davidben_cert = | |
| 642 ImportCertFromFile(certs_dir, "mit.davidben.der"); | |
| 643 ASSERT_NE(static_cast<X509Certificate*>(NULL), mit_davidben_cert); | |
| 644 | |
| 645 CertPrincipal mit_principal; | |
|
wtc
2010/08/03 01:26:58
Nit: mit_principal => mit_issuer
foaf_princip
| |
| 646 mit_principal.country_name = "US"; | |
| 647 mit_principal.state_or_province_name = "Massachusetts"; | |
| 648 mit_principal.organization_names.push_back( | |
| 649 "Massachusetts Institute of Technology"); | |
| 650 mit_principal.organization_unit_names.push_back("Client CA v1"); | |
| 651 | |
| 652 // IsIssuedBy should return true even if it cannot build a chain | |
| 653 // with that principal. | |
| 654 std::vector<CertPrincipal> mit_issuers(1, mit_principal); | |
| 655 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(mit_issuers)); | |
| 656 | |
| 657 // Test a client certificate from FOAF.ME. | |
| 658 scoped_refptr<X509Certificate> foaf_me_chromium_test_cert = | |
| 659 ImportCertFromFile(certs_dir, "foaf.me.chromium-test-cert.der"); | |
| 660 ASSERT_NE(static_cast<X509Certificate*>(NULL), foaf_me_chromium_test_cert); | |
| 661 | |
| 662 CertPrincipal foaf_principal; | |
| 663 foaf_principal.common_name = "FOAF.ME"; | |
| 664 foaf_principal.locality_name = "Wimbledon"; | |
| 665 foaf_principal.state_or_province_name = "LONDON"; | |
| 666 foaf_principal.country_name = "GB"; | |
| 667 foaf_principal.organization_names.push_back("FOAF.ME"); | |
| 668 | |
| 669 std::vector<CertPrincipal> foaf_issuers(1, foaf_principal); | |
| 670 EXPECT_TRUE(foaf_me_chromium_test_cert->IsIssuedBy(foaf_issuers)); | |
| 671 | |
| 672 // And test some combinations and mismatches. | |
| 673 std::vector<CertPrincipal> both_issuers; | |
| 674 both_issuers.push_back(mit_principal); | |
| 675 both_issuers.push_back(foaf_principal); | |
| 676 EXPECT_TRUE(foaf_me_chromium_test_cert->IsIssuedBy(both_issuers)); | |
| 677 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(both_issuers)); | |
| 678 EXPECT_FALSE(foaf_me_chromium_test_cert->IsIssuedBy(mit_issuers)); | |
| 679 EXPECT_FALSE(mit_davidben_cert->IsIssuedBy(foaf_issuers)); | |
| 680 } | |
| 681 #endif // defined(OS_MACOSX) | |
| 682 | |
| 636 class X509CertificateParseTest | 683 class X509CertificateParseTest |
| 637 : public testing::TestWithParam<CertificateFormatTestData> { | 684 : public testing::TestWithParam<CertificateFormatTestData> { |
| 638 public: | 685 public: |
| 639 virtual ~X509CertificateParseTest() {} | 686 virtual ~X509CertificateParseTest() {} |
| 640 virtual void SetUp() { | 687 virtual void SetUp() { |
| 641 test_data_ = GetParam(); | 688 test_data_ = GetParam(); |
| 642 } | 689 } |
| 643 virtual void TearDown() {} | 690 virtual void TearDown() {} |
| 644 | 691 |
| 645 protected: | 692 protected: |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 664 | 711 |
| 665 for (size_t j = 0; j < 20; ++j) | 712 for (size_t j = 0; j < 20; ++j) |
| 666 EXPECT_EQ(expected_fingerprint[j], actual_fingerprint.data[j]); | 713 EXPECT_EQ(expected_fingerprint[j], actual_fingerprint.data[j]); |
| 667 } | 714 } |
| 668 } | 715 } |
| 669 | 716 |
| 670 INSTANTIATE_TEST_CASE_P(, X509CertificateParseTest, | 717 INSTANTIATE_TEST_CASE_P(, X509CertificateParseTest, |
| 671 testing::ValuesIn(FormatTestData)); | 718 testing::ValuesIn(FormatTestData)); |
| 672 | 719 |
| 673 } // namespace net | 720 } // namespace net |
| OLD | NEW |