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

Side by Side Diff: content/browser/loader/resource_loader_unittest.cc

Issue 1304143010: Plumbing SSLPrivateKey Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 3 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 (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 "content/browser/loader/resource_loader.h" 5 #include "content/browser/loader/resource_loader.h"
6 6
7 #include "base/files/file.h" 7 #include "base/files/file.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 20 matching lines...) Expand all
31 #include "net/base/chunked_upload_data_stream.h" 31 #include "net/base/chunked_upload_data_stream.h"
32 #include "net/base/io_buffer.h" 32 #include "net/base/io_buffer.h"
33 #include "net/base/mock_file_stream.h" 33 #include "net/base/mock_file_stream.h"
34 #include "net/base/net_errors.h" 34 #include "net/base/net_errors.h"
35 #include "net/base/request_priority.h" 35 #include "net/base/request_priority.h"
36 #include "net/base/test_data_directory.h" 36 #include "net/base/test_data_directory.h"
37 #include "net/base/upload_bytes_element_reader.h" 37 #include "net/base/upload_bytes_element_reader.h"
38 #include "net/cert/x509_certificate.h" 38 #include "net/cert/x509_certificate.h"
39 #include "net/ssl/client_cert_store.h" 39 #include "net/ssl/client_cert_store.h"
40 #include "net/ssl/ssl_cert_request_info.h" 40 #include "net/ssl/ssl_cert_request_info.h"
41 #include "net/ssl/ssl_platform_key.h"
davidben 2015/09/25 20:10:11 No longer necessary?
svaldez 2015/09/28 16:54:52 Done.
42 #include "net/ssl/ssl_private_key.h"
41 #include "net/test/cert_test_util.h" 43 #include "net/test/cert_test_util.h"
42 #include "net/test/embedded_test_server/embedded_test_server.h" 44 #include "net/test/embedded_test_server/embedded_test_server.h"
43 #include "net/url_request/url_request.h" 45 #include "net/url_request/url_request.h"
44 #include "net/url_request/url_request_filter.h" 46 #include "net/url_request/url_request_filter.h"
45 #include "net/url_request/url_request_interceptor.h" 47 #include "net/url_request/url_request_interceptor.h"
46 #include "net/url_request/url_request_job_factory.h" 48 #include "net/url_request/url_request_job_factory.h"
47 #include "net/url_request/url_request_job_factory_impl.h" 49 #include "net/url_request/url_request_job_factory_impl.h"
48 #include "net/url_request/url_request_test_job.h" 50 #include "net/url_request/url_request_test_job.h"
49 #include "net/url_request/url_request_test_util.h" 51 #include "net/url_request/url_request_test_util.h"
50 #include "storage/browser/blob/shareable_file_reference.h" 52 #include "storage/browser/blob/shareable_file_reference.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 void Start() override { 158 void Start() override {
157 scoped_refptr<net::SSLCertRequestInfo> cert_request_info( 159 scoped_refptr<net::SSLCertRequestInfo> cert_request_info(
158 new net::SSLCertRequestInfo); 160 new net::SSLCertRequestInfo);
159 cert_request_info->cert_authorities = test_authorities(); 161 cert_request_info->cert_authorities = test_authorities();
160 base::ThreadTaskRunnerHandle::Get()->PostTask( 162 base::ThreadTaskRunnerHandle::Get()->PostTask(
161 FROM_HERE, 163 FROM_HERE,
162 base::Bind(&MockClientCertURLRequestJob::NotifyCertificateRequested, 164 base::Bind(&MockClientCertURLRequestJob::NotifyCertificateRequested,
163 this, cert_request_info)); 165 this, cert_request_info));
164 } 166 }
165 167
166 void ContinueWithCertificate(net::X509Certificate* cert) override { 168 void ContinueWithCertificate(net::X509Certificate* cert,
169 net::SSLPrivateKey* pkey) override {
167 net::URLRequestTestJob::Start(); 170 net::URLRequestTestJob::Start();
168 } 171 }
169 172
170 private: 173 private:
171 ~MockClientCertURLRequestJob() override {} 174 ~MockClientCertURLRequestJob() override {}
172 175
173 DISALLOW_COPY_AND_ASSIGN(MockClientCertURLRequestJob); 176 DISALLOW_COPY_AND_ASSIGN(MockClientCertURLRequestJob);
174 }; 177 };
175 178
176 class MockClientCertJobProtocolHandler 179 class MockClientCertJobProtocolHandler
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 444
442 ++call_count_; 445 ++call_count_;
443 passed_certs_ = cert_request_info->client_certs; 446 passed_certs_ = cert_request_info->client_certs;
444 delegate_ = delegate.Pass(); 447 delegate_ = delegate.Pass();
445 select_certificate_run_loop_.Quit(); 448 select_certificate_run_loop_.Quit();
446 } 449 }
447 450
448 int call_count() { return call_count_; } 451 int call_count() { return call_count_; }
449 net::CertificateList passed_certs() { return passed_certs_; } 452 net::CertificateList passed_certs() { return passed_certs_; }
450 453
451 void ContinueWithCertificate(net::X509Certificate* cert) { 454 void ContinueWithCertificate(net::X509Certificate* cert,
452 delegate_->ContinueWithCertificate(cert); 455 net::SSLPrivateKey* pkey) {
456 delegate_->ContinueWithCertificate(cert, pkey);
453 delegate_.reset(); 457 delegate_.reset();
454 } 458 }
455 459
456 void CancelCertificateSelection() { delegate_.reset(); } 460 void CancelCertificateSelection() { delegate_.reset(); }
457 461
458 private: 462 private:
459 net::CertificateList passed_certs_; 463 net::CertificateList passed_certs_;
460 int call_count_; 464 int call_count_;
461 scoped_ptr<ClientCertificateDelegate> delegate_; 465 scoped_ptr<ClientCertificateDelegate> delegate_;
462 466
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 EXPECT_EQ(1, store_request_count); 704 EXPECT_EQ(1, store_request_count);
701 EXPECT_EQ(MockClientCertURLRequestJob::test_authorities(), 705 EXPECT_EQ(MockClientCertURLRequestJob::test_authorities(),
702 store_requested_authorities); 706 store_requested_authorities);
703 707
704 // Check if the retrieved certificates were passed to the content browser 708 // Check if the retrieved certificates were passed to the content browser
705 // client. 709 // client.
706 EXPECT_EQ(1, test_client.call_count()); 710 EXPECT_EQ(1, test_client.call_count());
707 EXPECT_EQ(dummy_certs, test_client.passed_certs()); 711 EXPECT_EQ(dummy_certs, test_client.passed_certs());
708 712
709 // Continue the request. 713 // Continue the request.
710 test_client.ContinueWithCertificate(dummy_certs[0].get()); 714 test_client.ContinueWithCertificate(dummy_certs[0].get(), nullptr);
711 raw_ptr_resource_handler_->WaitForResponseComplete(); 715 raw_ptr_resource_handler_->WaitForResponseComplete();
712 EXPECT_EQ(net::OK, raw_ptr_resource_handler_->status().error()); 716 EXPECT_EQ(net::OK, raw_ptr_resource_handler_->status().error());
713 717
714 // Restore the original content browser client. 718 // Restore the original content browser client.
715 SetBrowserClientForTesting(old_client); 719 SetBrowserClientForTesting(old_client);
716 } 720 }
717 721
718 // Tests that client certificates are requested on a platform with NULL 722 // Tests that client certificates are requested on a platform with NULL
719 // ClientCertStore. 723 // ClientCertStore.
720 TEST_F(ClientCertResourceLoaderTest, WithNullStore) { 724 TEST_F(ClientCertResourceLoaderTest, WithNullStore) {
721 // Plug in test content browser client. 725 // Plug in test content browser client.
722 SelectCertificateBrowserClient test_client; 726 SelectCertificateBrowserClient test_client;
723 ContentBrowserClient* old_client = SetBrowserClientForTesting(&test_client); 727 ContentBrowserClient* old_client = SetBrowserClientForTesting(&test_client);
724 728
725 // Start the request and wait for it to pause. 729 // Start the request and wait for it to pause.
726 loader_->StartRequest(); 730 loader_->StartRequest();
727 test_client.WaitForSelectCertificate(); 731 test_client.WaitForSelectCertificate();
728 732
729 // Check if the SelectClientCertificate was called on the content browser 733 // Check if the SelectClientCertificate was called on the content browser
730 // client. 734 // client.
731 EXPECT_EQ(1, test_client.call_count()); 735 EXPECT_EQ(1, test_client.call_count());
732 EXPECT_EQ(net::CertificateList(), test_client.passed_certs()); 736 EXPECT_EQ(net::CertificateList(), test_client.passed_certs());
733 737
734 // Continue the request. 738 // Continue the request.
735 scoped_refptr<net::X509Certificate> cert( 739 scoped_refptr<net::X509Certificate> cert(
736 new net::X509Certificate("test", "test", base::Time(), base::Time())); 740 new net::X509Certificate("test", "test", base::Time(), base::Time()));
737 test_client.ContinueWithCertificate(cert.get()); 741
742 test_client.ContinueWithCertificate(cert.get(), nullptr);
738 raw_ptr_resource_handler_->WaitForResponseComplete(); 743 raw_ptr_resource_handler_->WaitForResponseComplete();
739 EXPECT_EQ(net::OK, raw_ptr_resource_handler_->status().error()); 744 EXPECT_EQ(net::OK, raw_ptr_resource_handler_->status().error());
740 745
741 // Restore the original content browser client. 746 // Restore the original content browser client.
742 SetBrowserClientForTesting(old_client); 747 SetBrowserClientForTesting(old_client);
743 } 748 }
744 749
745 // Tests that the ContentBrowserClient may cancel a certificate request. 750 // Tests that the ContentBrowserClient may cancel a certificate request.
746 TEST_F(ClientCertResourceLoaderTest, CancelSelection) { 751 TEST_F(ClientCertResourceLoaderTest, CancelSelection) {
747 // Plug in test content browser client. 752 // Plug in test content browser client.
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 ASSERT_TRUE( 1144 ASSERT_TRUE(
1140 CertStore::GetInstance()->RetrieveCert(deserialized.cert_id, &cert)); 1145 CertStore::GetInstance()->RetrieveCert(deserialized.cert_id, &cert));
1141 EXPECT_TRUE(cert->Equals(GetTestCert().get())); 1146 EXPECT_TRUE(cert->Equals(GetTestCert().get()));
1142 1147
1143 EXPECT_EQ(kTestCertError, deserialized.cert_status); 1148 EXPECT_EQ(kTestCertError, deserialized.cert_status);
1144 EXPECT_EQ(kTestConnectionStatus, deserialized.connection_status); 1149 EXPECT_EQ(kTestConnectionStatus, deserialized.connection_status);
1145 EXPECT_EQ(kTestSecurityBits, deserialized.security_bits); 1150 EXPECT_EQ(kTestSecurityBits, deserialized.security_bits);
1146 } 1151 }
1147 1152
1148 } // namespace content 1153 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698