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

Unified Diff: net/test/spawned_test_server/base_test_server.cc

Issue 1270043004: Add URLRequest unit tests for HPKP violation reports (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add BaseTestServer::GetCertificate() Created 5 years, 4 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 | « net/test/spawned_test_server/base_test_server.h ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/test/spawned_test_server/base_test_server.cc
diff --git a/net/test/spawned_test_server/base_test_server.cc b/net/test/spawned_test_server/base_test_server.cc
index bff9babefac4fd19b3fa9ac547088f1a6fbdd817..f6c09c0e91a0c7590134622d96c00c213686c2a6 100644
--- a/net/test/spawned_test_server/base_test_server.cc
+++ b/net/test/spawned_test_server/base_test_server.cc
@@ -19,6 +19,7 @@
#include "net/base/port_util.h"
#include "net/base/test_completion_callback.h"
#include "net/cert/test_root_certs.h"
+#include "net/cert/x509_certificate.h"
#include "net/dns/host_resolver.h"
#include "net/log/net_log.h"
#include "url/gurl.h"
@@ -335,6 +336,25 @@ bool BaseTestServer::LoadTestRootCert() const {
root_certificate_path.AppendASCII("root_ca_cert.pem"));
}
+scoped_refptr<X509Certificate> BaseTestServer::GetCertificate() const {
+ base::FilePath certificate_path(certificates_dir_);
davidben 2015/08/07 14:50:28 Huh. Apparently certificates_dir_ is kind of wonky
estark 2015/08/07 18:19:14 Ah, so you mean that GetLocalCertificatesDir() sho
+ base::FilePath certificate_file(ssl_options_.GetCertificateFile());
+ if (certificate_file.value().empty())
+ return nullptr;
+ certificate_path = certificate_path.Append(certificate_file);
+
+ std::string cert_data;
+ if (!base::ReadFileToString(certificate_path, &cert_data))
+ return nullptr;
+
+ CertificateList certs_in_file =
+ X509Certificate::CreateCertificateListFromBytes(
+ cert_data.data(), cert_data.size(), X509Certificate::FORMAT_AUTO);
davidben 2015/08/07 14:50:28 Since the test server itself only accepts PEM, I t
estark 2015/08/07 18:19:14 Done.
+ if (certs_in_file.empty())
+ return nullptr;
+ return certs_in_file[0];
+}
+
void BaseTestServer::Init(const std::string& host) {
host_port_pair_ = HostPortPair(host, 0);
« no previous file with comments | « net/test/spawned_test_server/base_test_server.h ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698