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 "chrome/browser/chromeos/policy/policy_cert_verifier.h" | 5 #include "chrome/browser/chromeos/policy/policy_cert_verifier.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 namespace policy { | 28 namespace policy { |
29 | 29 |
30 class PolicyCertVerifierTest : public testing::Test { | 30 class PolicyCertVerifierTest : public testing::Test { |
31 public: | 31 public: |
32 PolicyCertVerifierTest() | 32 PolicyCertVerifierTest() |
33 : trust_anchor_used_(false), test_nss_user_("user1") {} | 33 : trust_anchor_used_(false), test_nss_user_("user1") {} |
34 | 34 |
35 virtual ~PolicyCertVerifierTest() {} | 35 virtual ~PolicyCertVerifierTest() {} |
36 | 36 |
37 virtual void SetUp() OVERRIDE { | 37 virtual void SetUp() override { |
38 ASSERT_TRUE(test_nss_user_.constructed_successfully()); | 38 ASSERT_TRUE(test_nss_user_.constructed_successfully()); |
39 test_nss_user_.FinishInit(); | 39 test_nss_user_.FinishInit(); |
40 | 40 |
41 test_cert_db_.reset(new net::NSSCertDatabaseChromeOS( | 41 test_cert_db_.reset(new net::NSSCertDatabaseChromeOS( |
42 crypto::GetPublicSlotForChromeOSUser(test_nss_user_.username_hash()), | 42 crypto::GetPublicSlotForChromeOSUser(test_nss_user_.username_hash()), |
43 crypto::GetPrivateSlotForChromeOSUser( | 43 crypto::GetPrivateSlotForChromeOSUser( |
44 test_nss_user_.username_hash(), | 44 test_nss_user_.username_hash(), |
45 base::Callback<void(crypto::ScopedPK11Slot)>()))); | 45 base::Callback<void(crypto::ScopedPK11Slot)>()))); |
46 test_cert_db_->SetSlowTaskRunnerForTest(base::MessageLoopProxy::current()); | 46 test_cert_db_->SetSlowTaskRunnerForTest(base::MessageLoopProxy::current()); |
47 | 47 |
48 cert_verifier_.reset(new PolicyCertVerifier(base::Bind( | 48 cert_verifier_.reset(new PolicyCertVerifier(base::Bind( |
49 &PolicyCertVerifierTest::OnTrustAnchorUsed, base::Unretained(this)))); | 49 &PolicyCertVerifierTest::OnTrustAnchorUsed, base::Unretained(this)))); |
50 cert_verifier_->InitializeOnIOThread(new chromeos::CertVerifyProcChromeOS( | 50 cert_verifier_->InitializeOnIOThread(new chromeos::CertVerifyProcChromeOS( |
51 crypto::GetPublicSlotForChromeOSUser(test_nss_user_.username_hash()))); | 51 crypto::GetPublicSlotForChromeOSUser(test_nss_user_.username_hash()))); |
52 | 52 |
53 test_ca_cert_ = LoadCertificate("root_ca_cert.pem", net::CA_CERT); | 53 test_ca_cert_ = LoadCertificate("root_ca_cert.pem", net::CA_CERT); |
54 ASSERT_TRUE(test_ca_cert_.get()); | 54 ASSERT_TRUE(test_ca_cert_.get()); |
55 test_server_cert_ = LoadCertificate("ok_cert.pem", net::SERVER_CERT); | 55 test_server_cert_ = LoadCertificate("ok_cert.pem", net::SERVER_CERT); |
56 ASSERT_TRUE(test_server_cert_.get()); | 56 ASSERT_TRUE(test_server_cert_.get()); |
57 test_ca_cert_list_.push_back(test_ca_cert_); | 57 test_ca_cert_list_.push_back(test_ca_cert_); |
58 } | 58 } |
59 | 59 |
60 virtual void TearDown() OVERRIDE { | 60 virtual void TearDown() override { |
61 // Destroy |cert_verifier_| before destroying the ThreadBundle, otherwise | 61 // Destroy |cert_verifier_| before destroying the ThreadBundle, otherwise |
62 // BrowserThread::CurrentlyOn checks fail. | 62 // BrowserThread::CurrentlyOn checks fail. |
63 cert_verifier_.reset(); | 63 cert_verifier_.reset(); |
64 } | 64 } |
65 | 65 |
66 protected: | 66 protected: |
67 int VerifyTestServerCert(const net::TestCompletionCallback& test_callback, | 67 int VerifyTestServerCert(const net::TestCompletionCallback& test_callback, |
68 net::CertVerifyResult* verify_result, | 68 net::CertVerifyResult* verify_result, |
69 net::CertVerifier::RequestHandle* request_handle) { | 69 net::CertVerifier::RequestHandle* request_handle) { |
70 return cert_verifier_->Verify(test_server_cert_.get(), | 70 return cert_verifier_->Verify(test_server_cert_.get(), |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 int error = VerifyTestServerCert(callback, &verify_result, &request_handle); | 226 int error = VerifyTestServerCert(callback, &verify_result, &request_handle); |
227 // Note: this hits the cached result from the first Verify() in this test. | 227 // Note: this hits the cached result from the first Verify() in this test. |
228 EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, error); | 228 EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, error); |
229 } | 229 } |
230 // The additional trust anchors were reset, thus |cert_verifier_| should not | 230 // The additional trust anchors were reset, thus |cert_verifier_| should not |
231 // signal it's usage anymore. | 231 // signal it's usage anymore. |
232 EXPECT_FALSE(WasTrustAnchorUsedAndReset()); | 232 EXPECT_FALSE(WasTrustAnchorUsedAndReset()); |
233 } | 233 } |
234 | 234 |
235 } // namespace policy | 235 } // namespace policy |
OLD | NEW |