diff options
author | yuzo@chromium.org <yuzo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-16 05:38:44 +0000 |
---|---|---|
committer | yuzo@chromium.org <yuzo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-16 05:38:44 +0000 |
commit | 5ceeeae9fd67e4a5bfbec01c0b89bc15460c18dc (patch) | |
tree | 8447a82157d0fab025ca06fcbced90b1c10acf5e /webkit | |
parent | 28295ec43b82a3769795399cdf1bcfc47568714d (diff) | |
download | chromium_src-5ceeeae9fd67e4a5bfbec01c0b89bc15460c18dc.zip chromium_src-5ceeeae9fd67e4a5bfbec01c0b89bc15460c18dc.tar.gz chromium_src-5ceeeae9fd67e4a5bfbec01c0b89bc15460c18dc.tar.bz2 |
Support WSS in websocket_server.py.
With this change, websocket_server.py can start a pywebsocket server also for
WSS. We'll run two instances of pywebsocket in testing: one for WS, the other
for WSS.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/273035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29251 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/tools/layout_tests/layout_package/websocket_server.py | 81 |
1 files changed, 64 insertions, 17 deletions
diff --git a/webkit/tools/layout_tests/layout_package/websocket_server.py b/webkit/tools/layout_tests/layout_package/websocket_server.py index 3554e0a..4eb1d47 100644 --- a/webkit/tools/layout_tests/layout_package/websocket_server.py +++ b/webkit/tools/layout_tests/layout_package/websocket_server.py @@ -22,9 +22,11 @@ import http_server sys.path.append(path_utils.PathFromBase('tools', 'python')) import google.httpd_utils -_LOG_PREFIX = 'pywebsocket.log-' +_WS_LOG_PREFIX = 'pywebsocket.ws.log-' +_WSS_LOG_PREFIX = 'pywebsocket.wss.log-' _DEFAULT_WS_PORT = 8880 +_DEFAULT_WSS_PORT = 9323 _DEFAULT_ROOT = '.' @@ -35,12 +37,17 @@ def RemoveLogFiles(folder, starts_with): full_path = os.path.join(folder, file) os.remove(full_path) + class PyWebSocketNotStarted(Exception): pass + class PyWebSocket(http_server.Lighttpd): - def __init__(self, output_dir, background=False, port=_DEFAULT_WS_PORT, - root=_DEFAULT_ROOT): + def __init__(self, output_dir, port=_DEFAULT_WS_PORT, + root=_DEFAULT_ROOT, + use_tls=False, + private_key=http_server.Lighttpd._pem_file, + certificate=http_server.Lighttpd._pem_file): """Args: output_dir: the absolute path to the layout test result directory """ @@ -48,8 +55,16 @@ class PyWebSocket(http_server.Lighttpd): self._process = None self._port = port self._root = root + self._use_tls = use_tls + self._private_key = private_key + self._certificate = certificate if self._port: self._port = int(self._port) + if self._use_tls: + self._server_name = 'PyWebSocket(Secure)' + else: + self._server_name = 'PyWebSocket' + # Webkit tests try: self._webkit_tests = path_utils.PathFromBase( @@ -59,17 +74,21 @@ class PyWebSocket(http_server.Lighttpd): def Start(self): if not self._webkit_tests: - logging.info('No need to start PyWebSocket server.') + logging.info('No need to start %s server.' % self._server_name) return if self.IsRunning(): - raise PyWebSocketNotStarted('PyWebSocket is already running.') + raise PyWebSocketNotStarted('%s is already running.' % self._server_name) time_str = time.strftime('%d%b%Y-%H%M%S') - log_file_name = _LOG_PREFIX + time_str + '.txt' + if self._use_tls: + log_prefix = _WSS_LOG_PREFIX + else: + log_prefix = _WS_LOG_PREFIX + log_file_name = log_prefix + time_str + '.txt' error_log = os.path.join(self._output_dir, log_file_name) # Remove old log files. We only need to keep the last ones. - RemoveLogFiles(self._output_dir, _LOG_PREFIX) + RemoveLogFiles(self._output_dir, log_prefix) python_interp = sys.executable pywebsocket_base = path_utils.PathFromBase('third_party', 'pywebsocket') @@ -80,6 +99,9 @@ class PyWebSocket(http_server.Lighttpd): '-p', str(self._port), '-d', self._webkit_tests, ] + if self._use_tls: + start_cmd.extend(['-t', '-k', self._private_key, + '-c', self._certificate]) # Put the cygwin directory first in the path to find cygwin1.dll env = os.environ @@ -93,28 +115,35 @@ class PyWebSocket(http_server.Lighttpd): 'setup_mount.bat') subprocess.Popen(setup_mount).wait() - env['PYTHONPATH'] = pywebsocket_base + os.path.pathsep + env['PYTHONPATH'] + env['PYTHONPATH'] = (pywebsocket_base + os.path.pathsep + + env.get('PYTHONPATH', '')) - logging.info('Starting PyWebSocket server.') + logging.info('Starting %s server.' % self._server_name) self._process = subprocess.Popen(start_cmd, env=env) # Wait a bit before checking the liveness of the server. time.sleep(0.5) - url = 'http://127.0.0.1:%d/' % self._port + if self._use_tls: + url = 'https' + else: + url = 'http' + url = url + '://127.0.0.1:%d/' % self._port if not google.httpd_utils.UrlIsAlive(url): raise PyWebSocketNotStarted( - 'Failed to start PyWebSocket server on port %s.' % self._port) + 'Failed to start %s server on port %s.' % + (self._server_name, self._port)) # Our process terminated already if self._process.returncode != None: - raise PyWebSocketNotStarted('Failed to start PyWebSocket server.') + raise PyWebSocketNotStarted( + 'Failed to start %s server.' % self._server_name) def Stop(self, force=False): if not force and not self.IsRunning(): return - logging.info('Shutting down PyWebSocket server.') + logging.info('Shutting down %s server.' % self._server_name) platform_utils.KillProcess(self._process.pid) self._process = None @@ -127,12 +156,30 @@ if '__main__' == __name__: # manually. option_parser = optparse.OptionParser() option_parser.add_option('-p', '--port', dest='port', - default=_DEFAULT_WS_PORT, help='Port to listen on') + default=None, help='Port to listen on') option_parser.add_option('-r', '--root', dest='root', default='.', help='Absolute path to DocumentRoot') + option_parser.add_option('-t', '--tls', dest='use_tls', action='store_true', + default=False, help='use TLS (wss://)') + option_parser.add_option('-k', '--private_key', dest='private_key', + default='', help='TLS private key file.') + option_parser.add_option('-c', '--certificate', dest='certificate', + default='', help='TLS certificate file.') options, args = option_parser.parse_args() - pywebsocket = PyWebSocket(tempfile.gettempdir(), - port=options.port, - root=options.root) + if not options.port: + if options.use_tls: + options.port = _DEFAULT_WSS_PORT + else: + options.port = _DEFAULT_WS_PORT + + kwds = {'port':options.port, + 'root':options.root, + 'use_tls':options.use_tls} + if options.private_key: + kwds['private_key'] = options.private_key + if options.certificate: + kwds['certificate'] = options.certificate + + pywebsocket = PyWebSocket(tempfile.gettempdir(), **kwds) pywebsocket.Start() |