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

Unified Diff: content/browser/loader/resource_loader_unittest.cc

Issue 2898573002: Refactor client cert private key handling. (Closed)
Patch Set: removed no longer needed forward declaration 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/loader/resource_loader.cc ('k') | content/browser/ssl/ssl_client_auth_handler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/loader/resource_loader_unittest.cc
diff --git a/content/browser/loader/resource_loader_unittest.cc b/content/browser/loader/resource_loader_unittest.cc
index 715b4818fcbe8e609b91aa86cb54793a2cfea86a..dab9d6a9aa664cc5ccca14f44bb1ce394cafe668 100644
--- a/content/browser/loader/resource_loader_unittest.cc
+++ b/content/browser/loader/resource_loader_unittest.cc
@@ -42,6 +42,7 @@
#include "net/cert/x509_certificate.h"
#include "net/nqe/effective_connection_type.h"
#include "net/nqe/network_quality_estimator_test_util.h"
+#include "net/ssl/client_cert_identity_test_util.h"
#include "net/ssl/client_cert_store.h"
#include "net/ssl/ssl_cert_request_info.h"
#include "net/ssl/ssl_private_key.h"
@@ -79,7 +80,7 @@ class ClientCertStoreStub : public net::ClientCertStore {
ClientCertStoreStub(const net::CertificateList& response,
int* request_count,
std::vector<std::string>* requested_authorities)
- : response_(response),
+ : response_(std::move(response)),
requested_authorities_(requested_authorities),
request_count_(request_count) {
requested_authorities_->clear();
@@ -94,7 +95,7 @@ class ClientCertStoreStub : public net::ClientCertStore {
*requested_authorities_ = cert_request_info.cert_authorities;
++(*request_count_);
- callback.Run(response_);
+ callback.Run(net::FakeClientCertIdentityListFromCertificateList(response_));
}
private:
@@ -134,7 +135,7 @@ class LoaderDestroyingCertStore : public net::ClientCertStore {
const ClientCertListCallback& cert_selected_callback,
const base::Closure& on_loader_deleted_callback) {
loader->reset();
- cert_selected_callback.Run(net::CertificateList());
+ cert_selected_callback.Run(net::ClientCertIdentityList());
on_loader_deleted_callback.Run();
}
@@ -168,8 +169,9 @@ class MockClientCertURLRequestJob : public net::URLRequestTestJob {
base::RetainedRef(cert_request_info)));
}
- void ContinueWithCertificate(net::X509Certificate* cert,
- net::SSLPrivateKey* private_key) override {
+ void ContinueWithCertificate(
+ scoped_refptr<net::X509Certificate> cert,
+ scoped_refptr<net::SSLPrivateKey> private_key) override {
net::URLRequestTestJob::Start();
}
@@ -273,28 +275,31 @@ class SelectCertificateBrowserClient : public TestContentBrowserClient {
void SelectClientCertificate(
WebContents* web_contents,
net::SSLCertRequestInfo* cert_request_info,
- net::CertificateList client_certs,
+ net::ClientCertIdentityList client_certs,
std::unique_ptr<ClientCertificateDelegate> delegate) override {
EXPECT_FALSE(delegate_.get());
++call_count_;
- passed_certs_ = std::move(client_certs);
+ passed_identities_ = std::move(client_certs);
delegate_ = std::move(delegate);
select_certificate_run_loop_.Quit();
}
int call_count() { return call_count_; }
- net::CertificateList passed_certs() { return passed_certs_; }
+ const net::ClientCertIdentityList& passed_identities() {
+ return passed_identities_;
+ }
- void ContinueWithCertificate(net::X509Certificate* cert) {
- delegate_->ContinueWithCertificate(cert);
+ void ContinueWithCertificate(scoped_refptr<net::X509Certificate> cert,
+ scoped_refptr<net::SSLPrivateKey> private_key) {
+ delegate_->ContinueWithCertificate(std::move(cert), std::move(private_key));
delegate_.reset();
}
void CancelCertificateSelection() { delegate_.reset(); }
private:
- net::CertificateList passed_certs_;
+ net::ClientCertIdentityList passed_identities_;
int call_count_;
std::unique_ptr<ClientCertificateDelegate> delegate_;
@@ -595,8 +600,10 @@ TEST_F(ClientCertResourceLoaderTest, WithStoreLookup) {
// Set up the test client cert store.
int store_request_count;
std::vector<std::string> store_requested_authorities;
- net::CertificateList dummy_certs(
- 1, net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"));
+ scoped_refptr<net::X509Certificate> test_cert =
+ net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem");
+ ASSERT_TRUE(test_cert);
+ net::CertificateList dummy_certs(1, test_cert);
std::unique_ptr<ClientCertStoreStub> test_store(new ClientCertStoreStub(
dummy_certs, &store_request_count, &store_requested_authorities));
SetClientCertStore(std::move(test_store));
@@ -619,10 +626,11 @@ TEST_F(ClientCertResourceLoaderTest, WithStoreLookup) {
// Check if the retrieved certificates were passed to the content browser
// client.
EXPECT_EQ(1, test_client.call_count());
- EXPECT_EQ(dummy_certs, test_client.passed_certs());
+ EXPECT_EQ(1U, test_client.passed_identities().size());
+ EXPECT_EQ(test_cert.get(), test_client.passed_identities()[0]->certificate());
// Continue the request.
- test_client.ContinueWithCertificate(nullptr);
+ test_client.ContinueWithCertificate(nullptr, nullptr);
raw_ptr_resource_handler_->WaitUntilResponseComplete();
EXPECT_EQ(net::OK, raw_ptr_resource_handler_->final_status().error());
@@ -644,10 +652,10 @@ TEST_F(ClientCertResourceLoaderTest, WithNullStore) {
// Check if the SelectClientCertificate was called on the content browser
// client.
EXPECT_EQ(1, test_client.call_count());
- EXPECT_EQ(net::CertificateList(), test_client.passed_certs());
+ EXPECT_EQ(net::ClientCertIdentityList(), test_client.passed_identities());
// Continue the request.
- test_client.ContinueWithCertificate(nullptr);
+ test_client.ContinueWithCertificate(nullptr, nullptr);
raw_ptr_resource_handler_->WaitUntilResponseComplete();
EXPECT_EQ(net::OK, raw_ptr_resource_handler_->final_status().error());
@@ -668,7 +676,7 @@ TEST_F(ClientCertResourceLoaderTest, CancelSelection) {
// Check if the SelectClientCertificate was called on the content browser
// client.
EXPECT_EQ(1, test_client.call_count());
- EXPECT_EQ(net::CertificateList(), test_client.passed_certs());
+ EXPECT_EQ(net::ClientCertIdentityList(), test_client.passed_identities());
// Cancel the request.
test_client.CancelCertificateSelection();
« no previous file with comments | « content/browser/loader/resource_loader.cc ('k') | content/browser/ssl/ssl_client_auth_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698