| 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/test_server.h" | 5 #include "net/test/test_server.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "net/base/host_resolver.h" | 30 #include "net/base/host_resolver.h" |
| 31 #include "net/base/net_errors.h" | 31 #include "net/base/net_errors.h" |
| 32 #include "net/base/test_completion_callback.h" | 32 #include "net/base/test_completion_callback.h" |
| 33 #include "net/base/test_root_certs.h" | 33 #include "net/base/test_root_certs.h" |
| 34 #include "net/socket/tcp_client_socket.h" | 34 #include "net/socket/tcp_client_socket.h" |
| 35 #include "net/test/python_utils.h" | 35 #include "net/test/python_utils.h" |
| 36 #include "testing/platform_test.h" | 36 #include "testing/platform_test.h" |
| 37 | 37 |
| 38 namespace net { | 38 namespace net { |
| 39 | 39 |
| 40 namespace { | |
| 41 | |
| 42 std::string GetHostname(TestServer::Type type, | |
| 43 const TestServer::HTTPSOptions& options) { | |
| 44 if (type == TestServer::TYPE_HTTPS && | |
| 45 options.server_certificate == | |
| 46 TestServer::HTTPSOptions::CERT_MISMATCHED_NAME) { | |
| 47 // Return a different hostname string that resolves to the same hostname. | |
| 48 return "localhost"; | |
| 49 } | |
| 50 | |
| 51 return "127.0.0.1"; | |
| 52 } | |
| 53 | |
| 54 } // namespace | |
| 55 | |
| 56 TestServer::HTTPSOptions::HTTPSOptions() | 40 TestServer::HTTPSOptions::HTTPSOptions() |
| 57 : server_certificate(CERT_OK), | 41 : server_certificate(CERT_OK), |
| 58 request_client_certificate(false), | 42 request_client_certificate(false), |
| 59 bulk_ciphers(HTTPSOptions::BULK_CIPHER_ANY), | 43 bulk_ciphers(HTTPSOptions::BULK_CIPHER_ANY), |
| 60 record_resume(false) {} | 44 record_resume(false) {} |
| 61 | 45 |
| 62 TestServer::HTTPSOptions::HTTPSOptions( | 46 TestServer::HTTPSOptions::HTTPSOptions( |
| 63 TestServer::HTTPSOptions::ServerCertificate cert) | 47 TestServer::HTTPSOptions::ServerCertificate cert) |
| 64 : server_certificate(cert), | 48 : server_certificate(cert), |
| 65 request_client_certificate(false), | 49 request_client_certificate(false), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 76 case CERT_EXPIRED: | 60 case CERT_EXPIRED: |
| 77 return FilePath(FILE_PATH_LITERAL("expired_cert.pem")); | 61 return FilePath(FILE_PATH_LITERAL("expired_cert.pem")); |
| 78 default: | 62 default: |
| 79 NOTREACHED(); | 63 NOTREACHED(); |
| 80 } | 64 } |
| 81 return FilePath(); | 65 return FilePath(); |
| 82 } | 66 } |
| 83 | 67 |
| 84 const char* TestServer::kLocalhost = "127.0.0.1"; | 68 const char* TestServer::kLocalhost = "127.0.0.1"; |
| 85 | 69 |
| 86 TestServer::TestServer(Type type, const FilePath& document_root) | |
| 87 : type_(type), | |
| 88 started_(false), | |
| 89 log_to_console_(false) { | |
| 90 Init("127.0.0.1", document_root); | |
| 91 } | |
| 92 | |
| 93 TestServer::TestServer(Type type, | 70 TestServer::TestServer(Type type, |
| 94 const std::string& host, | 71 const std::string& host, |
| 95 const FilePath& document_root) | 72 const FilePath& document_root) |
| 96 : type_(type), | 73 : type_(type), |
| 97 started_(false), | 74 started_(false), |
| 98 log_to_console_(false) { | 75 log_to_console_(false) { |
| 99 Init(host, document_root); | 76 Init(host, document_root); |
| 100 } | 77 } |
| 101 | 78 |
| 102 TestServer::TestServer(const HTTPSOptions& https_options, | 79 TestServer::TestServer(const HTTPSOptions& https_options, |
| 103 const FilePath& document_root) | 80 const FilePath& document_root) |
| 104 : https_options_(https_options), | 81 : https_options_(https_options), |
| 105 type_(TYPE_HTTPS), | 82 type_(TYPE_HTTPS), |
| 106 started_(false), | 83 started_(false), |
| 107 log_to_console_(false) { | 84 log_to_console_(false) { |
| 108 Init(GetHostname(TYPE_HTTPS, https_options), document_root); | 85 const char* host = "127.0.0.1"; |
| 86 if (https_options_.server_certificate == |
| 87 TestServer::HTTPSOptions::CERT_MISMATCHED_NAME) { |
| 88 // Use a different hostname string that resolves to the same address. |
| 89 host = "localhost"; |
| 90 } |
| 91 |
| 92 Init(host, document_root); |
| 109 } | 93 } |
| 110 | 94 |
| 111 TestServer::~TestServer() { | 95 TestServer::~TestServer() { |
| 112 TestRootCerts* root_certs = TestRootCerts::GetInstance(); | 96 TestRootCerts* root_certs = TestRootCerts::GetInstance(); |
| 113 root_certs->Clear(); | 97 root_certs->Clear(); |
| 114 Stop(); | 98 Stop(); |
| 115 } | 99 } |
| 116 | 100 |
| 117 bool TestServer::Start() { | 101 bool TestServer::Start() { |
| 118 if (type_ == TYPE_HTTPS) { | 102 if (type_ == TYPE_HTTPS) { |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 command_line->AppendArg(kBulkCipherSwitch + "=3des"); | 412 command_line->AppendArg(kBulkCipherSwitch + "=3des"); |
| 429 | 413 |
| 430 if (https_options_.record_resume) | 414 if (https_options_.record_resume) |
| 431 command_line->AppendArg("--https-record-resume"); | 415 command_line->AppendArg("--https-record-resume"); |
| 432 } | 416 } |
| 433 | 417 |
| 434 return true; | 418 return true; |
| 435 } | 419 } |
| 436 | 420 |
| 437 } // namespace net | 421 } // namespace net |
| OLD | NEW |