| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/base_test_server.h" | 5 #include "net/test/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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
| 23 #include "net/base/test_completion_callback.h" | 23 #include "net/base/test_completion_callback.h" |
| 24 #include "net/base/test_root_certs.h" | 24 #include "net/base/test_root_certs.h" |
| 25 | 25 |
| 26 namespace net { | 26 namespace net { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 std::string GetHostname(BaseTestServer::Type type, | 30 std::string GetHostname(BaseTestServer::Type type, |
| 31 const BaseTestServer::SSLOptions& options) { | 31 const BaseTestServer::SSLOptions& options) { |
| 32 if ((type == BaseTestServer::TYPE_HTTPS || | 32 if (BaseTestServer::UsingSSL(type) && |
| 33 type == BaseTestServer::TYPE_WSS) && | |
| 34 options.server_certificate == | 33 options.server_certificate == |
| 35 BaseTestServer::SSLOptions::CERT_MISMATCHED_NAME) { | 34 BaseTestServer::SSLOptions::CERT_MISMATCHED_NAME) { |
| 36 // Return a different hostname string that resolves to the same hostname. | 35 // Return a different hostname string that resolves to the same hostname. |
| 37 return "localhost"; | 36 return "localhost"; |
| 38 } | 37 } |
| 39 | 38 |
| 40 // Use the 127.0.0.1 as default. | 39 // Use the 127.0.0.1 as default. |
| 41 return BaseTestServer::kLocalhost; | 40 return BaseTestServer::kLocalhost; |
| 42 } | 41 } |
| 43 | 42 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 started_(false), | 119 started_(false), |
| 121 log_to_console_(false) { | 120 log_to_console_(false) { |
| 122 Init(host); | 121 Init(host); |
| 123 } | 122 } |
| 124 | 123 |
| 125 BaseTestServer::BaseTestServer(Type type, const SSLOptions& ssl_options) | 124 BaseTestServer::BaseTestServer(Type type, const SSLOptions& ssl_options) |
| 126 : ssl_options_(ssl_options), | 125 : ssl_options_(ssl_options), |
| 127 type_(type), | 126 type_(type), |
| 128 started_(false), | 127 started_(false), |
| 129 log_to_console_(false) { | 128 log_to_console_(false) { |
| 130 DCHECK(type == TYPE_HTTPS || type == TYPE_WSS); | 129 DCHECK(UsingSSL(type)); |
| 131 Init(GetHostname(type, ssl_options)); | 130 Init(GetHostname(type, ssl_options)); |
| 132 } | 131 } |
| 133 | 132 |
| 134 BaseTestServer::~BaseTestServer() {} | 133 BaseTestServer::~BaseTestServer() {} |
| 135 | 134 |
| 136 const HostPortPair& BaseTestServer::host_port_pair() const { | 135 const HostPortPair& BaseTestServer::host_port_pair() const { |
| 137 DCHECK(started_); | 136 DCHECK(started_); |
| 138 return host_port_pair_; | 137 return host_port_pair_; |
| 139 } | 138 } |
| 140 | 139 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 root_certificate_path = src_dir.Append(certificates_dir_); | 301 root_certificate_path = src_dir.Append(certificates_dir_); |
| 303 } | 302 } |
| 304 | 303 |
| 305 return root_certs->AddFromFile( | 304 return root_certs->AddFromFile( |
| 306 root_certificate_path.AppendASCII("root_ca_cert.crt")); | 305 root_certificate_path.AppendASCII("root_ca_cert.crt")); |
| 307 } | 306 } |
| 308 | 307 |
| 309 bool BaseTestServer::SetupWhenServerStarted() { | 308 bool BaseTestServer::SetupWhenServerStarted() { |
| 310 DCHECK(host_port_pair_.port()); | 309 DCHECK(host_port_pair_.port()); |
| 311 | 310 |
| 312 if ((type_ == TYPE_HTTPS || type_ == TYPE_WSS) && !LoadTestRootCert()) | 311 if (UsingSSL(type_) && !LoadTestRootCert()) |
| 313 return false; | 312 return false; |
| 314 | 313 |
| 315 started_ = true; | 314 started_ = true; |
| 316 allowed_port_.reset(new ScopedPortException(host_port_pair_.port())); | 315 allowed_port_.reset(new ScopedPortException(host_port_pair_.port())); |
| 317 return true; | 316 return true; |
| 318 } | 317 } |
| 319 | 318 |
| 320 void BaseTestServer::CleanUpWhenStoppingServer() { | 319 void BaseTestServer::CleanUpWhenStoppingServer() { |
| 321 TestRootCerts* root_certs = TestRootCerts::GetInstance(); | 320 TestRootCerts* root_certs = TestRootCerts::GetInstance(); |
| 322 root_certs->Clear(); | 321 root_certs->Clear(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 arguments->Set("https-record-resume", base::Value::CreateNullValue()); | 388 arguments->Set("https-record-resume", base::Value::CreateNullValue()); |
| 390 if (ssl_options_.tls_intolerant != SSLOptions::TLS_INTOLERANT_NONE) { | 389 if (ssl_options_.tls_intolerant != SSLOptions::TLS_INTOLERANT_NONE) { |
| 391 arguments->Set("tls-intolerant", | 390 arguments->Set("tls-intolerant", |
| 392 base::Value::CreateIntegerValue(ssl_options_.tls_intolerant)); | 391 base::Value::CreateIntegerValue(ssl_options_.tls_intolerant)); |
| 393 } | 392 } |
| 394 } | 393 } |
| 395 return true; | 394 return true; |
| 396 } | 395 } |
| 397 | 396 |
| 398 } // namespace net | 397 } // namespace net |
| OLD | NEW |