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

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

Issue 401623006: Extract ScopedTestNSSDB from nss_util. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 4 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 <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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/message_loop/message_loop_proxy.h" 16 #include "base/message_loop/message_loop_proxy.h"
17 #include "base/path_service.h" 17 #include "base/path_service.h"
18 #include "base/run_loop.h" 18 #include "base/run_loop.h"
19 #include "base/strings/string16.h" 19 #include "base/strings/string16.h"
20 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
21 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
22 #include "crypto/nss_util.h"
23 #include "crypto/nss_util_internal.h"
24 #include "crypto/scoped_nss_types.h" 22 #include "crypto/scoped_nss_types.h"
23 #include "crypto/scoped_test_nss_db.h"
25 #include "net/base/crypto_module.h" 24 #include "net/base/crypto_module.h"
26 #include "net/base/net_errors.h" 25 #include "net/base/net_errors.h"
27 #include "net/base/test_data_directory.h" 26 #include "net/base/test_data_directory.h"
28 #include "net/cert/cert_status_flags.h" 27 #include "net/cert/cert_status_flags.h"
29 #include "net/cert/cert_verify_proc_nss.h" 28 #include "net/cert/cert_verify_proc_nss.h"
30 #include "net/cert/cert_verify_result.h" 29 #include "net/cert/cert_verify_result.h"
31 #include "net/cert/nss_cert_database.h" 30 #include "net/cert/nss_cert_database.h"
32 #include "net/cert/x509_certificate.h" 31 #include "net/cert/x509_certificate.h"
33 #include "net/test/cert_test_util.h" 32 #include "net/test/cert_test_util.h"
34 #include "net/third_party/mozilla_security_manager/nsNSSCertificateDB.h" 33 #include "net/third_party/mozilla_security_manager/nsNSSCertificateDB.h"
(...skipping 17 matching lines...) Expand all
52 destination->swap(*source); 51 destination->swap(*source);
53 } 52 }
54 53
55 } // namespace 54 } // namespace
56 55
57 class CertDatabaseNSSTest : public testing::Test { 56 class CertDatabaseNSSTest : public testing::Test {
58 public: 57 public:
59 virtual void SetUp() { 58 virtual void SetUp() {
60 ASSERT_TRUE(test_nssdb_.is_open()); 59 ASSERT_TRUE(test_nssdb_.is_open());
61 cert_db_.reset(new NSSCertDatabase( 60 cert_db_.reset(new NSSCertDatabase(
62 crypto::ScopedPK11Slot(crypto::GetPersistentNSSKeySlot()), 61 crypto::ScopedPK11Slot(
63 crypto::ScopedPK11Slot(crypto::GetPersistentNSSKeySlot()))); 62 PK11_ReferenceSlot(test_nssdb_.slot())) /* public slot */,
63 crypto::ScopedPK11Slot(
64 PK11_ReferenceSlot(test_nssdb_.slot())) /* private slot */));
64 public_module_ = cert_db_->GetPublicModule(); 65 public_module_ = cert_db_->GetPublicModule();
65 66
66 // Test db should be empty at start of test. 67 // Test db should be empty at start of test.
67 EXPECT_EQ(0U, ListCerts().size()); 68 EXPECT_EQ(0U, ListCerts().size());
68 } 69 }
69 70
70 virtual void TearDown() { 71 virtual void TearDown() {
71 // Run the message loop to process any observer callbacks (e.g. for the 72 // Run the message loop to process any observer callbacks (e.g. for the
72 // ClientSocketFactory singleton) so that the scoped ref ptrs created in 73 // ClientSocketFactory singleton) so that the scoped ref ptrs created in
73 // NSSCertDatabase::NotifyObservers* get released. 74 // NSSCertDatabase::NotifyObservers* get released.
(...skipping 18 matching lines...) Expand all
92 ImportCertFromFile(GetTestCertsDirectory(), name)); 93 ImportCertFromFile(GetTestCertsDirectory(), name));
93 if (!cert.get()) 94 if (!cert.get())
94 return false; 95 return false;
95 96
96 certs->push_back(cert); 97 certs->push_back(cert);
97 return true; 98 return true;
98 } 99 }
99 100
100 CertificateList ListCerts() { 101 CertificateList ListCerts() {
101 CertificateList result; 102 CertificateList result;
102 103 CERTCertList* cert_list = PK11_ListCertsInSlot(test_nssdb_.slot());
103 CERTCertList* cert_list =
104 PK11_ListCertsInSlot(cert_db_->GetPublicSlot().get());
105 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list); 104 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list);
106 !CERT_LIST_END(node, cert_list); 105 !CERT_LIST_END(node, cert_list);
107 node = CERT_LIST_NEXT(node)) { 106 node = CERT_LIST_NEXT(node)) {
108 result.push_back(X509Certificate::CreateFromHandle( 107 result.push_back(X509Certificate::CreateFromHandle(
109 node->cert, X509Certificate::OSCertHandles())); 108 node->cert, X509Certificate::OSCertHandles()));
110 } 109 }
111 CERT_DestroyCertList(cert_list); 110 CERT_DestroyCertList(cert_list);
112 111
113 // Sort the result so that test comparisons can be deterministic. 112 // Sort the result so that test comparisons can be deterministic.
114 std::sort(result.begin(), result.end(), X509Certificate::LessThan()); 113 std::sort(result.begin(), result.end(), X509Certificate::LessThan());
(...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 EXPECT_EQ(NSSCertDatabase::TRUST_DEFAULT, 1018 EXPECT_EQ(NSSCertDatabase::TRUST_DEFAULT,
1020 cert_db_->GetCertTrust(certs2[0].get(), SERVER_CERT)); 1019 cert_db_->GetCertTrust(certs2[0].get(), SERVER_CERT));
1021 1020
1022 new_certs = ListCerts(); 1021 new_certs = ListCerts();
1023 ASSERT_EQ(2U, new_certs.size()); 1022 ASSERT_EQ(2U, new_certs.size());
1024 EXPECT_STRNE(new_certs[0]->os_cert_handle()->nickname, 1023 EXPECT_STRNE(new_certs[0]->os_cert_handle()->nickname,
1025 new_certs[1]->os_cert_handle()->nickname); 1024 new_certs[1]->os_cert_handle()->nickname);
1026 } 1025 }
1027 1026
1028 } // namespace net 1027 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698