Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <cert.h> | 5 #include <cert.h> |
| 6 #include <pk11pub.h> | 6 #include <pk11pub.h> |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 | 9 |
| 10 #include "base/crypto/scoped_nss_types.h" | 10 #include "base/crypto/scoped_nss_types.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 } | 96 } |
| 97 | 97 |
| 98 } // namespace | 98 } // namespace |
| 99 | 99 |
| 100 // TODO(mattm): when https://bugzilla.mozilla.org/show_bug.cgi?id=588269 is | 100 // TODO(mattm): when https://bugzilla.mozilla.org/show_bug.cgi?id=588269 is |
| 101 // fixed, switch back to using a separate userdb for each test. | 101 // fixed, switch back to using a separate userdb for each test. |
| 102 // (When doing so, remember to add some standalone tests of DeleteCert since it | 102 // (When doing so, remember to add some standalone tests of DeleteCert since it |
| 103 // won't be tested by TearDown anymore.) | 103 // won't be tested by TearDown anymore.) |
| 104 class CertDatabaseNSSTest : public testing::Test { | 104 class CertDatabaseNSSTest : public testing::Test { |
| 105 public: | 105 public: |
| 106 virtual void SetUp() { | 106 virtual void SetUp() { |
|
M-A Ruel
2010/12/10 14:52:18
Isn't there already a base class that creates a te
| |
| 107 if (!temp_db_initialized_) { | 107 if (!temp_db_dir_.get()) { |
| 108 ScopedTempDir* temp_db_dir = Singleton< | 108 temp_db_dir_.reset(new ScopedTempDir()); |
| 109 ScopedTempDir, | 109 ASSERT_TRUE(temp_db_dir_->CreateUniqueTempDir()); |
| 110 DefaultSingletonTraits<ScopedTempDir>, | |
| 111 CertDatabaseNSSTest>::get(); | |
| 112 ASSERT_TRUE(temp_db_dir->CreateUniqueTempDir()); | |
| 113 ASSERT_TRUE( | 110 ASSERT_TRUE( |
| 114 base::OpenTestNSSDB(temp_db_dir->path(), "CertDatabaseNSSTest db")); | 111 base::OpenTestNSSDB(temp_db_dir_->path(), "CertDatabaseNSSTest db")); |
| 115 temp_db_initialized_ = true; | |
| 116 } | 112 } |
| 117 slot_.reset(base::GetDefaultNSSKeySlot()); | 113 slot_.reset(base::GetDefaultNSSKeySlot()); |
| 118 | 114 |
| 119 // Test db should be empty at start of test. | 115 // Test db should be empty at start of test. |
| 120 EXPECT_EQ(0U, ListCertsInSlot(slot_.get()).size()); | 116 EXPECT_EQ(0U, ListCertsInSlot(slot_.get()).size()); |
| 121 } | 117 } |
| 122 virtual void TearDown() { | 118 virtual void TearDown() { |
| 123 // Don't try to cleanup if the setup failed. | 119 // Don't try to cleanup if the setup failed. |
| 124 ASSERT_TRUE(temp_db_initialized_); | 120 ASSERT_TRUE(temp_db_dir_.get()); |
| 125 ASSERT_TRUE(slot_.get()); | 121 ASSERT_TRUE(slot_.get()); |
| 126 | 122 |
| 127 EXPECT_TRUE(CleanupSlotContents(slot_.get())); | 123 EXPECT_TRUE(CleanupSlotContents(slot_.get())); |
| 128 EXPECT_EQ(0U, ListCertsInSlot(slot_.get()).size()); | 124 EXPECT_EQ(0U, ListCertsInSlot(slot_.get()).size()); |
| 129 } | 125 } |
| 130 | 126 |
| 131 protected: | 127 protected: |
| 132 base::ScopedPK11Slot slot_; | 128 base::ScopedPK11Slot slot_; |
| 133 CertDatabase cert_db_; | 129 CertDatabase cert_db_; |
| 134 | 130 |
| 135 private: | 131 private: |
| 136 static bool temp_db_initialized_; | 132 static scoped_ptr<ScopedTempDir> temp_db_dir_; |
| 137 }; | 133 }; |
| 138 | 134 |
| 139 // static | 135 // static |
| 140 bool CertDatabaseNSSTest::temp_db_initialized_ = false; | 136 scoped_ptr<ScopedTempDir> CertDatabaseNSSTest::temp_db_dir_; |
|
M-A Ruel
2010/12/10 14:52:18
And why do you think it's better to use a scoped_p
Satish
2010/12/10 15:04:57
When getting rid of the singleton I considered eit
M-A Ruel
2010/12/10 15:09:42
I'm simply afraid of showing bad use cases. A glob
Satish
2010/12/10 16:10:11
I agree, though this is really just declaring the
M-A Ruel
2010/12/10 16:18:37
A class member variable. Creating the directory on
Satish
2010/12/10 17:13:48
Done.
| |
| 141 | 137 |
| 142 TEST_F(CertDatabaseNSSTest, ListCerts) { | 138 TEST_F(CertDatabaseNSSTest, ListCerts) { |
| 143 // This test isn't terribly useful, though it will at least let valgrind test | 139 // This test isn't terribly useful, though it will at least let valgrind test |
| 144 // for leaks. | 140 // for leaks. |
| 145 CertificateList certs; | 141 CertificateList certs; |
| 146 cert_db_.ListCerts(&certs); | 142 cert_db_.ListCerts(&certs); |
| 147 // The test DB is empty, but let's assume there will always be something in | 143 // The test DB is empty, but let's assume there will always be something in |
| 148 // the other slots. | 144 // the other slots. |
| 149 EXPECT_LT(0U, certs.size()); | 145 EXPECT_LT(0U, certs.size()); |
| 150 } | 146 } |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 493 puny_cert.get(), CA_CERT, | 489 puny_cert.get(), CA_CERT, |
| 494 CertDatabase::TRUSTED_SSL | CertDatabase::TRUSTED_EMAIL)); | 490 CertDatabase::TRUSTED_SSL | CertDatabase::TRUSTED_EMAIL)); |
| 495 | 491 |
| 496 verify_result.Reset(); | 492 verify_result.Reset(); |
| 497 error = puny_cert->Verify("xn--wgv71a119e.com", flags, &verify_result); | 493 error = puny_cert->Verify("xn--wgv71a119e.com", flags, &verify_result); |
| 498 EXPECT_EQ(OK, error); | 494 EXPECT_EQ(OK, error); |
| 499 EXPECT_EQ(0, verify_result.cert_status); | 495 EXPECT_EQ(0, verify_result.cert_status); |
| 500 } | 496 } |
| 501 | 497 |
| 502 } // namespace net | 498 } // namespace net |
| OLD | NEW |