| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """This is a simple HTTP/FTP/TCP/UDP/BASIC_AUTH_PROXY/WEBSOCKET server used for | 6 """This is a simple HTTP/FTP/TCP/UDP/BASIC_AUTH_PROXY/WEBSOCKET server used for |
| 7 testing Chrome. | 7 testing Chrome. |
| 8 | 8 |
| 9 It supports several test URLs, as specified by the handlers in TestPageHandler. | 9 It supports several test URLs, as specified by the handlers in TestPageHandler. |
| 10 By default, it listens on an ephemeral port and sends the port number back to | 10 By default, it listens on an ephemeral port and sends the port number back to |
| (...skipping 1962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1973 | 1973 |
| 1974 #TODO(ibrar): Must use Find* funtion defined in google\tools | 1974 #TODO(ibrar): Must use Find* funtion defined in google\tools |
| 1975 #i.e my_data_dir = FindUpward(my_data_dir, "test", "data") | 1975 #i.e my_data_dir = FindUpward(my_data_dir, "test", "data") |
| 1976 | 1976 |
| 1977 return my_data_dir | 1977 return my_data_dir |
| 1978 | 1978 |
| 1979 def create_server(self, server_data): | 1979 def create_server(self, server_data): |
| 1980 port = self.options.port | 1980 port = self.options.port |
| 1981 host = self.options.host | 1981 host = self.options.host |
| 1982 | 1982 |
| 1983 # Work around a bug in Mac OS 10.6. Spawning a WebSockets server |
| 1984 # will result in a call to |getaddrinfo|, which fails with "nodename |
| 1985 # nor servname provided" for localhost:0 on 10.6. |
| 1986 if self.options.server_type == SERVER_WEBSOCKET and \ |
| 1987 host == "localhost" and \ |
| 1988 port == 0: |
| 1989 host = "127.0.0.1" |
| 1990 |
| 1983 if self.options.server_type == SERVER_HTTP: | 1991 if self.options.server_type == SERVER_HTTP: |
| 1984 if self.options.https: | 1992 if self.options.https: |
| 1985 pem_cert_and_key = None | 1993 pem_cert_and_key = None |
| 1986 ocsp_der = None | 1994 ocsp_der = None |
| 1987 if self.options.cert_and_key_file: | 1995 if self.options.cert_and_key_file: |
| 1988 if not os.path.isfile(self.options.cert_and_key_file): | 1996 if not os.path.isfile(self.options.cert_and_key_file): |
| 1989 raise testserver_base.OptionError( | 1997 raise testserver_base.OptionError( |
| 1990 'specified server cert file not found: ' + | 1998 'specified server cert file not found: ' + |
| 1991 self.options.cert_and_key_file + ' exiting...') | 1999 self.options.cert_and_key_file + ' exiting...') |
| 1992 pem_cert_and_key = file(self.options.cert_and_key_file, 'r').read() | 2000 pem_cert_and_key = file(self.options.cert_and_key_file, 'r').read() |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2078 websocket_options.tls_client_cert_optional = False | 2086 websocket_options.tls_client_cert_optional = False |
| 2079 websocket_options.tls_client_auth = True | 2087 websocket_options.tls_client_auth = True |
| 2080 if len(self.options.ssl_client_ca) != 1: | 2088 if len(self.options.ssl_client_ca) != 1: |
| 2081 raise testserver_base.OptionError( | 2089 raise testserver_base.OptionError( |
| 2082 'one trusted client CA file should be specified') | 2090 'one trusted client CA file should be specified') |
| 2083 if not os.path.isfile(self.options.ssl_client_ca[0]): | 2091 if not os.path.isfile(self.options.ssl_client_ca[0]): |
| 2084 raise testserver_base.OptionError( | 2092 raise testserver_base.OptionError( |
| 2085 'specified trusted client CA file not found: ' + | 2093 'specified trusted client CA file not found: ' + |
| 2086 self.options.ssl_client_ca[0] + ' exiting...') | 2094 self.options.ssl_client_ca[0] + ' exiting...') |
| 2087 websocket_options.tls_client_ca = self.options.ssl_client_ca[0] | 2095 websocket_options.tls_client_ca = self.options.ssl_client_ca[0] |
| 2096 print 'Trying to start websocket server on %s://%s:%d...' % \ |
| 2097 (scheme, websocket_options.server_host, websocket_options.port) |
| 2088 server = WebSocketServer(websocket_options) | 2098 server = WebSocketServer(websocket_options) |
| 2089 print 'WebSocket server started on %s://%s:%d...' % \ | 2099 print 'WebSocket server started on %s://%s:%d...' % \ |
| 2090 (scheme, host, server.server_port) | 2100 (scheme, host, server.server_port) |
| 2091 server_data['port'] = server.server_port | 2101 server_data['port'] = server.server_port |
| 2092 websocket_options.use_basic_auth = self.options.ws_basic_auth | 2102 websocket_options.use_basic_auth = self.options.ws_basic_auth |
| 2093 elif self.options.server_type == SERVER_TCP_ECHO: | 2103 elif self.options.server_type == SERVER_TCP_ECHO: |
| 2094 # Used for generating the key (randomly) that encodes the "echo request" | 2104 # Used for generating the key (randomly) that encodes the "echo request" |
| 2095 # message. | 2105 # message. |
| 2096 random.seed() | 2106 random.seed() |
| 2097 server = TCPEchoServer((host, port), TCPEchoHandler) | 2107 server = TCPEchoServer((host, port), TCPEchoHandler) |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2284 'OCSP response.') | 2294 'OCSP response.') |
| 2285 self.option_parser.add_option('--alert-after-handshake', | 2295 self.option_parser.add_option('--alert-after-handshake', |
| 2286 dest='alert_after_handshake', | 2296 dest='alert_after_handshake', |
| 2287 default=False, action='store_true', | 2297 default=False, action='store_true', |
| 2288 help='If set, the server will send a fatal ' | 2298 help='If set, the server will send a fatal ' |
| 2289 'alert immediately after the handshake.') | 2299 'alert immediately after the handshake.') |
| 2290 | 2300 |
| 2291 | 2301 |
| 2292 if __name__ == '__main__': | 2302 if __name__ == '__main__': |
| 2293 sys.exit(ServerRunner().main()) | 2303 sys.exit(ServerRunner().main()) |
| OLD | NEW |