| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NET_BASE_SSL_TEST_UTIL_H_ | |
| 6 #define NET_BASE_SSL_TEST_UTIL_H_ | |
| 7 | |
| 8 #include "build/build_config.h" | |
| 9 | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/file_path.h" | |
| 13 #include "base/process_util.h" | |
| 14 | |
| 15 // TODO(dkegel): share this between net/base and | |
| 16 // chrome/browser without putting it in net.lib | |
| 17 | |
| 18 namespace net { | |
| 19 | |
| 20 // This object bounds the lifetime of an external python-based HTTP/HTTPS/FTP | |
| 21 // server that can provide various responses useful for testing. | |
| 22 // A few basic convenience methods are provided, but no | |
| 23 // URL handling methods (those belong at a higher layer, e.g. in | |
| 24 // url_request_unittest.h). | |
| 25 | |
| 26 class TestServerLauncher { | |
| 27 public: | |
| 28 TestServerLauncher(); | |
| 29 | |
| 30 virtual ~TestServerLauncher(); | |
| 31 | |
| 32 enum Protocol { | |
| 33 ProtoHTTP, ProtoFTP | |
| 34 }; | |
| 35 | |
| 36 // Load the test root cert, if it hasn't been loaded yet. | |
| 37 bool LoadTestRootCert(); | |
| 38 | |
| 39 // Start src/net/tools/testserver/testserver.py and | |
| 40 // ask it to serve the given protocol. | |
| 41 // If protocol is HTTP, and cert_path is not empty, serves HTTPS. | |
| 42 // file_root_url specifies the root url on the server that documents will be | |
| 43 // served out of. This is /files/ by default. | |
| 44 // Returns true on success, false if files not found or root cert | |
| 45 // not trusted. | |
| 46 bool Start(Protocol protocol, | |
| 47 const std::string& host_name, int port, | |
| 48 const FilePath& document_root, | |
| 49 const FilePath& cert_path, | |
| 50 const std::wstring& file_root_url); | |
| 51 | |
| 52 // Stop the server started by Start(). | |
| 53 bool Stop(); | |
| 54 | |
| 55 // If you access the server's Kill url, it will exit by itself | |
| 56 // without a call to Stop(). | |
| 57 // WaitToFinish is handy in that case. | |
| 58 // It returns true if the server exited cleanly. | |
| 59 bool WaitToFinish(int milliseconds); | |
| 60 | |
| 61 // Paths to a good, an expired, and an invalid server certificate | |
| 62 // (use as arguments to Start()). | |
| 63 FilePath GetOKCertPath(); | |
| 64 FilePath GetExpiredCertPath(); | |
| 65 | |
| 66 FilePath GetDocumentRootPath() { return document_root_dir_; } | |
| 67 | |
| 68 // Issuer name of the root cert that should be trusted for the test to work. | |
| 69 static const wchar_t kCertIssuerName[]; | |
| 70 | |
| 71 // Hostname to use for test server | |
| 72 static const char kHostName[]; | |
| 73 | |
| 74 // Different hostname to use for test server (that still resolves to same IP) | |
| 75 static const char kMismatchedHostName[]; | |
| 76 | |
| 77 // Port to use for test server | |
| 78 static const int kOKHTTPSPort; | |
| 79 | |
| 80 // Port to use for bad test server | |
| 81 static const int kBadHTTPSPort; | |
| 82 | |
| 83 private: | |
| 84 // Wait a while for the server to start, return whether | |
| 85 // we were able to make a connection to it. | |
| 86 bool WaitToStart(const std::string& host_name, int port); | |
| 87 | |
| 88 // Append to PYTHONPATH so Python can find pyftpdlib and tlslite. | |
| 89 void SetPythonPath(); | |
| 90 | |
| 91 // Path to our test root certificate. | |
| 92 FilePath GetRootCertPath(); | |
| 93 | |
| 94 // Returns false if our test root certificate is not trusted. | |
| 95 bool CheckCATrusted(); | |
| 96 | |
| 97 FilePath document_root_dir_; | |
| 98 | |
| 99 FilePath cert_dir_; | |
| 100 | |
| 101 FilePath python_runtime_; | |
| 102 | |
| 103 base::ProcessHandle process_handle_; | |
| 104 | |
| 105 #if defined(OS_LINUX) | |
| 106 struct PrivateCERTCertificate; | |
| 107 PrivateCERTCertificate *cert_; | |
| 108 #endif | |
| 109 | |
| 110 DISALLOW_COPY_AND_ASSIGN(TestServerLauncher); | |
| 111 }; | |
| 112 | |
| 113 } | |
| 114 | |
| 115 #endif // NET_BASE_SSL_TEST_UTIL_H_ | |
| OLD | NEW |