OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chromeos/network/onc/onc_certificate_importer_impl.h" | 5 #include "chromeos/network/onc/onc_certificate_importer_impl.h" |
6 | 6 |
7 #include <cert.h> | 7 #include <cert.h> |
8 #include <certdb.h> | 8 #include <certdb.h> |
9 #include <keyhi.h> | 9 #include <keyhi.h> |
10 #include <pk11pub.h> | 10 #include <pk11pub.h> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/test/test_simple_task_runner.h" | 16 #include "base/test/test_simple_task_runner.h" |
17 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chromeos/network/onc/onc_test_utils.h" | 19 #include "chromeos/network/onc/onc_test_utils.h" |
| 20 #include "components/cert_database/cert_database_service_io_part.h" |
20 #include "components/onc/onc_constants.h" | 21 #include "components/onc/onc_constants.h" |
21 #include "crypto/scoped_test_nss_db.h" | 22 #include "crypto/scoped_test_nss_db.h" |
22 #include "net/base/crypto_module.h" | 23 #include "net/base/crypto_module.h" |
23 #include "net/cert/cert_type.h" | 24 #include "net/cert/cert_type.h" |
24 #include "net/cert/nss_cert_database_chromeos.h" | 25 #include "net/cert/nss_cert_database_chromeos.h" |
25 #include "net/cert/x509_certificate.h" | 26 #include "net/cert/x509_certificate.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
27 | 28 |
28 namespace chromeos { | 29 namespace chromeos { |
29 namespace onc { | 30 namespace onc { |
(...skipping 23 matching lines...) Expand all Loading... |
53 return net::SERVER_CERT; | 54 return net::SERVER_CERT; |
54 return net::OTHER_CERT; | 55 return net::OTHER_CERT; |
55 } | 56 } |
56 #else | 57 #else |
57 net::CertType GetCertType(net::X509Certificate::OSCertHandle cert) { | 58 net::CertType GetCertType(net::X509Certificate::OSCertHandle cert) { |
58 NOTIMPLEMENTED(); | 59 NOTIMPLEMENTED(); |
59 return net::OTHER_CERT; | 60 return net::OTHER_CERT; |
60 } | 61 } |
61 #endif // USE_NSS | 62 #endif // USE_NSS |
62 | 63 |
| 64 class FakeCertDatabaseServiceIOPart |
| 65 : public cert_database::CertDatabaseServiceIOPart { |
| 66 public: |
| 67 explicit FakeCertDatabaseServiceIOPart(scoped_ptr<net::NSSCertDatabase> db) { |
| 68 SetNSSCertDatabase(db.Pass()); |
| 69 } |
| 70 |
| 71 ~FakeCertDatabaseServiceIOPart() override {} |
| 72 }; |
| 73 |
63 } // namespace | 74 } // namespace |
64 | 75 |
65 class ONCCertificateImporterImplTest : public testing::Test { | 76 class ONCCertificateImporterImplTest : public testing::Test { |
66 public: | 77 public: |
67 ONCCertificateImporterImplTest() {} | 78 ONCCertificateImporterImplTest() {} |
68 virtual ~ONCCertificateImporterImplTest() {} | 79 virtual ~ONCCertificateImporterImplTest() {} |
69 | 80 |
70 virtual void SetUp() override { | 81 virtual void SetUp() override { |
71 ASSERT_TRUE(public_nssdb_.is_open()); | 82 ASSERT_TRUE(public_nssdb_.is_open()); |
72 ASSERT_TRUE(private_nssdb_.is_open()); | 83 ASSERT_TRUE(private_nssdb_.is_open()); |
73 | 84 |
74 task_runner_ = new base::TestSimpleTaskRunner(); | 85 task_runner_ = new base::TestSimpleTaskRunner(); |
75 thread_task_runner_handle_.reset( | 86 thread_task_runner_handle_.reset( |
76 new base::ThreadTaskRunnerHandle(task_runner_)); | 87 new base::ThreadTaskRunnerHandle(task_runner_)); |
77 | 88 |
78 test_nssdb_.reset(new net::NSSCertDatabaseChromeOS( | 89 scoped_ptr<net::NSSCertDatabase> nss_db(new net::NSSCertDatabaseChromeOS( |
79 crypto::ScopedPK11Slot(PK11_ReferenceSlot(public_nssdb_.slot())), | 90 crypto::ScopedPK11Slot(PK11_ReferenceSlot(public_nssdb_.slot())), |
80 crypto::ScopedPK11Slot(PK11_ReferenceSlot(private_nssdb_.slot())))); | 91 crypto::ScopedPK11Slot(PK11_ReferenceSlot(private_nssdb_.slot())))); |
| 92 cert_db_io_.reset(new FakeCertDatabaseServiceIOPart(nss_db.Pass())); |
81 | 93 |
82 // Test db should be empty at start of test. | 94 // Test db should be empty at start of test. |
83 EXPECT_TRUE(ListCertsInPublicSlot().empty()); | 95 EXPECT_TRUE(ListCertsInPublicSlot().empty()); |
84 EXPECT_TRUE(ListCertsInPrivateSlot().empty()); | 96 EXPECT_TRUE(ListCertsInPrivateSlot().empty()); |
85 } | 97 } |
86 | 98 |
87 virtual void TearDown() override { | 99 virtual void TearDown() override { |
88 thread_task_runner_handle_.reset(); | 100 thread_task_runner_handle_.reset(); |
89 task_runner_ = NULL; | 101 task_runner_ = NULL; |
90 } | 102 } |
(...skipping 10 matching lines...) Expand all Loading... |
101 scoped_ptr<base::DictionaryValue> onc = | 113 scoped_ptr<base::DictionaryValue> onc = |
102 test_utils::ReadTestDictionary(filename); | 114 test_utils::ReadTestDictionary(filename); |
103 scoped_ptr<base::Value> certificates_value; | 115 scoped_ptr<base::Value> certificates_value; |
104 base::ListValue* certificates = NULL; | 116 base::ListValue* certificates = NULL; |
105 onc->RemoveWithoutPathExpansion(::onc::toplevel_config::kCertificates, | 117 onc->RemoveWithoutPathExpansion(::onc::toplevel_config::kCertificates, |
106 &certificates_value); | 118 &certificates_value); |
107 certificates_value.release()->GetAsList(&certificates); | 119 certificates_value.release()->GetAsList(&certificates); |
108 onc_certificates_.reset(certificates); | 120 onc_certificates_.reset(certificates); |
109 | 121 |
110 web_trust_certificates_.clear(); | 122 web_trust_certificates_.clear(); |
111 CertificateImporterImpl importer(task_runner_, test_nssdb_.get()); | 123 CertificateImporterImpl importer(task_runner_, cert_db_io_->GetWeakPtr()); |
112 importer.ImportCertificates( | 124 importer.ImportCertificates( |
113 *certificates, | 125 *certificates, |
114 ::onc::ONC_SOURCE_USER_IMPORT, // allow web trust | 126 ::onc::ONC_SOURCE_USER_IMPORT, // allow web trust |
115 base::Bind(&ONCCertificateImporterImplTest::OnImportCompleted, | 127 base::Bind(&ONCCertificateImporterImplTest::OnImportCompleted, |
116 base::Unretained(this), | 128 base::Unretained(this), |
117 expected_success)); | 129 expected_success)); |
118 | 130 |
119 task_runner_->RunUntilIdle(); | 131 task_runner_->RunUntilIdle(); |
120 | 132 |
121 public_list_ = ListCertsInPublicSlot(); | 133 public_list_ = ListCertsInPublicSlot(); |
(...skipping 24 matching lines...) Expand all Loading... |
146 certificate->GetStringWithoutPathExpansion(::onc::certificate::kGUID, guid); | 158 certificate->GetStringWithoutPathExpansion(::onc::certificate::kGUID, guid); |
147 } | 159 } |
148 | 160 |
149 // Certificates and the NSSCertDatabase depend on these test DBs. Destroy them | 161 // Certificates and the NSSCertDatabase depend on these test DBs. Destroy them |
150 // last. | 162 // last. |
151 crypto::ScopedTestNSSDB public_nssdb_; | 163 crypto::ScopedTestNSSDB public_nssdb_; |
152 crypto::ScopedTestNSSDB private_nssdb_; | 164 crypto::ScopedTestNSSDB private_nssdb_; |
153 | 165 |
154 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 166 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
155 scoped_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_; | 167 scoped_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_; |
156 scoped_ptr<net::NSSCertDatabaseChromeOS> test_nssdb_; | 168 scoped_ptr<FakeCertDatabaseServiceIOPart> cert_db_io_; |
157 scoped_ptr<base::ListValue> onc_certificates_; | 169 scoped_ptr<base::ListValue> onc_certificates_; |
158 // List of certs in the nssdb's public slot. | 170 // List of certs in the nssdb's public slot. |
159 net::CertificateList public_list_; | 171 net::CertificateList public_list_; |
160 // List of certs in the nssdb's "private" slot. | 172 // List of certs in the nssdb's "private" slot. |
161 net::CertificateList private_list_; | 173 net::CertificateList private_list_; |
162 net::CertificateList web_trust_certificates_; | 174 net::CertificateList web_trust_certificates_; |
163 | 175 |
164 private: | 176 private: |
165 net::CertificateList ListCertsInPublicSlot() { | 177 net::CertificateList ListCertsInPublicSlot() { |
166 return ListCertsInSlot(public_nssdb_.slot()); | 178 return ListCertsInSlot(public_nssdb_.slot()); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 "certificate-client-update.onc"), | 353 "certificate-client-update.onc"), |
342 CertParam(net::SERVER_CERT, | 354 CertParam(net::SERVER_CERT, |
343 "certificate-server.onc", | 355 "certificate-server.onc", |
344 "certificate-server-update.onc"), | 356 "certificate-server-update.onc"), |
345 CertParam(net::CA_CERT, | 357 CertParam(net::CA_CERT, |
346 "certificate-web-authority.onc", | 358 "certificate-web-authority.onc", |
347 "certificate-web-authority-update.onc"))); | 359 "certificate-web-authority-update.onc"))); |
348 | 360 |
349 } // namespace onc | 361 } // namespace onc |
350 } // namespace chromeos | 362 } // namespace chromeos |
OLD | NEW |