| 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/files/file_util.h" | 8 #include "base/files/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" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "crypto/nss_util_internal.h" | 12 #include "crypto/nss_util_internal.h" |
| 13 #include "crypto/scoped_nss_types.h" | 13 #include "crypto/scoped_nss_types.h" |
| 14 #include "crypto/scoped_test_nss_chromeos_user.h" | 14 #include "crypto/scoped_test_nss_chromeos_user.h" |
| 15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 16 #include "net/base/test_data_directory.h" | 16 #include "net/base/test_data_directory.h" |
| 17 #include "net/cert/nss_cert_database_chromeos.h" | 17 #include "net/cert/nss_cert_database_chromeos.h" |
| 18 #include "net/cert/x509_certificate.h" | 18 #include "net/cert/x509_certificate.h" |
| 19 #include "net/test/cert_test_util.h" | 19 #include "net/test/cert_test_util.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 21 |
| 22 // http://crbug.com/418369 |
| 23 #ifndef NDEBUG |
| 24 |
| 22 namespace chromeos { | 25 namespace chromeos { |
| 23 namespace { | 26 namespace { |
| 24 | 27 |
| 25 bool IsCertInCertificateList(const net::X509Certificate* cert, | 28 bool IsCertInCertificateList(const net::X509Certificate* cert, |
| 26 const net::CertificateList& cert_list) { | 29 const net::CertificateList& cert_list) { |
| 27 for (net::CertificateList::const_iterator it = cert_list.begin(); | 30 for (net::CertificateList::const_iterator it = cert_list.begin(); |
| 28 it != cert_list.end(); | 31 it != cert_list.end(); |
| 29 ++it) { | 32 ++it) { |
| 30 if (net::X509Certificate::IsSameOSCert((*it)->os_cert_handle(), | 33 if (net::X509Certificate::IsSameOSCert((*it)->os_cert_handle(), |
| 31 cert->os_cert_handle())) { | 34 cert->os_cert_handle())) { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 // parameter (which is irrelevant for these tests). | 168 // parameter (which is irrelevant for these tests). |
| 166 crypto::ScopedTestNSSChromeOSUser primary_user_; | 169 crypto::ScopedTestNSSChromeOSUser primary_user_; |
| 167 scoped_ptr<net::NSSCertDatabaseChromeOS> primary_db_; | 170 scoped_ptr<net::NSSCertDatabaseChromeOS> primary_db_; |
| 168 | 171 |
| 169 base::MessageLoop message_loop_; | 172 base::MessageLoop message_loop_; |
| 170 | 173 |
| 171 private: | 174 private: |
| 172 size_t certificates_loaded_events_count_; | 175 size_t certificates_loaded_events_count_; |
| 173 }; | 176 }; |
| 174 | 177 |
| 175 // http://crbug.com/418369 | |
| 176 #ifndef NDEBUG | |
| 177 TEST_F(CertLoaderTest, Basic) { | 178 TEST_F(CertLoaderTest, Basic) { |
| 178 EXPECT_FALSE(cert_loader_->CertificatesLoading()); | 179 EXPECT_FALSE(cert_loader_->CertificatesLoading()); |
| 179 EXPECT_FALSE(cert_loader_->certificates_loaded()); | 180 EXPECT_FALSE(cert_loader_->certificates_loaded()); |
| 180 EXPECT_FALSE(cert_loader_->IsHardwareBacked()); | 181 EXPECT_FALSE(cert_loader_->IsHardwareBacked()); |
| 181 | 182 |
| 182 FinishUserInitAndGetDatabase(&primary_user_, &primary_db_); | 183 FinishUserInitAndGetDatabase(&primary_user_, &primary_db_); |
| 183 | 184 |
| 184 cert_loader_->StartWithNSSDB(primary_db_.get()); | 185 cert_loader_->StartWithNSSDB(primary_db_.get()); |
| 185 | 186 |
| 186 EXPECT_FALSE(cert_loader_->certificates_loaded()); | 187 EXPECT_FALSE(cert_loader_->certificates_loaded()); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 primary_db_->GetCertTrust(certs[0].get(), net::CA_CERT)); | 309 primary_db_->GetCertTrust(certs[0].get(), net::CA_CERT)); |
| 309 ASSERT_TRUE(primary_db_->SetCertTrust( | 310 ASSERT_TRUE(primary_db_->SetCertTrust( |
| 310 certs[0].get(), net::CA_CERT, net::NSSCertDatabase::TRUSTED_SSL)); | 311 certs[0].get(), net::CA_CERT, net::NSSCertDatabase::TRUSTED_SSL)); |
| 311 | 312 |
| 312 // Cert trust change should trigger certificate reload in cert_loader_. | 313 // Cert trust change should trigger certificate reload in cert_loader_. |
| 313 ASSERT_EQ(0U, GetAndResetCertificatesLoadedEventsCount()); | 314 ASSERT_EQ(0U, GetAndResetCertificatesLoadedEventsCount()); |
| 314 base::RunLoop().RunUntilIdle(); | 315 base::RunLoop().RunUntilIdle(); |
| 315 EXPECT_EQ(1U, GetAndResetCertificatesLoadedEventsCount()); | 316 EXPECT_EQ(1U, GetAndResetCertificatesLoadedEventsCount()); |
| 316 } | 317 } |
| 317 | 318 |
| 319 } // namespace |
| 320 } // namespace chromeos |
| 321 |
| 318 #endif | 322 #endif |
| 319 | 323 |
| 320 } // namespace | |
| 321 } // namespace chromeos | |
| OLD | NEW |