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" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 : server_certificate(CERT_OK), | 64 : server_certificate(CERT_OK), |
65 ocsp_status(OCSP_OK), | 65 ocsp_status(OCSP_OK), |
66 cert_serial(0), | 66 cert_serial(0), |
67 request_client_certificate(false), | 67 request_client_certificate(false), |
68 key_exchanges(SSLOptions::KEY_EXCHANGE_ANY), | 68 key_exchanges(SSLOptions::KEY_EXCHANGE_ANY), |
69 bulk_ciphers(SSLOptions::BULK_CIPHER_ANY), | 69 bulk_ciphers(SSLOptions::BULK_CIPHER_ANY), |
70 record_resume(false), | 70 record_resume(false), |
71 tls_intolerant(TLS_INTOLERANT_NONE), | 71 tls_intolerant(TLS_INTOLERANT_NONE), |
72 fallback_scsv_enabled(false), | 72 fallback_scsv_enabled(false), |
73 staple_ocsp_response(false), | 73 staple_ocsp_response(false), |
74 enable_npn(false) {} | 74 enable_npn(false) { |
| 75 } |
75 | 76 |
76 BaseTestServer::SSLOptions::SSLOptions( | 77 BaseTestServer::SSLOptions::SSLOptions( |
77 BaseTestServer::SSLOptions::ServerCertificate cert) | 78 BaseTestServer::SSLOptions::ServerCertificate cert) |
78 : server_certificate(cert), | 79 : server_certificate(cert), |
79 ocsp_status(OCSP_OK), | 80 ocsp_status(OCSP_OK), |
80 cert_serial(0), | 81 cert_serial(0), |
81 request_client_certificate(false), | 82 request_client_certificate(false), |
82 key_exchanges(SSLOptions::KEY_EXCHANGE_ANY), | 83 key_exchanges(SSLOptions::KEY_EXCHANGE_ANY), |
83 bulk_ciphers(SSLOptions::BULK_CIPHER_ANY), | 84 bulk_ciphers(SSLOptions::BULK_CIPHER_ANY), |
84 record_resume(false), | 85 record_resume(false), |
85 tls_intolerant(TLS_INTOLERANT_NONE), | 86 tls_intolerant(TLS_INTOLERANT_NONE), |
86 fallback_scsv_enabled(false), | 87 fallback_scsv_enabled(false), |
87 staple_ocsp_response(false), | 88 staple_ocsp_response(false), |
88 enable_npn(false) {} | 89 enable_npn(false) { |
| 90 } |
89 | 91 |
90 BaseTestServer::SSLOptions::~SSLOptions() {} | 92 BaseTestServer::SSLOptions::~SSLOptions() { |
| 93 } |
91 | 94 |
92 base::FilePath BaseTestServer::SSLOptions::GetCertificateFile() const { | 95 base::FilePath BaseTestServer::SSLOptions::GetCertificateFile() const { |
93 switch (server_certificate) { | 96 switch (server_certificate) { |
94 case CERT_OK: | 97 case CERT_OK: |
95 case CERT_MISMATCHED_NAME: | 98 case CERT_MISMATCHED_NAME: |
96 return base::FilePath(FILE_PATH_LITERAL("ok_cert.pem")); | 99 return base::FilePath(FILE_PATH_LITERAL("ok_cert.pem")); |
97 case CERT_EXPIRED: | 100 case CERT_EXPIRED: |
98 return base::FilePath(FILE_PATH_LITERAL("expired_cert.pem")); | 101 return base::FilePath(FILE_PATH_LITERAL("expired_cert.pem")); |
99 case CERT_CHAIN_WRONG_ROOT: | 102 case CERT_CHAIN_WRONG_ROOT: |
100 // This chain uses its own dedicated test root certificate to avoid | 103 // This chain uses its own dedicated test root certificate to avoid |
(...skipping 24 matching lines...) Expand all Loading... |
125 return "unknown"; | 128 return "unknown"; |
126 default: | 129 default: |
127 NOTREACHED(); | 130 NOTREACHED(); |
128 return std::string(); | 131 return std::string(); |
129 } | 132 } |
130 } | 133 } |
131 | 134 |
132 const char BaseTestServer::kLocalhost[] = "127.0.0.1"; | 135 const char BaseTestServer::kLocalhost[] = "127.0.0.1"; |
133 | 136 |
134 BaseTestServer::BaseTestServer(Type type, const std::string& host) | 137 BaseTestServer::BaseTestServer(Type type, const std::string& host) |
135 : type_(type), | 138 : type_(type), started_(false), log_to_console_(false) { |
136 started_(false), | |
137 log_to_console_(false) { | |
138 Init(host); | 139 Init(host); |
139 } | 140 } |
140 | 141 |
141 BaseTestServer::BaseTestServer(Type type, const SSLOptions& ssl_options) | 142 BaseTestServer::BaseTestServer(Type type, const SSLOptions& ssl_options) |
142 : ssl_options_(ssl_options), | 143 : ssl_options_(ssl_options), |
143 type_(type), | 144 type_(type), |
144 started_(false), | 145 started_(false), |
145 log_to_console_(false) { | 146 log_to_console_(false) { |
146 DCHECK(UsingSSL(type)); | 147 DCHECK(UsingSSL(type)); |
147 Init(GetHostname(type, ssl_options)); | 148 Init(GetHostname(type, ssl_options)); |
148 } | 149 } |
149 | 150 |
150 BaseTestServer::~BaseTestServer() {} | 151 BaseTestServer::~BaseTestServer() { |
| 152 } |
151 | 153 |
152 const HostPortPair& BaseTestServer::host_port_pair() const { | 154 const HostPortPair& BaseTestServer::host_port_pair() const { |
153 DCHECK(started_); | 155 DCHECK(started_); |
154 return host_port_pair_; | 156 return host_port_pair_; |
155 } | 157 } |
156 | 158 |
157 const base::DictionaryValue& BaseTestServer::server_data() const { | 159 const base::DictionaryValue& BaseTestServer::server_data() const { |
158 DCHECK(started_); | 160 DCHECK(started_); |
159 DCHECK(server_data_.get()); | 161 DCHECK(server_data_.get()); |
160 return *server_data_; | 162 return *server_data_; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 | 209 |
208 void BaseTestServer::SetPort(uint16 port) { | 210 void BaseTestServer::SetPort(uint16 port) { |
209 host_port_pair_.set_port(port); | 211 host_port_pair_.set_port(port); |
210 } | 212 } |
211 | 213 |
212 GURL BaseTestServer::GetURL(const std::string& path) const { | 214 GURL BaseTestServer::GetURL(const std::string& path) const { |
213 return GURL(GetScheme() + "://" + host_port_pair_.ToString() + "/" + path); | 215 return GURL(GetScheme() + "://" + host_port_pair_.ToString() + "/" + path); |
214 } | 216 } |
215 | 217 |
216 GURL BaseTestServer::GetURLWithUser(const std::string& path, | 218 GURL BaseTestServer::GetURLWithUser(const std::string& path, |
217 const std::string& user) const { | 219 const std::string& user) const { |
218 return GURL(GetScheme() + "://" + user + "@" + host_port_pair_.ToString() + | 220 return GURL(GetScheme() + "://" + user + "@" + host_port_pair_.ToString() + |
219 "/" + path); | 221 "/" + path); |
220 } | 222 } |
221 | 223 |
222 GURL BaseTestServer::GetURLWithUserAndPassword(const std::string& path, | 224 GURL BaseTestServer::GetURLWithUserAndPassword( |
223 const std::string& user, | 225 const std::string& path, |
224 const std::string& password) const { | 226 const std::string& user, |
| 227 const std::string& password) const { |
225 return GURL(GetScheme() + "://" + user + ":" + password + "@" + | 228 return GURL(GetScheme() + "://" + user + ":" + password + "@" + |
226 host_port_pair_.ToString() + "/" + path); | 229 host_port_pair_.ToString() + "/" + path); |
227 } | 230 } |
228 | 231 |
229 // static | 232 // static |
230 bool BaseTestServer::GetFilePathWithReplacements( | 233 bool BaseTestServer::GetFilePathWithReplacements( |
231 const std::string& original_file_path, | 234 const std::string& original_file_path, |
232 const std::vector<StringPair>& text_to_replace, | 235 const std::vector<StringPair>& text_to_replace, |
233 std::string* replacement_path) { | 236 std::string* replacement_path) { |
234 std::string new_file_path = original_file_path; | 237 std::string new_file_path = original_file_path; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 } | 319 } |
317 | 320 |
318 return root_certs->AddFromFile( | 321 return root_certs->AddFromFile( |
319 root_certificate_path.AppendASCII("root_ca_cert.pem")); | 322 root_certificate_path.AppendASCII("root_ca_cert.pem")); |
320 } | 323 } |
321 | 324 |
322 bool BaseTestServer::SetupWhenServerStarted() { | 325 bool BaseTestServer::SetupWhenServerStarted() { |
323 DCHECK(host_port_pair_.port()); | 326 DCHECK(host_port_pair_.port()); |
324 | 327 |
325 if (UsingSSL(type_) && !LoadTestRootCert()) | 328 if (UsingSSL(type_) && !LoadTestRootCert()) |
326 return false; | 329 return false; |
327 | 330 |
328 started_ = true; | 331 started_ = true; |
329 allowed_port_.reset(new ScopedPortException(host_port_pair_.port())); | 332 allowed_port_.reset(new ScopedPortException(host_port_pair_.port())); |
330 return true; | 333 return true; |
331 } | 334 } |
332 | 335 |
333 void BaseTestServer::CleanUpWhenStoppingServer() { | 336 void BaseTestServer::CleanUpWhenStoppingServer() { |
334 TestRootCerts* root_certs = TestRootCerts::GetInstance(); | 337 TestRootCerts* root_certs = TestRootCerts::GetInstance(); |
335 root_certs->Clear(); | 338 root_certs->Clear(); |
336 | 339 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 arguments->SetString("cert-and-key-file", certificate_path.value()); | 371 arguments->SetString("cert-and-key-file", certificate_path.value()); |
369 } | 372 } |
370 | 373 |
371 // Check the client certificate related arguments. | 374 // Check the client certificate related arguments. |
372 if (ssl_options_.request_client_certificate) | 375 if (ssl_options_.request_client_certificate) |
373 arguments->Set("ssl-client-auth", base::Value::CreateNullValue()); | 376 arguments->Set("ssl-client-auth", base::Value::CreateNullValue()); |
374 scoped_ptr<base::ListValue> ssl_client_certs(new base::ListValue()); | 377 scoped_ptr<base::ListValue> ssl_client_certs(new base::ListValue()); |
375 | 378 |
376 std::vector<base::FilePath>::const_iterator it; | 379 std::vector<base::FilePath>::const_iterator it; |
377 for (it = ssl_options_.client_authorities.begin(); | 380 for (it = ssl_options_.client_authorities.begin(); |
378 it != ssl_options_.client_authorities.end(); ++it) { | 381 it != ssl_options_.client_authorities.end(); |
| 382 ++it) { |
379 if (it->IsAbsolute() && !base::PathExists(*it)) { | 383 if (it->IsAbsolute() && !base::PathExists(*it)) { |
380 LOG(ERROR) << "Client authority path " << it->value() | 384 LOG(ERROR) << "Client authority path " << it->value() |
381 << " doesn't exist. Can't launch https server."; | 385 << " doesn't exist. Can't launch https server."; |
382 return false; | 386 return false; |
383 } | 387 } |
384 ssl_client_certs->Append(new base::StringValue(it->value())); | 388 ssl_client_certs->Append(new base::StringValue(it->value())); |
385 } | 389 } |
386 | 390 |
387 if (ssl_client_certs->GetSize()) | 391 if (ssl_client_certs->GetSize()) |
388 arguments->Set("ssl-client-ca", ssl_client_certs.release()); | 392 arguments->Set("ssl-client-ca", ssl_client_certs.release()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 | 436 |
433 return GenerateAdditionalArguments(arguments); | 437 return GenerateAdditionalArguments(arguments); |
434 } | 438 } |
435 | 439 |
436 bool BaseTestServer::GenerateAdditionalArguments( | 440 bool BaseTestServer::GenerateAdditionalArguments( |
437 base::DictionaryValue* arguments) const { | 441 base::DictionaryValue* arguments) const { |
438 return true; | 442 return true; |
439 } | 443 } |
440 | 444 |
441 } // namespace net | 445 } // namespace net |
OLD | NEW |