Index: net/base/cert_database_nss_unittest.cc |
diff --git a/net/base/cert_database_nss_unittest.cc b/net/base/cert_database_nss_unittest.cc |
index 8e691041e96803ef6114349a93df174b08099f9e..468c8703304e2cc4baa31fc89937069242977d47 100644 |
--- a/net/base/cert_database_nss_unittest.cc |
+++ b/net/base/cert_database_nss_unittest.cc |
@@ -20,6 +20,7 @@ |
#include "net/base/cert_database.h" |
#include "net/base/cert_status_flags.h" |
#include "net/base/cert_verify_result.h" |
+#include "net/base/crypto_module.h" |
#include "net/base/net_errors.h" |
#include "net/base/x509_certificate.h" |
#include "net/third_party/mozilla_security_manager/nsNSSCertificateDB.h" |
@@ -107,21 +108,21 @@ class CertDatabaseNSSTest : public testing::Test { |
ASSERT_TRUE(temp_db_dir_.CreateUniqueTempDir()); |
ASSERT_TRUE( |
base::OpenTestNSSDB(temp_db_dir_.path(), "CertDatabaseNSSTest db")); |
- slot_.reset(base::GetDefaultNSSKeySlot()); |
+ slot_ = cert_db_.GetDefaultModule(); |
// Test db should be empty at start of test. |
- EXPECT_EQ(0U, ListCertsInSlot(slot_.get()).size()); |
+ EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); |
} |
virtual void TearDown() { |
// Don't try to cleanup if the setup failed. |
- ASSERT_TRUE(slot_.get()); |
+ ASSERT_TRUE(slot_->os_module_handle()); |
- EXPECT_TRUE(CleanupSlotContents(slot_.get())); |
- EXPECT_EQ(0U, ListCertsInSlot(slot_.get()).size()); |
+ EXPECT_TRUE(CleanupSlotContents(slot_->os_module_handle())); |
+ EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); |
} |
protected: |
- base::ScopedPK11Slot slot_; |
+ scoped_refptr<CryptoModule> slot_; |
CertDatabase cert_db_; |
private: |
@@ -142,18 +143,22 @@ TEST_F(CertDatabaseNSSTest, ImportFromPKCS12WrongPassword) { |
std::string pkcs12_data = ReadTestFile("client.p12"); |
EXPECT_EQ(ERR_PKCS12_IMPORT_BAD_PASSWORD, |
- cert_db_.ImportFromPKCS12(pkcs12_data, ASCIIToUTF16(""))); |
+ cert_db_.ImportFromPKCS12(slot_, |
+ pkcs12_data, |
+ ASCIIToUTF16(""))); |
// Test db should still be empty. |
- EXPECT_EQ(0U, ListCertsInSlot(slot_.get()).size()); |
+ EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); |
} |
TEST_F(CertDatabaseNSSTest, ImportFromPKCS12AndExportAgain) { |
std::string pkcs12_data = ReadTestFile("client.p12"); |
- EXPECT_EQ(OK, cert_db_.ImportFromPKCS12(pkcs12_data, ASCIIToUTF16("12345"))); |
+ EXPECT_EQ(OK, cert_db_.ImportFromPKCS12(slot_, |
+ pkcs12_data, |
+ ASCIIToUTF16("12345"))); |
- CertificateList cert_list = ListCertsInSlot(slot_.get()); |
+ CertificateList cert_list = ListCertsInSlot(slot_->os_module_handle()); |
ASSERT_EQ(1U, cert_list.size()); |
scoped_refptr<X509Certificate> cert(cert_list[0]); |
@@ -184,7 +189,7 @@ TEST_F(CertDatabaseNSSTest, ImportCACert_SSLTrust) { |
EXPECT_EQ(0U, failed.size()); |
- CertificateList cert_list = ListCertsInSlot(slot_.get()); |
+ CertificateList cert_list = ListCertsInSlot(slot_->os_module_handle()); |
ASSERT_EQ(1U, cert_list.size()); |
scoped_refptr<X509Certificate> cert(cert_list[0]); |
EXPECT_EQ("Test CA", cert->subject().common_name); |
@@ -216,7 +221,7 @@ TEST_F(CertDatabaseNSSTest, ImportCACert_EmailTrust) { |
EXPECT_EQ(0U, failed.size()); |
- CertificateList cert_list = ListCertsInSlot(slot_.get()); |
+ CertificateList cert_list = ListCertsInSlot(slot_->os_module_handle()); |
ASSERT_EQ(1U, cert_list.size()); |
scoped_refptr<X509Certificate> cert(cert_list[0]); |
EXPECT_EQ("Test CA", cert->subject().common_name); |
@@ -247,7 +252,7 @@ TEST_F(CertDatabaseNSSTest, ImportCACert_ObjSignTrust) { |
EXPECT_EQ(0U, failed.size()); |
- CertificateList cert_list = ListCertsInSlot(slot_.get()); |
+ CertificateList cert_list = ListCertsInSlot(slot_->os_module_handle()); |
ASSERT_EQ(1U, cert_list.size()); |
scoped_refptr<X509Certificate> cert(cert_list[0]); |
EXPECT_EQ("Test CA", cert->subject().common_name); |
@@ -282,7 +287,7 @@ TEST_F(CertDatabaseNSSTest, ImportCA_NotCACert) { |
EXPECT_EQ(certs[0], failed[0].certificate); |
EXPECT_EQ(ERR_IMPORT_CA_CERT_NOT_CA, failed[0].net_error); |
- EXPECT_EQ(0U, ListCertsInSlot(slot_.get()).size()); |
+ EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); |
} |
TEST_F(CertDatabaseNSSTest, ImportCACertHierarchy) { |
@@ -305,7 +310,7 @@ TEST_F(CertDatabaseNSSTest, ImportCACertHierarchy) { |
EXPECT_EQ("www.us.army.mil", failed[0].certificate->subject().common_name); |
EXPECT_EQ(ERR_IMPORT_CA_CERT_NOT_CA, failed[0].net_error); |
- CertificateList cert_list = ListCertsInSlot(slot_.get()); |
+ CertificateList cert_list = ListCertsInSlot(slot_->os_module_handle()); |
ASSERT_EQ(2U, cert_list.size()); |
EXPECT_EQ("DoD Root CA 2", cert_list[0]->subject().common_name); |
EXPECT_EQ("DOD CA-17", cert_list[1]->subject().common_name); |
@@ -322,7 +327,7 @@ TEST_F(CertDatabaseNSSTest, ImportCACertHierarchyDupeRoot) { |
&failed)); |
EXPECT_EQ(0U, failed.size()); |
- CertificateList cert_list = ListCertsInSlot(slot_.get()); |
+ CertificateList cert_list = ListCertsInSlot(slot_->os_module_handle()); |
ASSERT_EQ(1U, cert_list.size()); |
EXPECT_EQ("DoD Root CA 2", cert_list[0]->subject().common_name); |
@@ -342,7 +347,7 @@ TEST_F(CertDatabaseNSSTest, ImportCACertHierarchyDupeRoot) { |
EXPECT_EQ("www.us.army.mil", failed[1].certificate->subject().common_name); |
EXPECT_EQ(ERR_IMPORT_CA_CERT_NOT_CA, failed[1].net_error); |
- cert_list = ListCertsInSlot(slot_.get()); |
+ cert_list = ListCertsInSlot(slot_->os_module_handle()); |
ASSERT_EQ(2U, cert_list.size()); |
EXPECT_EQ("DoD Root CA 2", cert_list[0]->subject().common_name); |
EXPECT_EQ("DOD CA-17", cert_list[1]->subject().common_name); |
@@ -364,7 +369,7 @@ TEST_F(CertDatabaseNSSTest, ImportCACertHierarchyUntrusted) { |
// SEC_ERROR_UNTRUSTED_ISSUER |
EXPECT_EQ(ERR_FAILED, failed[0].net_error); |
- CertificateList cert_list = ListCertsInSlot(slot_.get()); |
+ CertificateList cert_list = ListCertsInSlot(slot_->os_module_handle()); |
ASSERT_EQ(1U, cert_list.size()); |
EXPECT_EQ("DoD Root CA 2", cert_list[0]->subject().common_name); |
} |
@@ -383,7 +388,7 @@ TEST_F(CertDatabaseNSSTest, ImportCACertHierarchyTree) { |
EXPECT_EQ(0U, failed.size()); |
- CertificateList cert_list = ListCertsInSlot(slot_.get()); |
+ CertificateList cert_list = ListCertsInSlot(slot_->os_module_handle()); |
ASSERT_EQ(3U, cert_list.size()); |
EXPECT_EQ("DOD CA-13", cert_list[0]->subject().common_name); |
EXPECT_EQ("DoD Root CA 2", cert_list[1]->subject().common_name); |
@@ -413,7 +418,7 @@ TEST_F(CertDatabaseNSSTest, ImportCACertNotHierarchy) { |
EXPECT_EQ("DOD CA-17", failed[1].certificate->subject().common_name); |
EXPECT_EQ(ERR_FAILED, failed[1].net_error); |
- CertificateList cert_list = ListCertsInSlot(slot_.get()); |
+ CertificateList cert_list = ListCertsInSlot(slot_->os_module_handle()); |
ASSERT_EQ(1U, cert_list.size()); |
EXPECT_EQ("Test CA", cert_list[0]->subject().common_name); |
} |
@@ -433,7 +438,7 @@ TEST_F(CertDatabaseNSSTest, ImportServerCert) { |
EXPECT_EQ(0U, failed.size()); |
- CertificateList cert_list = ListCertsInSlot(slot_.get()); |
+ CertificateList cert_list = ListCertsInSlot(slot_->os_module_handle()); |
ASSERT_EQ(2U, cert_list.size()); |
scoped_refptr<X509Certificate> goog_cert(cert_list[0]); |
scoped_refptr<X509Certificate> thawte_cert(cert_list[1]); |
@@ -461,7 +466,7 @@ TEST_F(CertDatabaseNSSTest, ImportServerCert_SelfSigned) { |
EXPECT_EQ(0U, failed.size()); |
- CertificateList cert_list = ListCertsInSlot(slot_.get()); |
+ CertificateList cert_list = ListCertsInSlot(slot_->os_module_handle()); |
ASSERT_EQ(1U, cert_list.size()); |
scoped_refptr<X509Certificate> puny_cert(cert_list[0]); |