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

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

Issue 11174006: Implement ScopedTestNSSDB instead of OpenTestNSSDB() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix another test Created 8 years, 2 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
« crypto/nss_util.cc ('K') | « crypto/nss_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <cert.h> 5 #include <cert.h>
6 #include <certdb.h> 6 #include <certdb.h>
7 #include <pk11pub.h> 7 #include <pk11pub.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 20 matching lines...) Expand all
31 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
32 32
33 // In NSS 3.13, CERTDB_VALID_PEER was renamed CERTDB_TERMINAL_RECORD. So we use 33 // In NSS 3.13, CERTDB_VALID_PEER was renamed CERTDB_TERMINAL_RECORD. So we use
34 // the new name of the macro. 34 // the new name of the macro.
35 #if !defined(CERTDB_TERMINAL_RECORD) 35 #if !defined(CERTDB_TERMINAL_RECORD)
36 #define CERTDB_TERMINAL_RECORD CERTDB_VALID_PEER 36 #define CERTDB_TERMINAL_RECORD CERTDB_VALID_PEER
37 #endif 37 #endif
38 38
39 namespace net { 39 namespace net {
40 40
41 // TODO(mattm): when https://bugzilla.mozilla.org/show_bug.cgi?id=588269 is
42 // fixed, switch back to using a separate userdb for each test.
43 // (When doing so, remember to add some standalone tests of DeleteCert since it
44 // won't be tested by TearDown anymore.)
45 class CertDatabaseNSSTest : public testing::Test { 41 class CertDatabaseNSSTest : public testing::Test {
46 public: 42 public:
47 static void SetUpTestCase() {
48 ASSERT_TRUE(crypto::OpenTestNSSDB());
49 // There is no matching TearDownTestCase call to close the test NSS DB
50 // because that would leave NSS in a potentially broken state for further
51 // tests, due to https://bugzilla.mozilla.org/show_bug.cgi?id=588269
52 }
53
54 virtual void SetUp() { 43 virtual void SetUp() {
44 test_nssdb_.reset(new crypto::ScopedTestNSSDB());
45 ASSERT_TRUE(test_nssdb_->is_open());
55 cert_db_ = NSSCertDatabase::GetInstance(); 46 cert_db_ = NSSCertDatabase::GetInstance();
56 slot_ = cert_db_->GetPublicModule(); 47 slot_ = cert_db_->GetPublicModule();
57 48
58 // Test db should be empty at start of test. 49 // Test db should be empty at start of test.
59 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); 50 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size());
60 } 51 }
61 52
62 virtual void TearDown() { 53 virtual void TearDown() {
63 // Don't try to cleanup if the setup failed. 54 // Don't try to cleanup if the setup failed.
64 ASSERT_TRUE(slot_->os_module_handle()); 55 ASSERT_TRUE(slot_->os_module_handle());
65 56
66 EXPECT_TRUE(CleanupSlotContents()); 57 EXPECT_TRUE(CleanupSlotContents());
67 58
68 // Run the message loop to process any observer callbacks (e.g. for the 59 // Run the message loop to process any observer callbacks (e.g. for the
69 // ClientSocketFactory singleton) so that the scoped ref ptrs created in 60 // ClientSocketFactory singleton) so that the scoped ref ptrs created in
70 // NSSCertDatabase::NotifyObservers* get released. 61 // NSSCertDatabase::NotifyObservers* get released.
71 MessageLoop::current()->RunAllPending(); 62 MessageLoop::current()->RunAllPending();
72 63
73 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); 64 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size());
65
66 test_nssdb_.reset();
74 } 67 }
75 68
76 protected: 69 protected:
77 static std::string ReadTestFile(const std::string& name) { 70 static std::string ReadTestFile(const std::string& name) {
78 std::string result; 71 std::string result;
79 FilePath cert_path = GetTestCertsDirectory().AppendASCII(name); 72 FilePath cert_path = GetTestCertsDirectory().AppendASCII(name);
80 EXPECT_TRUE(file_util::ReadFileToString(cert_path, &result)); 73 EXPECT_TRUE(file_util::ReadFileToString(cert_path, &result));
81 return result; 74 return result;
82 } 75 }
83 76
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 SECStatus srv = CERT_ChangeCertTrust( 115 SECStatus srv = CERT_ChangeCertTrust(
123 CERT_GetDefaultCertDB(), certs[i]->os_cert_handle(), &default_trust); 116 CERT_GetDefaultCertDB(), certs[i]->os_cert_handle(), &default_trust);
124 if (srv != SECSuccess) 117 if (srv != SECSuccess)
125 ok = false; 118 ok = false;
126 119
127 if (!cert_db_->DeleteCertAndKey(certs[i])) 120 if (!cert_db_->DeleteCertAndKey(certs[i]))
128 ok = false; 121 ok = false;
129 } 122 }
130 return ok; 123 return ok;
131 } 124 }
125
126 scoped_ptr<crypto::ScopedTestNSSDB> test_nssdb_;
Ryan Sleevi 2012/10/16 18:19:02 No need to use scoped_ptr here
Takashi Toyoshima 2012/10/17 04:58:53 Done.
132 }; 127 };
133 128
134 TEST_F(CertDatabaseNSSTest, ListCerts) { 129 TEST_F(CertDatabaseNSSTest, ListCerts) {
135 // This test isn't terribly useful, though it will at least let valgrind test 130 // This test isn't terribly useful, though it will at least let valgrind test
136 // for leaks. 131 // for leaks.
137 CertificateList certs; 132 CertificateList certs;
138 cert_db_->ListCerts(&certs); 133 cert_db_->ListCerts(&certs);
139 // The test DB is empty, but let's assume there will always be something in 134 // The test DB is empty, but let's assume there will always be something in
140 // the other slots. 135 // the other slots.
141 EXPECT_LT(0U, certs.size()); 136 EXPECT_LT(0U, certs.size());
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 921
927 // Server cert should verify. 922 // Server cert should verify.
928 CertVerifyResult verify_result2; 923 CertVerifyResult verify_result2;
929 error = verify_proc->Verify(certs[0], "127.0.0.1", flags, 924 error = verify_proc->Verify(certs[0], "127.0.0.1", flags,
930 NULL, &verify_result2); 925 NULL, &verify_result2);
931 EXPECT_EQ(OK, error); 926 EXPECT_EQ(OK, error);
932 EXPECT_EQ(0U, verify_result2.cert_status); 927 EXPECT_EQ(0U, verify_result2.cert_status);
933 } 928 }
934 929
935 } // namespace net 930 } // namespace net
OLDNEW
« crypto/nss_util.cc ('K') | « crypto/nss_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698