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

Side by Side Diff: chrome/common/net/x509_certificate_model_unittest.cc

Issue 10458069: Reland: Fix imported server certs being distrusted in NSS 3.13. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix the test failures Created 8 years, 6 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 | Annotate | Revision Log
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 "chrome/common/net/x509_certificate_model.h" 5 #include "chrome/common/net/x509_certificate_model.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "net/base/cert_database.h" 10 #include "net/base/cert_database.h"
(...skipping 10 matching lines...) Expand all
21 // Remove this when OpenSSL build implements the necessary functions. 21 // Remove this when OpenSSL build implements the necessary functions.
22 EXPECT_EQ(net::UNKNOWN_CERT, 22 EXPECT_EQ(net::UNKNOWN_CERT,
23 x509_certificate_model::GetType(cert->os_cert_handle())); 23 x509_certificate_model::GetType(cert->os_cert_handle()));
24 #else 24 #else
25 EXPECT_EQ(net::CA_CERT, 25 EXPECT_EQ(net::CA_CERT,
26 x509_certificate_model::GetType(cert->os_cert_handle())); 26 x509_certificate_model::GetType(cert->os_cert_handle()));
27 27
28 // Test that explicitly distrusted CA certs are still returned as CA_CERT 28 // Test that explicitly distrusted CA certs are still returned as CA_CERT
29 // type. See http://crbug.com/96654. 29 // type. See http://crbug.com/96654.
30 net::CertDatabase cert_db; 30 net::CertDatabase cert_db;
31 // TODO(mattm): This depends on the implementation details of SetCertTrust 31 EXPECT_TRUE(cert_db.SetCertTrust(cert, net::CA_CERT,
32 // where calling with SERVER_CERT and UNTRUSTED causes a cert to be explicitly 32 net::CertDatabase::DISTRUSTED_SSL));
33 // distrusted (trust set to CERTDB_TERMINAL_RECORD). See
34 // http://crbug.com/116411. When I fix that bug I'll also add a way to set
35 // this directly.
36 EXPECT_TRUE(cert_db.SetCertTrust(cert, net::SERVER_CERT,
37 net::CertDatabase::UNTRUSTED));
38 33
39 EXPECT_EQ(net::CA_CERT, 34 EXPECT_EQ(net::CA_CERT,
40 x509_certificate_model::GetType(cert->os_cert_handle())); 35 x509_certificate_model::GetType(cert->os_cert_handle()));
41 #endif 36 #endif
42 } 37 }
43 38
44 TEST(X509CertificateModelTest, GetTypeServer) { 39 TEST(X509CertificateModelTest, GetTypeServer) {
45 scoped_refptr<net::X509Certificate> cert( 40 scoped_refptr<net::X509Certificate> cert(
46 net::ImportCertFromFile(net::GetTestCertsDirectory(), 41 net::ImportCertFromFile(net::GetTestCertsDirectory(),
47 "google.single.der")); 42 "google.single.der"));
48 ASSERT_TRUE(cert.get()); 43 ASSERT_TRUE(cert.get());
49 44
50 #if defined(USE_OPENSSL) 45 #if defined(USE_OPENSSL)
51 // Remove this when OpenSSL build implements the necessary functions. 46 // Remove this when OpenSSL build implements the necessary functions.
52 EXPECT_EQ(net::UNKNOWN_CERT, 47 EXPECT_EQ(net::UNKNOWN_CERT,
53 x509_certificate_model::GetType(cert->os_cert_handle())); 48 x509_certificate_model::GetType(cert->os_cert_handle()));
54 #else 49 #else
55 // TODO(mattm): make GetCertType smarter so we can tell server certs even if 50 // Test mozilla_security_manager::GetCertType with server certs and default
56 // they have no trust bits set. 51 // trust. Currently this doesn't work.
52 // TODO(mattm): make mozilla_security_manager::GetCertType smarter so we can
53 // tell server certs even if they have no trust bits set.
57 EXPECT_EQ(net::UNKNOWN_CERT, 54 EXPECT_EQ(net::UNKNOWN_CERT,
58 x509_certificate_model::GetType(cert->os_cert_handle())); 55 x509_certificate_model::GetType(cert->os_cert_handle()));
59 56
60 net::CertDatabase cert_db; 57 net::CertDatabase cert_db;
58 // Test GetCertType with server certs and explicit trust.
61 EXPECT_TRUE(cert_db.SetCertTrust(cert, net::SERVER_CERT, 59 EXPECT_TRUE(cert_db.SetCertTrust(cert, net::SERVER_CERT,
62 net::CertDatabase::TRUSTED_SSL)); 60 net::CertDatabase::TRUSTED_SSL));
63 61
64 EXPECT_EQ(net::SERVER_CERT, 62 EXPECT_EQ(net::SERVER_CERT,
65 x509_certificate_model::GetType(cert->os_cert_handle())); 63 x509_certificate_model::GetType(cert->os_cert_handle()));
66 64
65 // Test GetCertType with server certs and explicit distrust.
67 EXPECT_TRUE(cert_db.SetCertTrust(cert, net::SERVER_CERT, 66 EXPECT_TRUE(cert_db.SetCertTrust(cert, net::SERVER_CERT,
68 net::CertDatabase::UNTRUSTED)); 67 net::CertDatabase::DISTRUSTED_SSL));
69 68
70 EXPECT_EQ(net::SERVER_CERT, 69 EXPECT_EQ(net::SERVER_CERT,
71 x509_certificate_model::GetType(cert->os_cert_handle())); 70 x509_certificate_model::GetType(cert->os_cert_handle()));
72 #endif 71 #endif
73 } 72 }
74 73
75 // An X.509 v1 certificate with the version field omitted should get 74 // An X.509 v1 certificate with the version field omitted should get
76 // the default value v1. 75 // the default value v1.
77 TEST(X509CertificateModelTest, GetVersionOmitted) { 76 TEST(X509CertificateModelTest, GetVersionOmitted) {
78 scoped_refptr<net::X509Certificate> cert( 77 scoped_refptr<net::X509Certificate> cert(
79 net::ImportCertFromFile(net::GetTestCertsDirectory(), 78 net::ImportCertFromFile(net::GetTestCertsDirectory(),
80 "ndn.ca.crt")); 79 "ndn.ca.crt"));
81 ASSERT_TRUE(cert.get()); 80 ASSERT_TRUE(cert.get());
82 81
83 EXPECT_EQ("1", x509_certificate_model::GetVersion(cert->os_cert_handle())); 82 EXPECT_EQ("1", x509_certificate_model::GetVersion(cert->os_cert_handle()));
84 } 83 }
OLDNEW
« no previous file with comments | « chrome/chrome_browser.gypi ('k') | chrome/third_party/mozilla_security_manager/nsNSSCertHelper.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698