Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: net/base/x509_certificate_unittest.cc

Issue 11579002: Add X509Certificate::IsIssuedByEncoded() (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: add X509CertificateTest.IsIssuedByEncoded unit test Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/base/x509_certificate.h" 5 #include "net/base/x509_certificate.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/pickle.h" 10 #include "base/pickle.h"
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 both_issuers.push_back(mit_issuer); 724 both_issuers.push_back(mit_issuer);
725 both_issuers.push_back(foaf_issuer); 725 both_issuers.push_back(foaf_issuer);
726 EXPECT_TRUE(foaf_me_chromium_test_cert->IsIssuedBy(both_issuers)); 726 EXPECT_TRUE(foaf_me_chromium_test_cert->IsIssuedBy(both_issuers));
727 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(both_issuers)); 727 EXPECT_TRUE(mit_davidben_cert->IsIssuedBy(both_issuers));
728 EXPECT_FALSE(foaf_me_chromium_test_cert->IsIssuedBy(mit_issuers)); 728 EXPECT_FALSE(foaf_me_chromium_test_cert->IsIssuedBy(mit_issuers));
729 EXPECT_FALSE(mit_davidben_cert->IsIssuedBy(foaf_issuers)); 729 EXPECT_FALSE(mit_davidben_cert->IsIssuedBy(foaf_issuers));
730 } 730 }
731 #endif // defined(OS_MACOSX) 731 #endif // defined(OS_MACOSX)
732 #endif // !defined(OS_IOS) 732 #endif // !defined(OS_IOS)
733 733
734 TEST(X509CertificateTest, IsIssuedByEncoded) {
735 FilePath certs_dir = GetTestCertsDirectory();
736
737 // Test a client certificate from MIT.
738 scoped_refptr<X509Certificate> mit_davidben_cert(
739 ImportCertFromFile(certs_dir, "mit.davidben.der"));
740 ASSERT_NE(static_cast<X509Certificate*>(NULL), mit_davidben_cert);
741
742 std::string mit_issuer(reinterpret_cast<const char*>(MITDN),
743 sizeof(MITDN));
744
745 // Test a certificate from Google, issued by Thawte
746 scoped_refptr<X509Certificate> google_cert(
747 ImportCertFromFile(certs_dir, "google.single.der"));
748 ASSERT_NE(static_cast<X509Certificate*>(NULL), google_cert);
749
750 std::string thawte_issuer(reinterpret_cast<const char*>(ThawteDN),
751 sizeof(ThawteDN));
752
753 // Check that the David Ben certificate is issued by MIT, but not
754 // by Thawte.
755 std::vector<std::string> issuers;
756 issuers.clear();
757 issuers.push_back(mit_issuer);
758 EXPECT_TRUE(mit_davidben_cert->IsIssuedByEncoded(issuers));
759 EXPECT_FALSE(google_cert->IsIssuedByEncoded(issuers));
760
761 // Check that the Google certificate is issued by Thawte and not
762 // by MIT.
763 issuers.clear();
764 issuers.push_back(thawte_issuer);
765 EXPECT_FALSE(mit_davidben_cert->IsIssuedByEncoded(issuers));
766 EXPECT_TRUE(google_cert->IsIssuedByEncoded(issuers));
767
768 // Check that they both pass when given a list of the two issuers.
769 issuers.clear();
770 issuers.push_back(mit_issuer);
771 issuers.push_back(thawte_issuer);
772 EXPECT_TRUE(mit_davidben_cert->IsIssuedByEncoded(issuers));
773 EXPECT_TRUE(google_cert->IsIssuedByEncoded(issuers));
774 }
775
734 #if !defined(OS_IOS) // TODO(ios): Unable to create certificates. 776 #if !defined(OS_IOS) // TODO(ios): Unable to create certificates.
735 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) 777 #if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX)
736 // This test creates a self-signed cert from a private key and then verify the 778 // This test creates a self-signed cert from a private key and then verify the
737 // content of the certificate. 779 // content of the certificate.
738 TEST(X509CertificateTest, CreateSelfSigned) { 780 TEST(X509CertificateTest, CreateSelfSigned) {
739 scoped_ptr<crypto::RSAPrivateKey> private_key( 781 scoped_ptr<crypto::RSAPrivateKey> private_key(
740 crypto::RSAPrivateKey::Create(1024)); 782 crypto::RSAPrivateKey::Create(1024));
741 scoped_refptr<X509Certificate> cert = 783 scoped_refptr<X509Certificate> cert =
742 X509Certificate::CreateSelfSigned( 784 X509Certificate::CreateSelfSigned(
743 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1)); 785 private_key.get(), "CN=subject", 1, base::TimeDelta::FromDays(1));
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 } 1153 }
1112 1154
1113 EXPECT_EQ(test_data.expected, X509Certificate::VerifyHostname( 1155 EXPECT_EQ(test_data.expected, X509Certificate::VerifyHostname(
1114 test_data.hostname, common_name, dns_names, ip_addressses)); 1156 test_data.hostname, common_name, dns_names, ip_addressses));
1115 } 1157 }
1116 1158
1117 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest, 1159 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest,
1118 testing::ValuesIn(kNameVerifyTestData)); 1160 testing::ValuesIn(kNameVerifyTestData));
1119 1161
1120 } // namespace net 1162 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698