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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 } | 41 } |
42 | 42 |
43 } // namespace | 43 } // namespace |
44 | 44 |
45 class NSSCertDatabaseChromeOSTest : public testing::Test, | 45 class NSSCertDatabaseChromeOSTest : public testing::Test, |
46 public CertDatabase::Observer { | 46 public CertDatabase::Observer { |
47 public: | 47 public: |
48 NSSCertDatabaseChromeOSTest() | 48 NSSCertDatabaseChromeOSTest() |
49 : observer_added_(false), user_1_("user1"), user_2_("user2") {} | 49 : observer_added_(false), user_1_("user1"), user_2_("user2") {} |
50 | 50 |
51 virtual void SetUp() OVERRIDE { | 51 virtual void SetUp() override { |
52 // Initialize nss_util slots. | 52 // Initialize nss_util slots. |
53 ASSERT_TRUE(user_1_.constructed_successfully()); | 53 ASSERT_TRUE(user_1_.constructed_successfully()); |
54 ASSERT_TRUE(user_2_.constructed_successfully()); | 54 ASSERT_TRUE(user_2_.constructed_successfully()); |
55 user_1_.FinishInit(); | 55 user_1_.FinishInit(); |
56 user_2_.FinishInit(); | 56 user_2_.FinishInit(); |
57 | 57 |
58 // Create NSSCertDatabaseChromeOS for each user. | 58 // Create NSSCertDatabaseChromeOS for each user. |
59 db_1_.reset(new NSSCertDatabaseChromeOS( | 59 db_1_.reset(new NSSCertDatabaseChromeOS( |
60 crypto::GetPublicSlotForChromeOSUser(user_1_.username_hash()), | 60 crypto::GetPublicSlotForChromeOSUser(user_1_.username_hash()), |
61 crypto::GetPrivateSlotForChromeOSUser( | 61 crypto::GetPrivateSlotForChromeOSUser( |
62 user_1_.username_hash(), | 62 user_1_.username_hash(), |
63 base::Callback<void(crypto::ScopedPK11Slot)>()))); | 63 base::Callback<void(crypto::ScopedPK11Slot)>()))); |
64 db_1_->SetSlowTaskRunnerForTest(base::MessageLoopProxy::current()); | 64 db_1_->SetSlowTaskRunnerForTest(base::MessageLoopProxy::current()); |
65 db_1_->SetSystemSlot( | 65 db_1_->SetSystemSlot( |
66 crypto::ScopedPK11Slot(PK11_ReferenceSlot(system_db_.slot()))); | 66 crypto::ScopedPK11Slot(PK11_ReferenceSlot(system_db_.slot()))); |
67 db_2_.reset(new NSSCertDatabaseChromeOS( | 67 db_2_.reset(new NSSCertDatabaseChromeOS( |
68 crypto::GetPublicSlotForChromeOSUser(user_2_.username_hash()), | 68 crypto::GetPublicSlotForChromeOSUser(user_2_.username_hash()), |
69 crypto::GetPrivateSlotForChromeOSUser( | 69 crypto::GetPrivateSlotForChromeOSUser( |
70 user_2_.username_hash(), | 70 user_2_.username_hash(), |
71 base::Callback<void(crypto::ScopedPK11Slot)>()))); | 71 base::Callback<void(crypto::ScopedPK11Slot)>()))); |
72 db_2_->SetSlowTaskRunnerForTest(base::MessageLoopProxy::current()); | 72 db_2_->SetSlowTaskRunnerForTest(base::MessageLoopProxy::current()); |
73 | 73 |
74 // Add observer to CertDatabase for checking that notifications from | 74 // Add observer to CertDatabase for checking that notifications from |
75 // NSSCertDatabaseChromeOS are proxied to the CertDatabase. | 75 // NSSCertDatabaseChromeOS are proxied to the CertDatabase. |
76 CertDatabase::GetInstance()->AddObserver(this); | 76 CertDatabase::GetInstance()->AddObserver(this); |
77 observer_added_ = true; | 77 observer_added_ = true; |
78 } | 78 } |
79 | 79 |
80 virtual void TearDown() OVERRIDE { | 80 virtual void TearDown() override { |
81 if (observer_added_) | 81 if (observer_added_) |
82 CertDatabase::GetInstance()->RemoveObserver(this); | 82 CertDatabase::GetInstance()->RemoveObserver(this); |
83 } | 83 } |
84 | 84 |
85 // CertDatabase::Observer: | 85 // CertDatabase::Observer: |
86 virtual void OnCertAdded(const X509Certificate* cert) OVERRIDE { | 86 virtual void OnCertAdded(const X509Certificate* cert) override { |
87 added_.push_back(cert ? cert->os_cert_handle() : NULL); | 87 added_.push_back(cert ? cert->os_cert_handle() : NULL); |
88 } | 88 } |
89 | 89 |
90 virtual void OnCertRemoved(const X509Certificate* cert) OVERRIDE {} | 90 virtual void OnCertRemoved(const X509Certificate* cert) override {} |
91 | 91 |
92 virtual void OnCACertChanged(const X509Certificate* cert) OVERRIDE { | 92 virtual void OnCACertChanged(const X509Certificate* cert) override { |
93 added_ca_.push_back(cert ? cert->os_cert_handle() : NULL); | 93 added_ca_.push_back(cert ? cert->os_cert_handle() : NULL); |
94 } | 94 } |
95 | 95 |
96 protected: | 96 protected: |
97 bool observer_added_; | 97 bool observer_added_; |
98 // Certificates that were passed to the CertDatabase observers. | 98 // Certificates that were passed to the CertDatabase observers. |
99 std::vector<CERTCertificate*> added_ca_; | 99 std::vector<CERTCertificate*> added_ca_; |
100 std::vector<CERTCertificate*> added_; | 100 std::vector<CERTCertificate*> added_; |
101 | 101 |
102 crypto::ScopedTestNSSChromeOSUser user_1_; | 102 crypto::ScopedTestNSSChromeOSUser user_1_; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 "client_2.pem", | 314 "client_2.pem", |
315 "client_2.pk8", | 315 "client_2.pk8", |
316 system_db_.slot())); | 316 system_db_.slot())); |
317 CertificateList certs; | 317 CertificateList certs; |
318 db_2_->ListCertsSync(&certs); | 318 db_2_->ListCertsSync(&certs); |
319 EXPECT_TRUE(IsCertInCertificateList(cert_1.get(), certs)); | 319 EXPECT_TRUE(IsCertInCertificateList(cert_1.get(), certs)); |
320 EXPECT_FALSE(IsCertInCertificateList(cert_2.get(), certs)); | 320 EXPECT_FALSE(IsCertInCertificateList(cert_2.get(), certs)); |
321 } | 321 } |
322 | 322 |
323 } // namespace net | 323 } // namespace net |
OLD | NEW |