Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Side by Side Diff: net/tools/testserver/testserver.py

Issue 336263005: Map WebSocket URL schemes to HTTP URL schemes for auth purposes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Factor out WebSocketDispatchOnFinishOpeningHandshake() into a separate function. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
2198 'enabled.'); 2200 'enabled.');
2199 # TODO(davidben): Add ALPN support to tlslite. 2201 # TODO(davidben): Add ALPN support to tlslite.
2200 self.option_parser.add_option('--enable-npn', dest='enable_npn', 2202 self.option_parser.add_option('--enable-npn', dest='enable_npn',
2201 default=False, const=True, 2203 default=False, const=True,
2202 action='store_const', 2204 action='store_const',
2203 help='Enable server support for the NPN ' 2205 help='Enable server support for the NPN '
2204 'extension. The server will advertise ' 2206 'extension. The server will advertise '
2205 'support for exactly one protocol, http/1.1') 2207 'support for exactly one protocol, http/1.1')
2206 self.option_parser.add_option('--file-root-url', default='/files/', 2208 self.option_parser.add_option('--file-root-url', default='/files/',
2207 help='Specify a root URL for files served.') 2209 help='Specify a root URL for files served.')
2210 # TODO(ricea): Generalise this to support basic auth for HTTP too.
Johnny 2014/07/08 20:27:40 nit: s/Generalise/Generalize/
Adam Rice 2014/07/09 06:35:01 Done.
2211 self.option_parser.add_option('--ws-basic-auth', action='store_true',
2212 dest='ws_basic_auth',
2213 help='Enable basic-auth for WebSocket')
2208 2214
2209 2215
2210 if __name__ == '__main__': 2216 if __name__ == '__main__':
2211 sys.exit(ServerRunner().main()) 2217 sys.exit(ServerRunner().main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698