Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Side by Side Diff: net/cert/nss_cert_database_chromeos_unittest.cc

Issue 2363653002: Cleanup unreachable cert adding code (Closed)
Patch Set: Rebased Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/cert/nss_cert_database.cc ('k') | net/quic/chromium/quic_stream_factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 CertDatabase::GetInstance()->AddObserver(this); 78 CertDatabase::GetInstance()->AddObserver(this);
79 observer_added_ = true; 79 observer_added_ = true;
80 } 80 }
81 81
82 void TearDown() override { 82 void TearDown() override {
83 if (observer_added_) 83 if (observer_added_)
84 CertDatabase::GetInstance()->RemoveObserver(this); 84 CertDatabase::GetInstance()->RemoveObserver(this);
85 } 85 }
86 86
87 // CertDatabase::Observer: 87 // CertDatabase::Observer:
88 void OnCertAdded(const X509Certificate* cert) override { 88 void OnCertDBChanged(const X509Certificate* cert) override {
89 added_.push_back(cert ? cert->os_cert_handle() : NULL);
90 }
91
92 void OnCertRemoved(const X509Certificate* cert) override {}
93
94 void OnCACertChanged(const X509Certificate* cert) override {
95 added_ca_.push_back(cert ? cert->os_cert_handle() : NULL); 89 added_ca_.push_back(cert ? cert->os_cert_handle() : NULL);
96 } 90 }
97 91
98 protected: 92 protected:
99 bool observer_added_; 93 bool observer_added_;
100 // Certificates that were passed to the CertDatabase observers. 94 // Certificates that were passed to the CertDatabase observers.
101 std::vector<CERTCertificate*> added_ca_; 95 std::vector<CERTCertificate*> added_ca_;
102 std::vector<CERTCertificate*> added_;
103 96
104 crypto::ScopedTestNSSChromeOSUser user_1_; 97 crypto::ScopedTestNSSChromeOSUser user_1_;
105 crypto::ScopedTestNSSChromeOSUser user_2_; 98 crypto::ScopedTestNSSChromeOSUser user_2_;
106 crypto::ScopedTestNSSDB system_db_; 99 crypto::ScopedTestNSSDB system_db_;
107 std::unique_ptr<NSSCertDatabaseChromeOS> db_1_; 100 std::unique_ptr<NSSCertDatabaseChromeOS> db_1_;
108 std::unique_ptr<NSSCertDatabaseChromeOS> db_2_; 101 std::unique_ptr<NSSCertDatabaseChromeOS> db_2_;
109 }; 102 };
110 103
111 // Test that ListModules() on each user includes that user's NSS software slot, 104 // Test that ListModules() on each user includes that user's NSS software slot,
112 // and does not include the software slot of the other user. (Does not check the 105 // and does not include the software slot of the other user. (Does not check the
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // Check that the imported certs only shows up in the list for the user that 166 // Check that the imported certs only shows up in the list for the user that
174 // imported them. 167 // imported them.
175 EXPECT_TRUE(IsCertInCertificateList(certs_1[0].get(), user_1_certlist)); 168 EXPECT_TRUE(IsCertInCertificateList(certs_1[0].get(), user_1_certlist));
176 EXPECT_FALSE(IsCertInCertificateList(certs_1[0].get(), user_2_certlist)); 169 EXPECT_FALSE(IsCertInCertificateList(certs_1[0].get(), user_2_certlist));
177 170
178 EXPECT_TRUE(IsCertInCertificateList(certs_2[0].get(), user_2_certlist)); 171 EXPECT_TRUE(IsCertInCertificateList(certs_2[0].get(), user_2_certlist));
179 EXPECT_FALSE(IsCertInCertificateList(certs_2[0].get(), user_1_certlist)); 172 EXPECT_FALSE(IsCertInCertificateList(certs_2[0].get(), user_1_certlist));
180 173
181 // Run the message loop so the observer notifications get processed. 174 // Run the message loop so the observer notifications get processed.
182 base::RunLoop().RunUntilIdle(); 175 base::RunLoop().RunUntilIdle();
183 // Should have gotten two OnCACertChanged notifications. 176 // Should have gotten two OnCertDBChanged notifications.
184 ASSERT_EQ(2U, added_ca_.size()); 177 ASSERT_EQ(2U, added_ca_.size());
185 // TODO(mattm): make NSSCertDatabase actually pass the cert to the callback, 178 // TODO(mattm): make NSSCertDatabase actually pass the cert to the callback,
186 // and enable these checks: 179 // and enable these checks:
187 // EXPECT_EQ(certs_1[0]->os_cert_handle(), added_ca_[0]); 180 // EXPECT_EQ(certs_1[0]->os_cert_handle(), added_ca_[0]);
188 // EXPECT_EQ(certs_2[0]->os_cert_handle(), added_ca_[1]); 181 // EXPECT_EQ(certs_2[0]->os_cert_handle(), added_ca_[1]);
189 EXPECT_EQ(0U, added_.size());
190 182
191 // Tests that the new certs are loaded by async ListCerts method. 183 // Tests that the new certs are loaded by async ListCerts method.
192 CertificateList user_1_certlist_async; 184 CertificateList user_1_certlist_async;
193 CertificateList user_2_certlist_async; 185 CertificateList user_2_certlist_async;
194 db_1_->ListCerts( 186 db_1_->ListCerts(
195 base::Bind(&SwapCertLists, base::Unretained(&user_1_certlist_async))); 187 base::Bind(&SwapCertLists, base::Unretained(&user_1_certlist_async)));
196 db_2_->ListCerts( 188 db_2_->ListCerts(
197 base::Bind(&SwapCertLists, base::Unretained(&user_2_certlist_async))); 189 base::Bind(&SwapCertLists, base::Unretained(&user_2_certlist_async)));
198 190
199 base::RunLoop().RunUntilIdle(); 191 base::RunLoop().RunUntilIdle();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 EXPECT_FALSE(IsCertInCertificateList(certs_1[0].get(), user_2_certlist)); 236 EXPECT_FALSE(IsCertInCertificateList(certs_1[0].get(), user_2_certlist));
245 237
246 EXPECT_TRUE(IsCertInCertificateList(certs_2[0].get(), user_2_certlist)); 238 EXPECT_TRUE(IsCertInCertificateList(certs_2[0].get(), user_2_certlist));
247 EXPECT_FALSE(IsCertInCertificateList(certs_2[0].get(), user_1_certlist)); 239 EXPECT_FALSE(IsCertInCertificateList(certs_2[0].get(), user_1_certlist));
248 240
249 // Run the message loop so the observer notifications get processed. 241 // Run the message loop so the observer notifications get processed.
250 base::RunLoop().RunUntilIdle(); 242 base::RunLoop().RunUntilIdle();
251 // TODO(mattm): ImportServerCert doesn't actually cause any observers to 243 // TODO(mattm): ImportServerCert doesn't actually cause any observers to
252 // fire. Is that correct? 244 // fire. Is that correct?
253 EXPECT_EQ(0U, added_ca_.size()); 245 EXPECT_EQ(0U, added_ca_.size());
254 EXPECT_EQ(0U, added_.size());
255 246
256 // Tests that the new certs are loaded by async ListCerts method. 247 // Tests that the new certs are loaded by async ListCerts method.
257 CertificateList user_1_certlist_async; 248 CertificateList user_1_certlist_async;
258 CertificateList user_2_certlist_async; 249 CertificateList user_2_certlist_async;
259 db_1_->ListCerts( 250 db_1_->ListCerts(
260 base::Bind(&SwapCertLists, base::Unretained(&user_1_certlist_async))); 251 base::Bind(&SwapCertLists, base::Unretained(&user_1_certlist_async)));
261 db_2_->ListCerts( 252 db_2_->ListCerts(
262 base::Bind(&SwapCertLists, base::Unretained(&user_2_certlist_async))); 253 base::Bind(&SwapCertLists, base::Unretained(&user_2_certlist_async)));
263 254
264 base::RunLoop().RunUntilIdle(); 255 base::RunLoop().RunUntilIdle();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 "client_2.pem", 307 "client_2.pem",
317 "client_2.pk8", 308 "client_2.pk8",
318 system_db_.slot())); 309 system_db_.slot()));
319 CertificateList certs; 310 CertificateList certs;
320 db_2_->ListCertsSync(&certs); 311 db_2_->ListCertsSync(&certs);
321 EXPECT_TRUE(IsCertInCertificateList(cert_1.get(), certs)); 312 EXPECT_TRUE(IsCertInCertificateList(cert_1.get(), certs));
322 EXPECT_FALSE(IsCertInCertificateList(cert_2.get(), certs)); 313 EXPECT_FALSE(IsCertInCertificateList(cert_2.get(), certs));
323 } 314 }
324 315
325 } // namespace net 316 } // namespace net
OLDNEW
« no previous file with comments | « net/cert/nss_cert_database.cc ('k') | net/quic/chromium/quic_stream_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698