Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "net/test/spawned_test_server/base_test_server.h" | 5 #include "net/test/spawned_test_server/base_test_server.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "net/base/address_list.h" | 16 #include "net/base/address_list.h" |
| 17 #include "net/base/host_port_pair.h" | 17 #include "net/base/host_port_pair.h" |
| 18 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
| 19 #include "net/base/port_util.h" | 19 #include "net/base/port_util.h" |
| 20 #include "net/base/test_completion_callback.h" | 20 #include "net/base/test_completion_callback.h" |
| 21 #include "net/cert/test_root_certs.h" | 21 #include "net/cert/test_root_certs.h" |
| 22 #include "net/cert/x509_certificate.h" | |
| 22 #include "net/dns/host_resolver.h" | 23 #include "net/dns/host_resolver.h" |
| 23 #include "net/log/net_log.h" | 24 #include "net/log/net_log.h" |
| 24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 25 | 26 |
| 26 namespace net { | 27 namespace net { |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 std::string GetHostname(BaseTestServer::Type type, | 31 std::string GetHostname(BaseTestServer::Type type, |
| 31 const BaseTestServer::SSLOptions& options) { | 32 const BaseTestServer::SSLOptions& options) { |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 base::FilePath src_dir; | 329 base::FilePath src_dir; |
| 329 if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)) | 330 if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)) |
| 330 return false; | 331 return false; |
| 331 root_certificate_path = src_dir.Append(certificates_dir_); | 332 root_certificate_path = src_dir.Append(certificates_dir_); |
| 332 } | 333 } |
| 333 | 334 |
| 334 return root_certs->AddFromFile( | 335 return root_certs->AddFromFile( |
| 335 root_certificate_path.AppendASCII("root_ca_cert.pem")); | 336 root_certificate_path.AppendASCII("root_ca_cert.pem")); |
| 336 } | 337 } |
| 337 | 338 |
| 339 scoped_refptr<X509Certificate> BaseTestServer::GetCertificate() const { | |
| 340 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
| |
| 341 base::FilePath certificate_file(ssl_options_.GetCertificateFile()); | |
| 342 if (certificate_file.value().empty()) | |
| 343 return nullptr; | |
| 344 certificate_path = certificate_path.Append(certificate_file); | |
| 345 | |
| 346 std::string cert_data; | |
| 347 if (!base::ReadFileToString(certificate_path, &cert_data)) | |
| 348 return nullptr; | |
| 349 | |
| 350 CertificateList certs_in_file = | |
| 351 X509Certificate::CreateCertificateListFromBytes( | |
| 352 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.
| |
| 353 if (certs_in_file.empty()) | |
| 354 return nullptr; | |
| 355 return certs_in_file[0]; | |
| 356 } | |
| 357 | |
| 338 void BaseTestServer::Init(const std::string& host) { | 358 void BaseTestServer::Init(const std::string& host) { |
| 339 host_port_pair_ = HostPortPair(host, 0); | 359 host_port_pair_ = HostPortPair(host, 0); |
| 340 | 360 |
| 341 // TODO(battre) Remove this after figuring out why the TestServer is flaky. | 361 // TODO(battre) Remove this after figuring out why the TestServer is flaky. |
| 342 // http://crbug.com/96594 | 362 // http://crbug.com/96594 |
| 343 log_to_console_ = true; | 363 log_to_console_ = true; |
| 344 } | 364 } |
| 345 | 365 |
| 346 void BaseTestServer::SetResourcePath(const base::FilePath& document_root, | 366 void BaseTestServer::SetResourcePath(const base::FilePath& document_root, |
| 347 const base::FilePath& certificates_dir) { | 367 const base::FilePath& certificates_dir) { |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 | 534 |
| 515 return GenerateAdditionalArguments(arguments); | 535 return GenerateAdditionalArguments(arguments); |
| 516 } | 536 } |
| 517 | 537 |
| 518 bool BaseTestServer::GenerateAdditionalArguments( | 538 bool BaseTestServer::GenerateAdditionalArguments( |
| 519 base::DictionaryValue* arguments) const { | 539 base::DictionaryValue* arguments) const { |
| 520 return true; | 540 return true; |
| 521 } | 541 } |
| 522 | 542 |
| 523 } // namespace net | 543 } // namespace net |
| OLD | NEW |