OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "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 24 matching lines...) Expand all Loading... | |
35 class PolicyCertVerifierTest : public testing::Test { | 35 class PolicyCertVerifierTest : public testing::Test { |
36 public: | 36 public: |
37 PolicyCertVerifierTest() : cert_db_(NULL), trust_anchor_used_(false) {} | 37 PolicyCertVerifierTest() : cert_db_(NULL), trust_anchor_used_(false) {} |
38 | 38 |
39 virtual ~PolicyCertVerifierTest() {} | 39 virtual ~PolicyCertVerifierTest() {} |
40 | 40 |
41 virtual void SetUp() OVERRIDE { | 41 virtual void SetUp() OVERRIDE { |
42 ASSERT_TRUE(test_nssdb_.is_open()); | 42 ASSERT_TRUE(test_nssdb_.is_open()); |
43 cert_db_ = net::NSSCertDatabase::GetInstance(); | 43 cert_db_ = net::NSSCertDatabase::GetInstance(); |
44 | 44 |
45 cert_verifier_.reset(new PolicyCertVerifier(base::Bind( | 45 cert_verifier_.reset(new PolicyCertVerifier()); |
46 &PolicyCertVerifierTest::OnTrustAnchorUsed, base::Unretained(this)))); | 46 cert_verifier_subscription_ = cert_verifier_->RegisterAnchorUsedCallback( |
47 base::Bind(&PolicyCertVerifierTest::OnTrustAnchorUsed, | |
48 base::Unretained(this))); | |
47 cert_verifier_->InitializeOnIOThread(); | 49 cert_verifier_->InitializeOnIOThread(); |
48 | 50 |
49 test_ca_cert_ = LoadCertificate("root_ca_cert.pem", net::CA_CERT); | 51 test_ca_cert_ = LoadCertificate("root_ca_cert.pem", net::CA_CERT); |
50 ASSERT_TRUE(test_ca_cert_); | 52 ASSERT_TRUE(test_ca_cert_); |
51 test_server_cert_ = LoadCertificate("ok_cert.pem", net::SERVER_CERT); | 53 test_server_cert_ = LoadCertificate("ok_cert.pem", net::SERVER_CERT); |
52 ASSERT_TRUE(test_server_cert_); | 54 ASSERT_TRUE(test_server_cert_); |
53 test_ca_cert_list_.push_back(test_ca_cert_); | 55 test_ca_cert_list_.push_back(test_ca_cert_); |
54 } | 56 } |
55 | 57 |
56 virtual void TearDown() OVERRIDE { | 58 virtual void TearDown() OVERRIDE { |
57 // Destroy |cert_verifier_| before destroying the ThreadBundle, otherwise | 59 cert_verifier_subscription_.reset(); |
60 // Destroy |cert_verifier_| before destroying the ThreadBundle, otherwise | |
Joao da Silva
2013/10/16 12:44:58
indent
pneubeck (no reviews)
2013/10/22 18:47:41
Done.
| |
58 // BrowserThread::CurrentlyOn checks fail. | 61 // BrowserThread::CurrentlyOn checks fail. |
62 cert_verifier_->ShutdownOnUIThread(); | |
59 cert_verifier_.reset(); | 63 cert_verifier_.reset(); |
60 } | 64 } |
61 | 65 |
62 protected: | 66 protected: |
63 int VerifyTestServerCert(const net::TestCompletionCallback& test_callback, | 67 int VerifyTestServerCert(const net::TestCompletionCallback& test_callback, |
64 net::CertVerifyResult* verify_result, | 68 net::CertVerifyResult* verify_result, |
65 net::CertVerifier::RequestHandle* request_handle) { | 69 net::CertVerifier::RequestHandle* request_handle) { |
66 return cert_verifier_->Verify(test_server_cert_.get(), | 70 return cert_verifier_->Verify(test_server_cert_.get(), |
67 "127.0.0.1", | 71 "127.0.0.1", |
68 0, | 72 0, |
(...skipping 13 matching lines...) Expand all Loading... | |
82 // Returns whether |cert_verifier| signalled usage of one of the additional | 86 // Returns whether |cert_verifier| signalled usage of one of the additional |
83 // trust anchors (i.e. of |test_ca_cert_|) for the first time or since the | 87 // trust anchors (i.e. of |test_ca_cert_|) for the first time or since the |
84 // last call of this function. | 88 // last call of this function. |
85 bool WasTrustAnchorUsedAndReset() { | 89 bool WasTrustAnchorUsedAndReset() { |
86 base::RunLoop().RunUntilIdle(); | 90 base::RunLoop().RunUntilIdle(); |
87 bool result = trust_anchor_used_; | 91 bool result = trust_anchor_used_; |
88 trust_anchor_used_ = false; | 92 trust_anchor_used_ = false; |
89 return result; | 93 return result; |
90 } | 94 } |
91 | 95 |
96 private: | |
97 scoped_ptr<base::CallbackList<void()>::Subscription> | |
98 cert_verifier_subscription_; | |
Joao da Silva
2013/10/16 12:44:58
Can't this come below after |thread_bundle_|, sinc
pneubeck (no reviews)
2013/10/22 18:47:41
Yes. I think the reason why I moved it here vanish
| |
99 | |
100 public: | |
92 // |test_ca_cert_| is the issuer of |test_server_cert_|. | 101 // |test_ca_cert_| is the issuer of |test_server_cert_|. |
93 scoped_refptr<net::X509Certificate> test_ca_cert_; | 102 scoped_refptr<net::X509Certificate> test_ca_cert_; |
94 scoped_refptr<net::X509Certificate> test_server_cert_; | 103 scoped_refptr<net::X509Certificate> test_server_cert_; |
95 net::CertificateList test_ca_cert_list_; | 104 net::CertificateList test_ca_cert_list_; |
96 net::NSSCertDatabase* cert_db_; | 105 net::NSSCertDatabase* cert_db_; |
97 scoped_ptr<PolicyCertVerifier> cert_verifier_; | 106 scoped_ptr<PolicyCertVerifier> cert_verifier_; |
98 | 107 |
99 private: | 108 private: |
100 void OnTrustAnchorUsed() { | 109 void OnTrustAnchorUsed() { |
101 trust_anchor_used_ = true; | 110 trust_anchor_used_ = true; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 int error = VerifyTestServerCert(callback, &verify_result, &request_handle); | 234 int error = VerifyTestServerCert(callback, &verify_result, &request_handle); |
226 // Note: this hits the cached result from the first Verify() in this test. | 235 // Note: this hits the cached result from the first Verify() in this test. |
227 EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, error); | 236 EXPECT_EQ(net::ERR_CERT_AUTHORITY_INVALID, error); |
228 } | 237 } |
229 // The additional trust anchors were reset, thus |cert_verifier_| should not | 238 // The additional trust anchors were reset, thus |cert_verifier_| should not |
230 // signal it's usage anymore. | 239 // signal it's usage anymore. |
231 EXPECT_FALSE(WasTrustAnchorUsedAndReset()); | 240 EXPECT_FALSE(WasTrustAnchorUsedAndReset()); |
232 } | 241 } |
233 | 242 |
234 } // namespace policy | 243 } // namespace policy |
OLD | NEW |