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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 self.allow_draft75 = False | 96 self.allow_draft75 = False |
97 self.strict = True | 97 self.strict = True |
98 | 98 |
99 self.use_tls = False | 99 self.use_tls = False |
100 self.private_key = None | 100 self.private_key = None |
101 self.certificate = None | 101 self.certificate = None |
102 self.tls_client_auth = False | 102 self.tls_client_auth = False |
103 self.tls_client_ca = None | 103 self.tls_client_ca = None |
104 self.tls_module = 'ssl' | 104 self.tls_module = 'ssl' |
105 self.use_basic_auth = False | 105 self.use_basic_auth = False |
| 106 self.basic_auth_credential = 'Basic ' + base64.b64encode('test:test') |
106 | 107 |
107 | 108 |
108 class RecordingSSLSessionCache(object): | 109 class RecordingSSLSessionCache(object): |
109 """RecordingSSLSessionCache acts as a TLS session cache and maintains a log of | 110 """RecordingSSLSessionCache acts as a TLS session cache and maintains a log of |
110 lookups and inserts in order to test session cache behaviours.""" | 111 lookups and inserts in order to test session cache behaviours.""" |
111 | 112 |
112 def __init__(self): | 113 def __init__(self): |
113 self.log = [] | 114 self.log = [] |
114 | 115 |
115 def __getitem__(self, sessionID): | 116 def __getitem__(self, sessionID): |
(...skipping 1901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2017 'one trusted client CA file should be specified') | 2018 'one trusted client CA file should be specified') |
2018 if not os.path.isfile(self.options.ssl_client_ca[0]): | 2019 if not os.path.isfile(self.options.ssl_client_ca[0]): |
2019 raise testserver_base.OptionError( | 2020 raise testserver_base.OptionError( |
2020 'specified trusted client CA file not found: ' + | 2021 'specified trusted client CA file not found: ' + |
2021 self.options.ssl_client_ca[0] + ' exiting...') | 2022 self.options.ssl_client_ca[0] + ' exiting...') |
2022 websocket_options.tls_client_ca = self.options.ssl_client_ca[0] | 2023 websocket_options.tls_client_ca = self.options.ssl_client_ca[0] |
2023 server = WebSocketServer(websocket_options) | 2024 server = WebSocketServer(websocket_options) |
2024 print 'WebSocket server started on %s://%s:%d...' % \ | 2025 print 'WebSocket server started on %s://%s:%d...' % \ |
2025 (scheme, host, server.server_port) | 2026 (scheme, host, server.server_port) |
2026 server_data['port'] = server.server_port | 2027 server_data['port'] = server.server_port |
| 2028 websocket_options.use_basic_auth = self.options.ws_basic_auth |
2027 elif self.options.server_type == SERVER_TCP_ECHO: | 2029 elif self.options.server_type == SERVER_TCP_ECHO: |
2028 # Used for generating the key (randomly) that encodes the "echo request" | 2030 # Used for generating the key (randomly) that encodes the "echo request" |
2029 # message. | 2031 # message. |
2030 random.seed() | 2032 random.seed() |
2031 server = TCPEchoServer((host, port), TCPEchoHandler) | 2033 server = TCPEchoServer((host, port), TCPEchoHandler) |
2032 print 'Echo TCP server started on port %d...' % server.server_port | 2034 print 'Echo TCP server started on port %d...' % server.server_port |
2033 server_data['port'] = server.server_port | 2035 server_data['port'] = server.server_port |
2034 elif self.options.server_type == SERVER_UDP_ECHO: | 2036 elif self.options.server_type == SERVER_UDP_ECHO: |
2035 # Used for generating the key (randomly) that encodes the "echo request" | 2037 # Used for generating the key (randomly) that encodes the "echo request" |
2036 # message. | 2038 # message. |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2192 'enabled.'); | 2194 'enabled.'); |
2193 # TODO(davidben): Add ALPN support to tlslite. | 2195 # TODO(davidben): Add ALPN support to tlslite. |
2194 self.option_parser.add_option('--enable-npn', dest='enable_npn', | 2196 self.option_parser.add_option('--enable-npn', dest='enable_npn', |
2195 default=False, const=True, | 2197 default=False, const=True, |
2196 action='store_const', | 2198 action='store_const', |
2197 help='Enable server support for the NPN ' | 2199 help='Enable server support for the NPN ' |
2198 'extension. The server will advertise ' | 2200 'extension. The server will advertise ' |
2199 'support for exactly one protocol, http/1.1') | 2201 'support for exactly one protocol, http/1.1') |
2200 self.option_parser.add_option('--file-root-url', default='/files/', | 2202 self.option_parser.add_option('--file-root-url', default='/files/', |
2201 help='Specify a root URL for files served.') | 2203 help='Specify a root URL for files served.') |
| 2204 # TODO(ricea): Generalise this to support basic auth for HTTP too. |
| 2205 self.option_parser.add_option('--ws-basic-auth', action='store_true', |
| 2206 dest='ws_basic_auth', |
| 2207 help='Enable basic-auth for WebSocket') |
2202 | 2208 |
2203 | 2209 |
2204 if __name__ == '__main__': | 2210 if __name__ == '__main__': |
2205 sys.exit(ServerRunner().main()) | 2211 sys.exit(ServerRunner().main()) |
OLD | NEW |