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

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: Replace accidentally removed #include <string> Created 6 years, 4 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 1902 matching lines...) Expand 10 before | Expand all | Expand 10 after
2018 'one trusted client CA file should be specified') 2019 'one trusted client CA file should be specified')
2019 if not os.path.isfile(self.options.ssl_client_ca[0]): 2020 if not os.path.isfile(self.options.ssl_client_ca[0]):
2020 raise testserver_base.OptionError( 2021 raise testserver_base.OptionError(
2021 'specified trusted client CA file not found: ' + 2022 'specified trusted client CA file not found: ' +
2022 self.options.ssl_client_ca[0] + ' exiting...') 2023 self.options.ssl_client_ca[0] + ' exiting...')
2023 websocket_options.tls_client_ca = self.options.ssl_client_ca[0] 2024 websocket_options.tls_client_ca = self.options.ssl_client_ca[0]
2024 server = WebSocketServer(websocket_options) 2025 server = WebSocketServer(websocket_options)
2025 print 'WebSocket server started on %s://%s:%d...' % \ 2026 print 'WebSocket server started on %s://%s:%d...' % \
2026 (scheme, host, server.server_port) 2027 (scheme, host, server.server_port)
2027 server_data['port'] = server.server_port 2028 server_data['port'] = server.server_port
2029 websocket_options.use_basic_auth = self.options.ws_basic_auth
2028 elif self.options.server_type == SERVER_TCP_ECHO: 2030 elif self.options.server_type == SERVER_TCP_ECHO:
2029 # Used for generating the key (randomly) that encodes the "echo request" 2031 # Used for generating the key (randomly) that encodes the "echo request"
2030 # message. 2032 # message.
2031 random.seed() 2033 random.seed()
2032 server = TCPEchoServer((host, port), TCPEchoHandler) 2034 server = TCPEchoServer((host, port), TCPEchoHandler)
2033 print 'Echo TCP server started on port %d...' % server.server_port 2035 print 'Echo TCP server started on port %d...' % server.server_port
2034 server_data['port'] = server.server_port 2036 server_data['port'] = server.server_port
2035 elif self.options.server_type == SERVER_UDP_ECHO: 2037 elif self.options.server_type == SERVER_UDP_ECHO:
2036 # Used for generating the key (randomly) that encodes the "echo request" 2038 # Used for generating the key (randomly) that encodes the "echo request"
2037 # message. 2039 # message.
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
2199 'enabled.'); 2201 'enabled.');
2200 # TODO(davidben): Add ALPN support to tlslite. 2202 # TODO(davidben): Add ALPN support to tlslite.
2201 self.option_parser.add_option('--enable-npn', dest='enable_npn', 2203 self.option_parser.add_option('--enable-npn', dest='enable_npn',
2202 default=False, const=True, 2204 default=False, const=True,
2203 action='store_const', 2205 action='store_const',
2204 help='Enable server support for the NPN ' 2206 help='Enable server support for the NPN '
2205 'extension. The server will advertise ' 2207 'extension. The server will advertise '
2206 'support for exactly one protocol, http/1.1') 2208 'support for exactly one protocol, http/1.1')
2207 self.option_parser.add_option('--file-root-url', default='/files/', 2209 self.option_parser.add_option('--file-root-url', default='/files/',
2208 help='Specify a root URL for files served.') 2210 help='Specify a root URL for files served.')
2211 # TODO(ricea): Generalize this to support basic auth for HTTP too.
2212 self.option_parser.add_option('--ws-basic-auth', action='store_true',
2213 dest='ws_basic_auth',
2214 help='Enable basic-auth for WebSocket')
2209 2215
2210 2216
2211 if __name__ == '__main__': 2217 if __name__ == '__main__':
2212 sys.exit(ServerRunner().main()) 2218 sys.exit(ServerRunner().main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698