| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/cert_loader.h" | 5 #include "chromeos/cert_loader.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 return false; | 34 return false; |
| 35 } | 35 } |
| 36 | 36 |
| 37 void FailOnPrivateSlotCallback(crypto::ScopedPK11Slot slot) { | 37 void FailOnPrivateSlotCallback(crypto::ScopedPK11Slot slot) { |
| 38 EXPECT_FALSE(true) << "GetPrivateSlotForChromeOSUser callback called even " | 38 EXPECT_FALSE(true) << "GetPrivateSlotForChromeOSUser callback called even " |
| 39 << "though the private slot had been initialized."; | 39 << "though the private slot had been initialized."; |
| 40 } | 40 } |
| 41 | 41 |
| 42 } // namespace |
| 43 |
| 42 class CertLoaderTest : public testing::Test, | 44 class CertLoaderTest : public testing::Test, |
| 43 public CertLoader::Observer { | 45 public CertLoader::Observer { |
| 44 public: | 46 public: |
| 45 CertLoaderTest() : cert_loader_(NULL), | 47 CertLoaderTest() : cert_loader_(NULL), |
| 46 primary_user_("primary"), | 48 primary_user_("primary"), |
| 47 certificates_loaded_events_count_(0U) { | 49 certificates_loaded_events_count_(0U) { |
| 48 } | 50 } |
| 49 | 51 |
| 50 virtual ~CertLoaderTest() {} | 52 virtual ~CertLoaderTest() {} |
| 51 | 53 |
| 52 virtual void SetUp() OVERRIDE { | 54 virtual void SetUp() OVERRIDE { |
| 53 ASSERT_TRUE(primary_user_.constructed_successfully()); | 55 ASSERT_TRUE(primary_user_.constructed_successfully()); |
| 54 ASSERT_TRUE( | 56 ASSERT_TRUE( |
| 55 crypto::GetPublicSlotForChromeOSUser(primary_user_.username_hash())); | 57 crypto::GetPublicSlotForChromeOSUser(primary_user_.username_hash())); |
| 56 | 58 |
| 57 CertLoader::Initialize(); | 59 CertLoader::Initialize(); |
| 58 cert_loader_ = CertLoader::Get(); | 60 cert_loader_ = CertLoader::Get(); |
| 59 cert_loader_->AddObserver(this); | 61 cert_loader_->AddObserver(this); |
| 60 cert_loader_->SetSlowTaskRunnerForTest(message_loop_.message_loop_proxy()); | |
| 61 } | 62 } |
| 62 | 63 |
| 63 virtual void TearDown() { | 64 virtual void TearDown() { |
| 64 cert_loader_->RemoveObserver(this); | 65 cert_loader_->RemoveObserver(this); |
| 65 CertLoader::Shutdown(); | 66 CertLoader::Shutdown(); |
| 66 } | 67 } |
| 67 | 68 |
| 68 protected: | 69 protected: |
| 69 void StartCertLoaderWithPrimaryUser() { | 70 void StartCertLoaderWithPrimaryUser() { |
| 70 FinishUserInitAndGetDatabase(&primary_user_, &primary_db_); | 71 FinishUserInitAndGetDatabase(&primary_user_, &primary_db_); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 101 | 102 |
| 102 crypto::ScopedPK11Slot private_slot( | 103 crypto::ScopedPK11Slot private_slot( |
| 103 crypto::GetPrivateSlotForChromeOSUser( | 104 crypto::GetPrivateSlotForChromeOSUser( |
| 104 user->username_hash(), | 105 user->username_hash(), |
| 105 base::Bind(&FailOnPrivateSlotCallback))); | 106 base::Bind(&FailOnPrivateSlotCallback))); |
| 106 ASSERT_TRUE(private_slot); | 107 ASSERT_TRUE(private_slot); |
| 107 | 108 |
| 108 database->reset(new net::NSSCertDatabaseChromeOS( | 109 database->reset(new net::NSSCertDatabaseChromeOS( |
| 109 crypto::GetPublicSlotForChromeOSUser(user->username_hash()), | 110 crypto::GetPublicSlotForChromeOSUser(user->username_hash()), |
| 110 private_slot.Pass())); | 111 private_slot.Pass())); |
| 112 (*database)->SetSlowTaskRunnerForTest(message_loop_.message_loop_proxy()); |
| 111 } | 113 } |
| 112 | 114 |
| 113 int GetDbPrivateSlotId(net::NSSCertDatabase* db) { | 115 int GetDbPrivateSlotId(net::NSSCertDatabase* db) { |
| 114 return static_cast<int>(PK11_GetSlotID(db->GetPrivateSlot().get())); | 116 return static_cast<int>(PK11_GetSlotID(db->GetPrivateSlot().get())); |
| 115 } | 117 } |
| 116 | 118 |
| 117 void ImportCACert(const std::string& cert_file, | 119 void ImportCACert(const std::string& cert_file, |
| 118 net::NSSCertDatabase* database, | 120 net::NSSCertDatabase* database, |
| 119 net::CertificateList* imported_certs) { | 121 net::CertificateList* imported_certs) { |
| 120 ASSERT_TRUE(database); | 122 ASSERT_TRUE(database); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 primary_db_->GetCertTrust(certs[0], net::CA_CERT)); | 299 primary_db_->GetCertTrust(certs[0], net::CA_CERT)); |
| 298 ASSERT_TRUE(primary_db_->SetCertTrust( | 300 ASSERT_TRUE(primary_db_->SetCertTrust( |
| 299 certs[0], net::CA_CERT, net::NSSCertDatabase::TRUSTED_SSL)); | 301 certs[0], net::CA_CERT, net::NSSCertDatabase::TRUSTED_SSL)); |
| 300 | 302 |
| 301 // Cert trust change should trigger certificate reload in cert_loader_. | 303 // Cert trust change should trigger certificate reload in cert_loader_. |
| 302 ASSERT_EQ(0U, GetAndResetCertificatesLoadedEventsCount()); | 304 ASSERT_EQ(0U, GetAndResetCertificatesLoadedEventsCount()); |
| 303 base::RunLoop().RunUntilIdle(); | 305 base::RunLoop().RunUntilIdle(); |
| 304 EXPECT_EQ(1U, GetAndResetCertificatesLoadedEventsCount()); | 306 EXPECT_EQ(1U, GetAndResetCertificatesLoadedEventsCount()); |
| 305 } | 307 } |
| 306 | 308 |
| 307 } // namespace | |
| 308 } // namespace chromeos | 309 } // namespace chromeos |
| OLD | NEW |