summaryrefslogtreecommitdiffstats
path: root/net/base/ssl_test_util.h
diff options
context:
space:
mode:
authordkegel@google.com <dkegel@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-14 05:26:10 +0000
committerdkegel@google.com <dkegel@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-14 05:26:10 +0000
commitee287e40bb740d7238717a97b5f635ae3e68c47a (patch)
tree4515656a0a870939dbcf6892b48baa02c99c26ca /net/base/ssl_test_util.h
parent0afe827a49501c6801c3c9efbbdb1f64aa010beb (diff)
downloadchromium_src-ee287e40bb740d7238717a97b5f635ae3e68c47a.zip
chromium_src-ee287e40bb740d7238717a97b5f635ae3e68c47a.tar.gz
chromium_src-ee287e40bb740d7238717a97b5f635ae3e68c47a.tar.bz2
ssl_client_socket_unittest.cc: launch local server with TestServerLauncher
rather than use bugs.webkit.org, fixes TODO(darin) Add tests with bad server certs ssl_client_socket_nss.cc: fix bugs revealed by new tests tcp_pinger.cc: helper class to do synchronous connect from tests. Has to work inside ui tests where one can't use TestCompletionCallback. ssl_test_util: renamed class TestServerLauncher, added Start/Stop methods. Make part of net.lib to work around link error in test_shell_tests. url_request_unittest.h: use TestServerLauncher to manage server. SSL client tests disabled for now on Mac. BUG=7114 Review URL: http://codereview.chromium.org/16207 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9823 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/ssl_test_util.h')
-rw-r--r--net/base/ssl_test_util.h73
1 files changed, 61 insertions, 12 deletions
diff --git a/net/base/ssl_test_util.h b/net/base/ssl_test_util.h
index 9daa4cc..dd6d95d 100644
--- a/net/base/ssl_test_util.h
+++ b/net/base/ssl_test_util.h
@@ -5,49 +5,98 @@
#ifndef NET_BASE_SSL_TEST_UTIL_H_
#define NET_BASE_SSL_TEST_UTIL_H_
-#include "build/build_config.h"
+#include <string>
#include "base/file_path.h"
+#include "base/process_util.h"
+#include "base/ref_counted.h"
+#include "build/build_config.h"
-// TODO(dkegel): share this between net/base and
+// TODO(dkegel): share this between net/base and
// chrome/browser without putting it in net.lib
-class SSLTestUtil {
+namespace net {
+
+// This object bounds the lifetime of an external python-based HTTP/HTTPS/FTP
+// server that can provide various responses useful for testing.
+// A few basic convenience methods are provided, but no
+// URL handling methods (those belong at a higher layer, e.g. in
+// url_request_unittest.h).
+
+class TestServerLauncher {
public:
- SSLTestUtil();
+ TestServerLauncher();
- ~SSLTestUtil();
+ virtual ~TestServerLauncher();
- FilePath GetRootCertPath();
+ enum Protocol {
+ ProtoHTTP, ProtoFTP
+ };
- FilePath GetOKCertPath();
+ // Start src/net/tools/test_server/test_server.py and
+ // ask it to serve the given protocol.
+ // If protocol is HTTP, and cert_path is not empty, serves HTTPS.
+ // Returns true on success, false if files not found or root cert
+ // not trusted.
+ bool Start(Protocol protocol,
+ const std::string& host_name, int port,
+ const FilePath& document_root,
+ const FilePath& cert_path);
+ // Stop the server started by Start().
+ void Stop();
+
+ // Paths to a good, an expired, and an invalid server certificate
+ // (use as arguments to Start()).
+ FilePath GetOKCertPath();
FilePath GetExpiredCertPath();
+ // Issuer name of the root cert that should be trusted for the test to work.
+ static const wchar_t kCertIssuerName[];
+
// Hostname to use for test server
static const char kHostName[];
+ // Different hostname to use for test server (that still resolves to same IP)
+ static const char kMismatchedHostName[];
+
// Port to use for test server
static const int kOKHTTPSPort;
// Port to use for bad test server
static const int kBadHTTPSPort;
- // Issuer name of the cert that should be trusted for the test to work.
- static const wchar_t kCertIssuerName[];
+ private:
+ // Wait a while for the server to start, return whether
+ // we were able to make a connection to it.
+ bool Wait(const std::string& host_name, int port);
+
+ // Append to PYTHONPATH so Python can find pyftpdlib and tlslite.
+ void SetPythonPath();
+
+ // Path to our test root certificate.
+ FilePath GetRootCertPath();
// Returns false if our test root certificate is not trusted.
bool CheckCATrusted();
- private:
+ FilePath data_dir_;
+
FilePath cert_dir_;
+ FilePath python_runtime_;
+
+ base::ProcessHandle process_handle_;
+
#if defined(OS_LINUX)
struct PrivateCERTCertificate;
PrivateCERTCertificate *cert_;
#endif
- DISALLOW_COPY_AND_ASSIGN(SSLTestUtil);
+ DISALLOW_COPY_AND_ASSIGN(TestServerLauncher);
};
-#endif // NET_BASE_SSL_TEST_UTIL_H_
+}
+
+#endif // NET_BASE_SSL_TEST_UTIL_H_
+