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

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: Fixing unused function in Android. Created 5 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
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_private_key.h"
41 #include "net/test/cert_test_util.h" 42 #include "net/test/cert_test_util.h"
42 #include "net/test/embedded_test_server/embedded_test_server.h" 43 #include "net/test/embedded_test_server/embedded_test_server.h"
43 #include "net/url_request/url_request.h" 44 #include "net/url_request/url_request.h"
44 #include "net/url_request/url_request_filter.h" 45 #include "net/url_request/url_request_filter.h"
45 #include "net/url_request/url_request_interceptor.h" 46 #include "net/url_request/url_request_interceptor.h"
46 #include "net/url_request/url_request_job_factory.h" 47 #include "net/url_request/url_request_job_factory.h"
47 #include "net/url_request/url_request_job_factory_impl.h" 48 #include "net/url_request/url_request_job_factory_impl.h"
48 #include "net/url_request/url_request_test_job.h" 49 #include "net/url_request/url_request_test_job.h"
49 #include "net/url_request/url_request_test_util.h" 50 #include "net/url_request/url_request_test_util.h"
50 #include "storage/browser/blob/shareable_file_reference.h" 51 #include "storage/browser/blob/shareable_file_reference.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 void Start() override { 157 void Start() override {
157 scoped_refptr<net::SSLCertRequestInfo> cert_request_info( 158 scoped_refptr<net::SSLCertRequestInfo> cert_request_info(
158 new net::SSLCertRequestInfo); 159 new net::SSLCertRequestInfo);
159 cert_request_info->cert_authorities = test_authorities(); 160 cert_request_info->cert_authorities = test_authorities();
160 base::ThreadTaskRunnerHandle::Get()->PostTask( 161 base::ThreadTaskRunnerHandle::Get()->PostTask(
161 FROM_HERE, 162 FROM_HERE,
162 base::Bind(&MockClientCertURLRequestJob::NotifyCertificateRequested, 163 base::Bind(&MockClientCertURLRequestJob::NotifyCertificateRequested,
163 this, cert_request_info)); 164 this, cert_request_info));
164 } 165 }
165 166
166 void ContinueWithCertificate(net::X509Certificate* cert) override { 167 void ContinueWithCertificate(net::X509Certificate* cert,
168 net::SSLPrivateKey* private_key) override {
167 net::URLRequestTestJob::Start(); 169 net::URLRequestTestJob::Start();
168 } 170 }
169 171
170 private: 172 private:
171 ~MockClientCertURLRequestJob() override {} 173 ~MockClientCertURLRequestJob() override {}
172 174
173 DISALLOW_COPY_AND_ASSIGN(MockClientCertURLRequestJob); 175 DISALLOW_COPY_AND_ASSIGN(MockClientCertURLRequestJob);
174 }; 176 };
175 177
176 class MockClientCertJobProtocolHandler 178 class MockClientCertJobProtocolHandler
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 443
442 ++call_count_; 444 ++call_count_;
443 passed_certs_ = cert_request_info->client_certs; 445 passed_certs_ = cert_request_info->client_certs;
444 delegate_ = delegate.Pass(); 446 delegate_ = delegate.Pass();
445 select_certificate_run_loop_.Quit(); 447 select_certificate_run_loop_.Quit();
446 } 448 }
447 449
448 int call_count() { return call_count_; } 450 int call_count() { return call_count_; }
449 net::CertificateList passed_certs() { return passed_certs_; } 451 net::CertificateList passed_certs() { return passed_certs_; }
450 452
451 void ContinueWithCertificate(net::X509Certificate* cert) { 453 void ContinueWithCertificate(net::X509Certificate* cert,
452 delegate_->ContinueWithCertificate(cert); 454 net::SSLPrivateKey* private_key) {
455 delegate_->ContinueWithCertificate(cert, private_key);
453 delegate_.reset(); 456 delegate_.reset();
454 } 457 }
455 458
456 void CancelCertificateSelection() { delegate_.reset(); } 459 void CancelCertificateSelection() { delegate_.reset(); }
457 460
458 private: 461 private:
459 net::CertificateList passed_certs_; 462 net::CertificateList passed_certs_;
460 int call_count_; 463 int call_count_;
461 scoped_ptr<ClientCertificateDelegate> delegate_; 464 scoped_ptr<ClientCertificateDelegate> delegate_;
462 465
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 EXPECT_EQ(1, store_request_count); 703 EXPECT_EQ(1, store_request_count);
701 EXPECT_EQ(MockClientCertURLRequestJob::test_authorities(), 704 EXPECT_EQ(MockClientCertURLRequestJob::test_authorities(),
702 store_requested_authorities); 705 store_requested_authorities);
703 706
704 // Check if the retrieved certificates were passed to the content browser 707 // Check if the retrieved certificates were passed to the content browser
705 // client. 708 // client.
706 EXPECT_EQ(1, test_client.call_count()); 709 EXPECT_EQ(1, test_client.call_count());
707 EXPECT_EQ(dummy_certs, test_client.passed_certs()); 710 EXPECT_EQ(dummy_certs, test_client.passed_certs());
708 711
709 // Continue the request. 712 // Continue the request.
710 test_client.ContinueWithCertificate(dummy_certs[0].get()); 713 test_client.ContinueWithCertificate(dummy_certs[0].get(), nullptr);
davidben 2015/10/13 20:32:15 Given that this call does absolutely nothing with
svaldez 2015/10/14 15:06:18 Done.
711 raw_ptr_resource_handler_->WaitForResponseComplete(); 714 raw_ptr_resource_handler_->WaitForResponseComplete();
712 EXPECT_EQ(net::OK, raw_ptr_resource_handler_->status().error()); 715 EXPECT_EQ(net::OK, raw_ptr_resource_handler_->status().error());
713 716
714 // Restore the original content browser client. 717 // Restore the original content browser client.
715 SetBrowserClientForTesting(old_client); 718 SetBrowserClientForTesting(old_client);
716 } 719 }
717 720
718 // Tests that client certificates are requested on a platform with NULL 721 // Tests that client certificates are requested on a platform with NULL
719 // ClientCertStore. 722 // ClientCertStore.
720 TEST_F(ClientCertResourceLoaderTest, WithNullStore) { 723 TEST_F(ClientCertResourceLoaderTest, WithNullStore) {
721 // Plug in test content browser client. 724 // Plug in test content browser client.
722 SelectCertificateBrowserClient test_client; 725 SelectCertificateBrowserClient test_client;
723 ContentBrowserClient* old_client = SetBrowserClientForTesting(&test_client); 726 ContentBrowserClient* old_client = SetBrowserClientForTesting(&test_client);
724 727
725 // Start the request and wait for it to pause. 728 // Start the request and wait for it to pause.
726 loader_->StartRequest(); 729 loader_->StartRequest();
727 test_client.WaitForSelectCertificate(); 730 test_client.WaitForSelectCertificate();
728 731
729 // Check if the SelectClientCertificate was called on the content browser 732 // Check if the SelectClientCertificate was called on the content browser
730 // client. 733 // client.
731 EXPECT_EQ(1, test_client.call_count()); 734 EXPECT_EQ(1, test_client.call_count());
732 EXPECT_EQ(net::CertificateList(), test_client.passed_certs()); 735 EXPECT_EQ(net::CertificateList(), test_client.passed_certs());
733 736
734 // Continue the request. 737 // Continue the request.
735 scoped_refptr<net::X509Certificate> cert( 738 scoped_refptr<net::X509Certificate> cert(
736 new net::X509Certificate("test", "test", base::Time(), base::Time())); 739 new net::X509Certificate("test", "test", base::Time(), base::Time()));
737 test_client.ContinueWithCertificate(cert.get()); 740
741 test_client.ContinueWithCertificate(cert.get(), nullptr);
davidben 2015/10/13 20:32:15 Ditto
svaldez 2015/10/14 15:06:18 Done.
738 raw_ptr_resource_handler_->WaitForResponseComplete(); 742 raw_ptr_resource_handler_->WaitForResponseComplete();
739 EXPECT_EQ(net::OK, raw_ptr_resource_handler_->status().error()); 743 EXPECT_EQ(net::OK, raw_ptr_resource_handler_->status().error());
740 744
741 // Restore the original content browser client. 745 // Restore the original content browser client.
742 SetBrowserClientForTesting(old_client); 746 SetBrowserClientForTesting(old_client);
743 } 747 }
744 748
745 // Tests that the ContentBrowserClient may cancel a certificate request. 749 // Tests that the ContentBrowserClient may cancel a certificate request.
746 TEST_F(ClientCertResourceLoaderTest, CancelSelection) { 750 TEST_F(ClientCertResourceLoaderTest, CancelSelection) {
747 // Plug in test content browser client. 751 // Plug in test content browser client.
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 ASSERT_TRUE( 1143 ASSERT_TRUE(
1140 CertStore::GetInstance()->RetrieveCert(deserialized.cert_id, &cert)); 1144 CertStore::GetInstance()->RetrieveCert(deserialized.cert_id, &cert));
1141 EXPECT_TRUE(cert->Equals(GetTestCert().get())); 1145 EXPECT_TRUE(cert->Equals(GetTestCert().get()));
1142 1146
1143 EXPECT_EQ(kTestCertError, deserialized.cert_status); 1147 EXPECT_EQ(kTestCertError, deserialized.cert_status);
1144 EXPECT_EQ(kTestConnectionStatus, deserialized.connection_status); 1148 EXPECT_EQ(kTestConnectionStatus, deserialized.connection_status);
1145 EXPECT_EQ(kTestSecurityBits, deserialized.security_bits); 1149 EXPECT_EQ(kTestSecurityBits, deserialized.security_bits);
1146 } 1150 }
1147 1151
1148 } // namespace content 1152 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698