| 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 "net/cert/nss_cert_database_chromeos.h" | 5 #include "net/cert/nss_cert_database_chromeos.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/test/scoped_task_scheduler.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "crypto/nss_util_internal.h" | 15 #include "crypto/nss_util_internal.h" |
| 14 #include "crypto/scoped_test_nss_chromeos_user.h" | 16 #include "crypto/scoped_test_nss_chromeos_user.h" |
| 15 #include "crypto/scoped_test_nss_db.h" | 17 #include "crypto/scoped_test_nss_db.h" |
| 16 #include "net/cert/cert_database.h" | 18 #include "net/cert/cert_database.h" |
| 17 #include "net/test/cert_test_util.h" | 19 #include "net/test/cert_test_util.h" |
| 18 #include "net/test/test_data_directory.h" | 20 #include "net/test/test_data_directory.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 22 |
| 21 namespace net { | 23 namespace net { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 41 | 43 |
| 42 destination->swap(*source); | 44 destination->swap(*source); |
| 43 } | 45 } |
| 44 | 46 |
| 45 } // namespace | 47 } // namespace |
| 46 | 48 |
| 47 class NSSCertDatabaseChromeOSTest : public testing::Test, | 49 class NSSCertDatabaseChromeOSTest : public testing::Test, |
| 48 public CertDatabase::Observer { | 50 public CertDatabase::Observer { |
| 49 public: | 51 public: |
| 50 NSSCertDatabaseChromeOSTest() | 52 NSSCertDatabaseChromeOSTest() |
| 51 : observer_added_(false), user_1_("user1"), user_2_("user2") {} | 53 : scoped_task_scheduler_(base::MessageLoop::current()), |
| 54 observer_added_(false), |
| 55 user_1_("user1"), |
| 56 user_2_("user2") {} |
| 52 | 57 |
| 53 void SetUp() override { | 58 void SetUp() override { |
| 54 // Initialize nss_util slots. | 59 // Initialize nss_util slots. |
| 55 ASSERT_TRUE(user_1_.constructed_successfully()); | 60 ASSERT_TRUE(user_1_.constructed_successfully()); |
| 56 ASSERT_TRUE(user_2_.constructed_successfully()); | 61 ASSERT_TRUE(user_2_.constructed_successfully()); |
| 57 user_1_.FinishInit(); | 62 user_1_.FinishInit(); |
| 58 user_2_.FinishInit(); | 63 user_2_.FinishInit(); |
| 59 | 64 |
| 60 // Create NSSCertDatabaseChromeOS for each user. | 65 // Create NSSCertDatabaseChromeOS for each user. |
| 61 db_1_.reset(new NSSCertDatabaseChromeOS( | 66 db_1_.reset(new NSSCertDatabaseChromeOS( |
| 62 crypto::GetPublicSlotForChromeOSUser(user_1_.username_hash()), | 67 crypto::GetPublicSlotForChromeOSUser(user_1_.username_hash()), |
| 63 crypto::GetPrivateSlotForChromeOSUser( | 68 crypto::GetPrivateSlotForChromeOSUser( |
| 64 user_1_.username_hash(), | 69 user_1_.username_hash(), |
| 65 base::Callback<void(crypto::ScopedPK11Slot)>()))); | 70 base::Callback<void(crypto::ScopedPK11Slot)>()))); |
| 66 db_1_->SetSlowTaskRunnerForTest(base::ThreadTaskRunnerHandle::Get()); | |
| 67 db_1_->SetSystemSlot( | 71 db_1_->SetSystemSlot( |
| 68 crypto::ScopedPK11Slot(PK11_ReferenceSlot(system_db_.slot()))); | 72 crypto::ScopedPK11Slot(PK11_ReferenceSlot(system_db_.slot()))); |
| 69 db_2_.reset(new NSSCertDatabaseChromeOS( | 73 db_2_.reset(new NSSCertDatabaseChromeOS( |
| 70 crypto::GetPublicSlotForChromeOSUser(user_2_.username_hash()), | 74 crypto::GetPublicSlotForChromeOSUser(user_2_.username_hash()), |
| 71 crypto::GetPrivateSlotForChromeOSUser( | 75 crypto::GetPrivateSlotForChromeOSUser( |
| 72 user_2_.username_hash(), | 76 user_2_.username_hash(), |
| 73 base::Callback<void(crypto::ScopedPK11Slot)>()))); | 77 base::Callback<void(crypto::ScopedPK11Slot)>()))); |
| 74 db_2_->SetSlowTaskRunnerForTest(base::ThreadTaskRunnerHandle::Get()); | |
| 75 | 78 |
| 76 // Add observer to CertDatabase for checking that notifications from | 79 // Add observer to CertDatabase for checking that notifications from |
| 77 // NSSCertDatabaseChromeOS are proxied to the CertDatabase. | 80 // NSSCertDatabaseChromeOS are proxied to the CertDatabase. |
| 78 CertDatabase::GetInstance()->AddObserver(this); | 81 CertDatabase::GetInstance()->AddObserver(this); |
| 79 observer_added_ = true; | 82 observer_added_ = true; |
| 80 } | 83 } |
| 81 | 84 |
| 82 void TearDown() override { | 85 void TearDown() override { |
| 83 if (observer_added_) | 86 if (observer_added_) |
| 84 CertDatabase::GetInstance()->RemoveObserver(this); | 87 CertDatabase::GetInstance()->RemoveObserver(this); |
| 85 } | 88 } |
| 86 | 89 |
| 87 // CertDatabase::Observer: | 90 // CertDatabase::Observer: |
| 88 void OnCertDBChanged(const X509Certificate* cert) override { | 91 void OnCertDBChanged(const X509Certificate* cert) override { |
| 89 added_ca_.push_back(cert ? cert->os_cert_handle() : NULL); | 92 added_ca_.push_back(cert ? cert->os_cert_handle() : NULL); |
| 90 } | 93 } |
| 91 | 94 |
| 92 protected: | 95 protected: |
| 96 base::test::ScopedTaskScheduler scoped_task_scheduler_; |
| 97 |
| 93 bool observer_added_; | 98 bool observer_added_; |
| 94 // Certificates that were passed to the CertDatabase observers. | 99 // Certificates that were passed to the CertDatabase observers. |
| 95 std::vector<CERTCertificate*> added_ca_; | 100 std::vector<CERTCertificate*> added_ca_; |
| 96 | 101 |
| 97 crypto::ScopedTestNSSChromeOSUser user_1_; | 102 crypto::ScopedTestNSSChromeOSUser user_1_; |
| 98 crypto::ScopedTestNSSChromeOSUser user_2_; | 103 crypto::ScopedTestNSSChromeOSUser user_2_; |
| 99 crypto::ScopedTestNSSDB system_db_; | 104 crypto::ScopedTestNSSDB system_db_; |
| 100 std::unique_ptr<NSSCertDatabaseChromeOS> db_1_; | 105 std::unique_ptr<NSSCertDatabaseChromeOS> db_1_; |
| 101 std::unique_ptr<NSSCertDatabaseChromeOS> db_2_; | 106 std::unique_ptr<NSSCertDatabaseChromeOS> db_2_; |
| 102 }; | 107 }; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 "client_2.pem", | 312 "client_2.pem", |
| 308 "client_2.pk8", | 313 "client_2.pk8", |
| 309 system_db_.slot())); | 314 system_db_.slot())); |
| 310 CertificateList certs; | 315 CertificateList certs; |
| 311 db_2_->ListCertsSync(&certs); | 316 db_2_->ListCertsSync(&certs); |
| 312 EXPECT_TRUE(IsCertInCertificateList(cert_1.get(), certs)); | 317 EXPECT_TRUE(IsCertInCertificateList(cert_1.get(), certs)); |
| 313 EXPECT_FALSE(IsCertInCertificateList(cert_2.get(), certs)); | 318 EXPECT_FALSE(IsCertInCertificateList(cert_2.get(), certs)); |
| 314 } | 319 } |
| 315 | 320 |
| 316 } // namespace net | 321 } // namespace net |
| OLD | NEW |