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

Side by Side Diff: chrome/browser/chromeos/certificate_provider/certificate_provider_service_unittest.cc

Issue 2937553003: Make CertificateProviderService vend ClientCertIdentities directly. (Closed)
Patch Set: Created 3 years, 6 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/certificate_provider/certificate_provider_serv ice.h" 5 #include "chrome/browser/chromeos/certificate_provider/certificate_provider_serv ice.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/test/test_mock_time_task_runner.h" 14 #include "base/test/test_mock_time_task_runner.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "chrome/browser/chromeos/certificate_provider/certificate_provider.h" 16 #include "chrome/browser/chromeos/certificate_provider/certificate_provider.h"
17 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
18 #include "net/ssl/client_key_store.h"
19 #include "net/test/cert_test_util.h" 18 #include "net/test/cert_test_util.h"
20 #include "net/test/test_data_directory.h" 19 #include "net/test/test_data_directory.h"
21 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
22 21
23 namespace chromeos { 22 namespace chromeos {
24 23
25 namespace { 24 namespace {
26 25
27 const char kExtension1[] = "extension1"; 26 const char kExtension1[] = "extension1";
28 const char kExtension2[] = "extension2"; 27 const char kExtension2[] = "extension2";
29 28
30 void ExpectEmptySignatureAndStoreError(net::Error* out_error, 29 void ExpectEmptySignatureAndStoreError(net::Error* out_error,
31 net::Error error, 30 net::Error error,
32 const std::vector<uint8_t>& signature) { 31 const std::vector<uint8_t>& signature) {
33 EXPECT_TRUE(signature.empty()); 32 EXPECT_TRUE(signature.empty());
34 *out_error = error; 33 *out_error = error;
35 } 34 }
36 35
37 void ExpectOKAndStoreSignature(std::vector<uint8_t>* out_signature, 36 void ExpectOKAndStoreSignature(std::vector<uint8_t>* out_signature,
38 net::Error error, 37 net::Error error,
39 const std::vector<uint8_t>& signature) { 38 const std::vector<uint8_t>& signature) {
40 EXPECT_EQ(net::OK, error); 39 EXPECT_EQ(net::OK, error);
41 *out_signature = signature; 40 *out_signature = signature;
42 } 41 }
43 42
44 void StoreCertificates(net::CertificateList* out_certs, 43 void StoreCertificates(net::ClientCertIdentityList* out_certs,
45 const net::CertificateList& certs) { 44 net::ClientCertIdentityList certs) {
46 if (out_certs) 45 if (out_certs)
47 *out_certs = certs; 46 *out_certs = std::move(certs);
47 }
48
49 void SavePrivateKey(scoped_refptr<net::SSLPrivateKey>* out_key,
davidben 2017/06/16 00:28:25 Nit: vaguely odd that this and the above function
mattm 2017/06/16 22:34:55 Done.
50 scoped_refptr<net::SSLPrivateKey> in_key) {
51 *out_key = std::move(in_key);
48 } 52 }
49 53
50 certificate_provider::CertificateInfo CreateCertInfo( 54 certificate_provider::CertificateInfo CreateCertInfo(
51 const std::string& cert_filename) { 55 const std::string& cert_filename) {
52 certificate_provider::CertificateInfo cert_info; 56 certificate_provider::CertificateInfo cert_info;
53 cert_info.certificate = 57 cert_info.certificate =
54 net::ImportCertFromFile(net::GetTestCertsDirectory(), cert_filename); 58 net::ImportCertFromFile(net::GetTestCertsDirectory(), cert_filename);
55 EXPECT_TRUE(cert_info.certificate) << "Could not load " << cert_filename; 59 EXPECT_TRUE(cert_info.certificate) << "Could not load " << cert_filename;
56 cert_info.supported_hashes.push_back(net::SSLPrivateKey::Hash::SHA256); 60 cert_info.supported_hashes.push_back(net::SSLPrivateKey::Hash::SHA256);
57 61
58 return cert_info; 62 return cert_info;
59 } 63 }
60 64
61 bool IsKeyEqualToCertInfo(const certificate_provider::CertificateInfo& info, 65 bool IsKeyEqualToCertInfo(const certificate_provider::CertificateInfo& info,
62 net::SSLPrivateKey* key) { 66 net::SSLPrivateKey* key) {
63 return info.supported_hashes == key->GetDigestPreferences(); 67 return info.supported_hashes == key->GetDigestPreferences();
64 } 68 }
65 69
70 bool ClientCertIdentityAlphabeticSorter(
71 const std::unique_ptr<net::ClientCertIdentity>& a_identity,
72 const std::unique_ptr<net::ClientCertIdentity>& b_identity) {
73 return a_identity->certificate()->subject().GetDisplayName() <
74 b_identity->certificate()->subject().GetDisplayName();
75 }
76
66 class TestDelegate : public CertificateProviderService::Delegate { 77 class TestDelegate : public CertificateProviderService::Delegate {
67 public: 78 public:
68 enum class RequestType { NONE, SIGN, GET_CERTIFICATES }; 79 enum class RequestType { NONE, SIGN, GET_CERTIFICATES };
69 80
70 TestDelegate() {} 81 TestDelegate() {}
71 82
72 std::vector<std::string> CertificateProviderExtensions() override { 83 std::vector<std::string> CertificateProviderExtensions() override {
73 return std::vector<std::string>(provider_extensions_.begin(), 84 return std::vector<std::string>(provider_extensions_.begin(),
74 provider_extensions_.end()); 85 provider_extensions_.end());
75 } 86 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 DISALLOW_COPY_AND_ASSIGN(TestDelegate); 129 DISALLOW_COPY_AND_ASSIGN(TestDelegate);
119 }; 130 };
120 131
121 } // namespace 132 } // namespace
122 133
123 class CertificateProviderServiceTest : public testing::Test { 134 class CertificateProviderServiceTest : public testing::Test {
124 public: 135 public:
125 CertificateProviderServiceTest() 136 CertificateProviderServiceTest()
126 : task_runner_(new base::TestMockTimeTaskRunner()), 137 : task_runner_(new base::TestMockTimeTaskRunner()),
127 task_runner_handle_(task_runner_), 138 task_runner_handle_(task_runner_),
128 client_key_store_(net::ClientKeyStore::GetInstance()),
129 service_(new CertificateProviderService()), 139 service_(new CertificateProviderService()),
130 cert_info1_(CreateCertInfo("client_1.pem")), 140 cert_info1_(CreateCertInfo("client_1.pem")),
131 cert_info2_(CreateCertInfo("client_2.pem")) { 141 cert_info2_(CreateCertInfo("client_2.pem")) {
132 std::unique_ptr<TestDelegate> test_delegate(new TestDelegate); 142 std::unique_ptr<TestDelegate> test_delegate(new TestDelegate);
133 test_delegate_ = test_delegate.get(); 143 test_delegate_ = test_delegate.get();
134 service_->SetDelegate(std::move(test_delegate)); 144 service_->SetDelegate(std::move(test_delegate));
135 145
136 certificate_provider_ = service_->CreateCertificateProvider(); 146 certificate_provider_ = service_->CreateCertificateProvider();
137 EXPECT_TRUE(certificate_provider_); 147 EXPECT_TRUE(certificate_provider_);
138 148
139 test_delegate_->provider_extensions_.insert(kExtension1); 149 test_delegate_->provider_extensions_.insert(kExtension1);
140 } 150 }
141 151
142 // Triggers a GetCertificates request and returns the request id. Assumes that 152 // Triggers a GetCertificates request and returns the request id. Assumes that
143 // at least one extension is registered as a certificate provider. 153 // at least one extension is registered as a certificate provider.
144 int RequestCertificatesFromExtensions(net::CertificateList* certs) { 154 int RequestCertificatesFromExtensions(net::ClientCertIdentityList* certs) {
145 test_delegate_->ClearAndExpectRequest( 155 test_delegate_->ClearAndExpectRequest(
146 TestDelegate::RequestType::GET_CERTIFICATES); 156 TestDelegate::RequestType::GET_CERTIFICATES);
147 157
148 certificate_provider_->GetCertificates( 158 certificate_provider_->GetCertificates(
149 base::Bind(&StoreCertificates, certs)); 159 base::Bind(&StoreCertificates, certs));
150 160
151 task_runner_->RunUntilIdle(); 161 task_runner_->RunUntilIdle();
152 EXPECT_EQ(TestDelegate::RequestType::NONE, 162 EXPECT_EQ(TestDelegate::RequestType::NONE,
153 test_delegate_->expected_request_type_); 163 test_delegate_->expected_request_type_);
154 return test_delegate_->last_cert_request_id_; 164 return test_delegate_->last_cert_request_id_;
155 } 165 }
156 166
167 scoped_refptr<net::SSLPrivateKey> FetchIdentityPrivateKey(
168 net::ClientCertIdentity* identity) {
169 scoped_refptr<net::SSLPrivateKey> ssl_private_key;
170 identity->AcquirePrivateKey(base::Bind(SavePrivateKey, &ssl_private_key));
171 task_runner_->RunUntilIdle();
172 return ssl_private_key;
173 }
174
157 // Provides |cert_info1_| through kExtension1. 175 // Provides |cert_info1_| through kExtension1.
158 void ProvideDefaultCert() { 176 std::unique_ptr<net::ClientCertIdentity> ProvideDefaultCert() {
159 const int cert_request_id = RequestCertificatesFromExtensions(nullptr); 177 net::ClientCertIdentityList certs;
178 const int cert_request_id = RequestCertificatesFromExtensions(&certs);
160 SetCertificateProvidedByExtension(kExtension1, cert_request_id, 179 SetCertificateProvidedByExtension(kExtension1, cert_request_id,
161 cert_info1_); 180 cert_info1_);
162 task_runner_->RunUntilIdle(); 181 task_runner_->RunUntilIdle();
182 if (certs.empty())
183 return nullptr;
184 return std::move(certs[0]);
163 } 185 }
164 186
165 // Like service_->SetCertificatesProvidedByExtension but taking a single 187 // Like service_->SetCertificatesProvidedByExtension but taking a single
166 // CertificateInfo instead of a list. 188 // CertificateInfo instead of a list.
167 void SetCertificateProvidedByExtension( 189 void SetCertificateProvidedByExtension(
168 const std::string& extension_id, 190 const std::string& extension_id,
169 int cert_request_id, 191 int cert_request_id,
170 const certificate_provider::CertificateInfo& cert_info) { 192 const certificate_provider::CertificateInfo& cert_info) {
171 certificate_provider::CertificateInfoList infos; 193 certificate_provider::CertificateInfoList infos;
172 infos.push_back(cert_info); 194 infos.push_back(cert_info);
(...skipping 21 matching lines...) Expand all
194 if (expected_extension_id != extension_id) { 216 if (expected_extension_id != extension_id) {
195 LOG(ERROR) << "Wrong extension id. Got " << extension_id; 217 LOG(ERROR) << "Wrong extension id. Got " << extension_id;
196 return false; 218 return false;
197 } 219 }
198 return true; 220 return true;
199 } 221 }
200 222
201 scoped_refptr<base::TestMockTimeTaskRunner> task_runner_; 223 scoped_refptr<base::TestMockTimeTaskRunner> task_runner_;
202 base::ThreadTaskRunnerHandle task_runner_handle_; 224 base::ThreadTaskRunnerHandle task_runner_handle_;
203 TestDelegate* test_delegate_ = nullptr; 225 TestDelegate* test_delegate_ = nullptr;
204 net::ClientKeyStore* const client_key_store_;
205 std::unique_ptr<CertificateProvider> certificate_provider_; 226 std::unique_ptr<CertificateProvider> certificate_provider_;
206 std::unique_ptr<CertificateProviderService> service_; 227 std::unique_ptr<CertificateProviderService> service_;
207 const certificate_provider::CertificateInfo cert_info1_; 228 const certificate_provider::CertificateInfo cert_info1_;
208 const certificate_provider::CertificateInfo cert_info2_; 229 const certificate_provider::CertificateInfo cert_info2_;
209 230
210 private: 231 private:
211 DISALLOW_COPY_AND_ASSIGN(CertificateProviderServiceTest); 232 DISALLOW_COPY_AND_ASSIGN(CertificateProviderServiceTest);
212 }; 233 };
213 234
214 TEST_F(CertificateProviderServiceTest, GetCertificates) { 235 TEST_F(CertificateProviderServiceTest, GetCertificates) {
215 test_delegate_->provider_extensions_.insert(kExtension2); 236 test_delegate_->provider_extensions_.insert(kExtension2);
216 237
217 net::CertificateList certs; 238 net::ClientCertIdentityList certs;
218 const int cert_request_id = RequestCertificatesFromExtensions(&certs); 239 const int cert_request_id = RequestCertificatesFromExtensions(&certs);
219 240
220 task_runner_->RunUntilIdle(); 241 task_runner_->RunUntilIdle();
221 // No certificates set until all registered extensions replied. 242 // No certificates set until all registered extensions replied.
222 EXPECT_TRUE(certs.empty()); 243 EXPECT_TRUE(certs.empty());
223 244
224 SetCertificateProvidedByExtension(kExtension1, cert_request_id, cert_info1_); 245 SetCertificateProvidedByExtension(kExtension1, cert_request_id, cert_info1_);
225 246
226 task_runner_->RunUntilIdle(); 247 task_runner_->RunUntilIdle();
227 // No certificates set until all registered extensions replied. 248 // No certificates set until all registered extensions replied.
228 EXPECT_TRUE(certs.empty()); 249 EXPECT_TRUE(certs.empty());
229 250
230 SetCertificateProvidedByExtension(kExtension2, cert_request_id, cert_info2_); 251 SetCertificateProvidedByExtension(kExtension2, cert_request_id, cert_info2_);
231 252
232 task_runner_->RunUntilIdle(); 253 task_runner_->RunUntilIdle();
233 EXPECT_EQ(2u, certs.size()); 254 ASSERT_EQ(2u, certs.size());
234 255
235 // Verify that the ClientKeyStore returns key handles for the provide certs. 256 // Verify that the ClientCertIdentity returns key handles for the provided
236 EXPECT_TRUE( 257 // certs.
237 client_key_store_->FetchClientCertPrivateKey(*cert_info1_.certificate)); 258 EXPECT_TRUE(FetchIdentityPrivateKey(certs[0].get()));
238 EXPECT_TRUE( 259 EXPECT_TRUE(FetchIdentityPrivateKey(certs[1].get()));
239 client_key_store_->FetchClientCertPrivateKey(*cert_info2_.certificate));
240 260
241 // Deregister the extensions as certificate providers. The next 261 // Deregister the extensions as certificate providers. The next
242 // GetCertificates call must report an empty list of certs. 262 // GetCertificates call must report an empty list of certs.
243 test_delegate_->provider_extensions_.clear(); 263 test_delegate_->provider_extensions_.clear();
244 264
245 // No request expected. 265 // No request expected.
246 test_delegate_->ClearAndExpectRequest(TestDelegate::RequestType::NONE); 266 test_delegate_->ClearAndExpectRequest(TestDelegate::RequestType::NONE);
247 267
248 certificate_provider_->GetCertificates( 268 certificate_provider_->GetCertificates(
249 base::Bind(&StoreCertificates, &certs)); 269 base::Bind(&StoreCertificates, &certs));
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 std::string())); 362 std::string()));
343 363
344 EXPECT_TRUE(CheckLookUpCertificate(cert_info2_, true /* is known */, 364 EXPECT_TRUE(CheckLookUpCertificate(cert_info2_, true /* is known */,
345 true /* is currently provided */, 365 true /* is currently provided */,
346 kExtension1)); 366 kExtension1));
347 } 367 }
348 368
349 TEST_F(CertificateProviderServiceTest, GetCertificatesTimeout) { 369 TEST_F(CertificateProviderServiceTest, GetCertificatesTimeout) {
350 test_delegate_->provider_extensions_.insert(kExtension2); 370 test_delegate_->provider_extensions_.insert(kExtension2);
351 371
352 net::CertificateList certs; 372 net::ClientCertIdentityList certs;
353 const int cert_request_id = RequestCertificatesFromExtensions(&certs); 373 const int cert_request_id = RequestCertificatesFromExtensions(&certs);
354 374
355 certificate_provider::CertificateInfoList infos; 375 certificate_provider::CertificateInfoList infos;
356 SetCertificateProvidedByExtension(kExtension1, cert_request_id, cert_info1_); 376 SetCertificateProvidedByExtension(kExtension1, cert_request_id, cert_info1_);
357 377
358 task_runner_->RunUntilIdle(); 378 task_runner_->RunUntilIdle();
359 // No certificates set until all registered extensions replied or a timeout 379 // No certificates set until all registered extensions replied or a timeout
360 // occurred. 380 // occurred.
361 EXPECT_TRUE(certs.empty()); 381 EXPECT_TRUE(certs.empty());
362 382
363 task_runner_->FastForwardUntilNoTasksRemain(); 383 task_runner_->FastForwardUntilNoTasksRemain();
364 // After the timeout, only extension1_'s certificates are returned. 384 // After the timeout, only extension1_'s certificates are returned.
365 // This verifies that the timeout delay is > 0 but not how long the delay is. 385 // This verifies that the timeout delay is > 0 but not how long the delay is.
366 EXPECT_EQ(1u, certs.size()); 386 ASSERT_EQ(1u, certs.size());
367 387
368 EXPECT_TRUE( 388 EXPECT_TRUE(FetchIdentityPrivateKey(certs[0].get()));
369 client_key_store_->FetchClientCertPrivateKey(*cert_info1_.certificate));
370 } 389 }
371 390
372 TEST_F(CertificateProviderServiceTest, UnloadExtensionAfterGetCertificates) { 391 TEST_F(CertificateProviderServiceTest, UnloadExtensionAfterGetCertificates) {
373 test_delegate_->provider_extensions_.insert(kExtension2); 392 test_delegate_->provider_extensions_.insert(kExtension2);
374 393
375 const int cert_request_id = RequestCertificatesFromExtensions(nullptr); 394 net::ClientCertIdentityList certs;
395 const int cert_request_id = RequestCertificatesFromExtensions(&certs);
376 396
377 SetCertificateProvidedByExtension(kExtension1, cert_request_id, cert_info1_); 397 SetCertificateProvidedByExtension(kExtension1, cert_request_id, cert_info1_);
378 SetCertificateProvidedByExtension(kExtension2, cert_request_id, cert_info2_); 398 SetCertificateProvidedByExtension(kExtension2, cert_request_id, cert_info2_);
379 task_runner_->RunUntilIdle(); 399 task_runner_->RunUntilIdle();
380 400
401 ASSERT_EQ(2u, certs.size());
402
403 // Sort the returned certs to ensure that the test results are stable.
404 std::sort(certs.begin(), certs.end(), ClientCertIdentityAlphabeticSorter);
405
381 // Private key handles for both certificates must be available now. 406 // Private key handles for both certificates must be available now.
382 EXPECT_TRUE( 407 EXPECT_TRUE(FetchIdentityPrivateKey(certs[0].get()));
383 client_key_store_->FetchClientCertPrivateKey(*cert_info1_.certificate)); 408 EXPECT_TRUE(FetchIdentityPrivateKey(certs[1].get()));
384 EXPECT_TRUE(
385 client_key_store_->FetchClientCertPrivateKey(*cert_info2_.certificate));
386 409
387 // Unload one of the extensions. 410 // Unload one of the extensions.
388 service_->OnExtensionUnloaded(kExtension2); 411 service_->OnExtensionUnloaded(kExtension2);
389 412
390 // extension1 isn't affected by the uninstall. 413 // extension1 isn't affected by the uninstall.
391 EXPECT_TRUE( 414 EXPECT_TRUE(FetchIdentityPrivateKey(certs[0].get()));
392 client_key_store_->FetchClientCertPrivateKey(*cert_info1_.certificate));
393 // No key handles that were backed by the uninstalled extension must be 415 // No key handles that were backed by the uninstalled extension must be
394 // returned. 416 // returned.
395 EXPECT_FALSE( 417 EXPECT_FALSE(FetchIdentityPrivateKey(certs[1].get()));
396 client_key_store_->FetchClientCertPrivateKey(*cert_info2_.certificate)); 418 }
419
420 TEST_F(CertificateProviderServiceTest, DestroyServiceAfterGetCertificates) {
421 test_delegate_->provider_extensions_.insert(kExtension2);
422
423 net::ClientCertIdentityList certs;
424 const int cert_request_id = RequestCertificatesFromExtensions(&certs);
425
426 SetCertificateProvidedByExtension(kExtension1, cert_request_id, cert_info1_);
427 SetCertificateProvidedByExtension(kExtension2, cert_request_id, cert_info2_);
428 task_runner_->RunUntilIdle();
429
430 ASSERT_EQ(2u, certs.size());
431
432 // Destroy the service.
433 service_.reset();
434
435 // Private key handles for both certificates should return nullptr now.
436 EXPECT_FALSE(FetchIdentityPrivateKey(certs[0].get()));
437 EXPECT_FALSE(FetchIdentityPrivateKey(certs[1].get()));
397 } 438 }
398 439
399 TEST_F(CertificateProviderServiceTest, UnloadExtensionDuringGetCertificates) { 440 TEST_F(CertificateProviderServiceTest, UnloadExtensionDuringGetCertificates) {
400 test_delegate_->provider_extensions_.insert(kExtension2); 441 test_delegate_->provider_extensions_.insert(kExtension2);
401 442
402 net::CertificateList certs; 443 net::ClientCertIdentityList certs;
403 const int cert_request_id = RequestCertificatesFromExtensions(&certs); 444 const int cert_request_id = RequestCertificatesFromExtensions(&certs);
404 445
405 SetCertificateProvidedByExtension(kExtension1, cert_request_id, cert_info1_); 446 SetCertificateProvidedByExtension(kExtension1, cert_request_id, cert_info1_);
406 447
407 // The pending certificate request is only waiting for kExtension2. Unloading 448 // The pending certificate request is only waiting for kExtension2. Unloading
408 // that extension must cause the request to be finished. 449 // that extension must cause the request to be finished.
409 service_->OnExtensionUnloaded(kExtension2); 450 service_->OnExtensionUnloaded(kExtension2);
410 451
411 task_runner_->RunUntilIdle(); 452 task_runner_->RunUntilIdle();
412 EXPECT_EQ(1u, certs.size()); 453 EXPECT_EQ(1u, certs.size());
413 } 454 }
414 455
415 // Trying to sign data using the exposed SSLPrivateKey must cause a sign 456 // Trying to sign data using the exposed SSLPrivateKey must cause a sign
416 // request. The reply must be correctly routed back to the private key. 457 // request. The reply must be correctly routed back to the private key.
417 TEST_F(CertificateProviderServiceTest, SignRequest) { 458 TEST_F(CertificateProviderServiceTest, SignRequest) {
418 ProvideDefaultCert(); 459 std::unique_ptr<net::ClientCertIdentity> cert(ProvideDefaultCert());
davidben 2017/06/16 00:28:25 ASSERT_TRUE(cert)?
mattm 2017/06/16 22:34:55 Done.
419 460
420 scoped_refptr<net::SSLPrivateKey> private_key( 461 scoped_refptr<net::SSLPrivateKey> private_key(
421 client_key_store_->FetchClientCertPrivateKey(*cert_info1_.certificate)); 462 FetchIdentityPrivateKey(cert.get()));
422 463
423 ASSERT_TRUE(private_key); 464 ASSERT_TRUE(private_key);
424 EXPECT_TRUE(IsKeyEqualToCertInfo(cert_info1_, private_key.get())); 465 EXPECT_TRUE(IsKeyEqualToCertInfo(cert_info1_, private_key.get()));
425 466
426 test_delegate_->ClearAndExpectRequest(TestDelegate::RequestType::SIGN); 467 test_delegate_->ClearAndExpectRequest(TestDelegate::RequestType::SIGN);
427 468
428 std::vector<uint8_t> received_signature; 469 std::vector<uint8_t> received_signature;
429 private_key->SignDigest( 470 private_key->SignDigest(
430 net::SSLPrivateKey::Hash::SHA256, std::string("any input data"), 471 net::SSLPrivateKey::Hash::SHA256, std::string("any input data"),
431 base::Bind(&ExpectOKAndStoreSignature, &received_signature)); 472 base::Bind(&ExpectOKAndStoreSignature, &received_signature));
(...skipping 13 matching lines...) Expand all
445 signature_reply.push_back(5); 486 signature_reply.push_back(5);
446 signature_reply.push_back(7); 487 signature_reply.push_back(7);
447 signature_reply.push_back(8); 488 signature_reply.push_back(8);
448 service_->ReplyToSignRequest(kExtension1, sign_request_id, signature_reply); 489 service_->ReplyToSignRequest(kExtension1, sign_request_id, signature_reply);
449 490
450 task_runner_->RunUntilIdle(); 491 task_runner_->RunUntilIdle();
451 EXPECT_EQ(signature_reply, received_signature); 492 EXPECT_EQ(signature_reply, received_signature);
452 } 493 }
453 494
454 TEST_F(CertificateProviderServiceTest, UnloadExtensionDuringSign) { 495 TEST_F(CertificateProviderServiceTest, UnloadExtensionDuringSign) {
455 ProvideDefaultCert(); 496 std::unique_ptr<net::ClientCertIdentity> cert(ProvideDefaultCert());
davidben 2017/06/16 00:28:25 Ditto.
mattm 2017/06/16 22:34:55 Done.
456 497
457 scoped_refptr<net::SSLPrivateKey> private_key( 498 scoped_refptr<net::SSLPrivateKey> private_key(
458 client_key_store_->FetchClientCertPrivateKey(*cert_info1_.certificate)); 499 FetchIdentityPrivateKey(cert.get()));
459 ASSERT_TRUE(private_key); 500 ASSERT_TRUE(private_key);
460 501
461 test_delegate_->ClearAndExpectRequest(TestDelegate::RequestType::SIGN); 502 test_delegate_->ClearAndExpectRequest(TestDelegate::RequestType::SIGN);
462 503
463 net::Error error = net::OK; 504 net::Error error = net::OK;
464 private_key->SignDigest( 505 private_key->SignDigest(
465 net::SSLPrivateKey::Hash::SHA256, std::string("any input data"), 506 net::SSLPrivateKey::Hash::SHA256, std::string("any input data"),
466 base::Bind(&ExpectEmptySignatureAndStoreError, &error)); 507 base::Bind(&ExpectEmptySignatureAndStoreError, &error));
467 508
468 task_runner_->RunUntilIdle(); 509 task_runner_->RunUntilIdle();
469 510
470 // No signature received until the extension replied to the service or is 511 // No signature received until the extension replied to the service or is
471 // unloaded. 512 // unloaded.
472 EXPECT_EQ(net::OK, error); 513 EXPECT_EQ(net::OK, error);
473 514
474 // Unload the extension. 515 // Unload the extension.
475 service_->OnExtensionUnloaded(kExtension1); 516 service_->OnExtensionUnloaded(kExtension1);
476 517
477 task_runner_->RunUntilIdle(); 518 task_runner_->RunUntilIdle();
478 EXPECT_EQ(net::ERR_FAILED, error); 519 EXPECT_EQ(net::ERR_FAILED, error);
479 } 520 }
480 521
481 } // namespace chromeos 522 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698