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" |
11 #include "base/file_util.h" | 11 #include "base/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 "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
17 #include "net/base/address_list.h" | 17 #include "net/base/address_list.h" |
18 #include "net/base/host_port_pair.h" | 18 #include "net/base/host_port_pair.h" |
19 #include "net/base/host_resolver.h" | 19 #include "net/base/host_resolver.h" |
20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
21 #include "net/base/net_log.h" | 21 #include "net/base/net_log.h" |
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 bool UsingSSL(BaseTestServer::Type type) { |
| 31 return type == BaseTestServer::TYPE_HTTPS || |
| 32 type == BaseTestServer::TYPE_WSS; |
| 33 } |
| 34 |
30 std::string GetHostname(BaseTestServer::Type type, | 35 std::string GetHostname(BaseTestServer::Type type, |
31 const BaseTestServer::SSLOptions& options) { | 36 const BaseTestServer::SSLOptions& options) { |
32 if ((type == BaseTestServer::TYPE_HTTPS || | 37 if (UsingSSL(type) && |
33 type == BaseTestServer::TYPE_WSS) && | |
34 options.server_certificate == | 38 options.server_certificate == |
35 BaseTestServer::SSLOptions::CERT_MISMATCHED_NAME) { | 39 BaseTestServer::SSLOptions::CERT_MISMATCHED_NAME) { |
36 // Return a different hostname string that resolves to the same hostname. | 40 // Return a different hostname string that resolves to the same hostname. |
37 return "localhost"; | 41 return "localhost"; |
38 } | 42 } |
39 | 43 |
40 // Use the 127.0.0.1 as default. | 44 // Use the 127.0.0.1 as default. |
41 return BaseTestServer::kLocalhost; | 45 return BaseTestServer::kLocalhost; |
42 } | 46 } |
43 | 47 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 started_(false), | 124 started_(false), |
121 log_to_console_(false) { | 125 log_to_console_(false) { |
122 Init(host); | 126 Init(host); |
123 } | 127 } |
124 | 128 |
125 BaseTestServer::BaseTestServer(Type type, const SSLOptions& ssl_options) | 129 BaseTestServer::BaseTestServer(Type type, const SSLOptions& ssl_options) |
126 : ssl_options_(ssl_options), | 130 : ssl_options_(ssl_options), |
127 type_(type), | 131 type_(type), |
128 started_(false), | 132 started_(false), |
129 log_to_console_(false) { | 133 log_to_console_(false) { |
130 DCHECK(type == TYPE_HTTPS || type == TYPE_WSS); | 134 DCHECK(UsingSSL(type)); |
131 Init(GetHostname(type, ssl_options)); | 135 Init(GetHostname(type, ssl_options)); |
132 } | 136 } |
133 | 137 |
134 BaseTestServer::~BaseTestServer() {} | 138 BaseTestServer::~BaseTestServer() {} |
135 | 139 |
136 const HostPortPair& BaseTestServer::host_port_pair() const { | 140 const HostPortPair& BaseTestServer::host_port_pair() const { |
137 DCHECK(started_); | 141 DCHECK(started_); |
138 return host_port_pair_; | 142 return host_port_pair_; |
139 } | 143 } |
140 | 144 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 root_certificate_path = src_dir.Append(certificates_dir_); | 306 root_certificate_path = src_dir.Append(certificates_dir_); |
303 } | 307 } |
304 | 308 |
305 return root_certs->AddFromFile( | 309 return root_certs->AddFromFile( |
306 root_certificate_path.AppendASCII("root_ca_cert.crt")); | 310 root_certificate_path.AppendASCII("root_ca_cert.crt")); |
307 } | 311 } |
308 | 312 |
309 bool BaseTestServer::SetupWhenServerStarted() { | 313 bool BaseTestServer::SetupWhenServerStarted() { |
310 DCHECK(host_port_pair_.port()); | 314 DCHECK(host_port_pair_.port()); |
311 | 315 |
312 if ((type_ == TYPE_HTTPS || type_ == TYPE_WSS) && !LoadTestRootCert()) | 316 if (UsingSSL(type_) && !LoadTestRootCert()) |
313 return false; | 317 return false; |
314 | 318 |
315 started_ = true; | 319 started_ = true; |
316 allowed_port_.reset(new ScopedPortException(host_port_pair_.port())); | 320 allowed_port_.reset(new ScopedPortException(host_port_pair_.port())); |
317 return true; | 321 return true; |
318 } | 322 } |
319 | 323 |
320 void BaseTestServer::CleanUpWhenStoppingServer() { | 324 void BaseTestServer::CleanUpWhenStoppingServer() { |
321 TestRootCerts* root_certs = TestRootCerts::GetInstance(); | 325 TestRootCerts* root_certs = TestRootCerts::GetInstance(); |
322 root_certs->Clear(); | 326 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()); | 393 arguments->Set("https-record-resume", base::Value::CreateNullValue()); |
390 if (ssl_options_.tls_intolerant != SSLOptions::TLS_INTOLERANT_NONE) { | 394 if (ssl_options_.tls_intolerant != SSLOptions::TLS_INTOLERANT_NONE) { |
391 arguments->Set("tls-intolerant", | 395 arguments->Set("tls-intolerant", |
392 base::Value::CreateIntegerValue(ssl_options_.tls_intolerant)); | 396 base::Value::CreateIntegerValue(ssl_options_.tls_intolerant)); |
393 } | 397 } |
394 } | 398 } |
395 return true; | 399 return true; |
396 } | 400 } |
397 | 401 |
398 } // namespace net | 402 } // namespace net |
OLD | NEW |