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

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

Issue 11175002: testserver.py TLS and client auth support on WebSocket. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add crbug Created 8 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « net/test/base_test_server.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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/SYNC/TCP/UDP/ server used for testing Chrome. 6 """This is a simple HTTP/FTP/SYNC/TCP/UDP/ server used for testing Chrome.
7 7
8 It supports several test URLs, as specified by the handlers in TestPageHandler. 8 It supports several test URLs, as specified by the handlers in TestPageHandler.
9 By default, it listens on an ephemeral port and sends the port number back to 9 By default, it listens on an ephemeral port and sends the port number back to
10 the originating process over a pipe. The originating process can specify an 10 the originating process over a pipe. The originating process can specify an
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 self.port = port 86 self.port = port
87 self.websock_handlers = data_dir 87 self.websock_handlers = data_dir
88 self.scan_dir = None 88 self.scan_dir = None
89 self.allow_handlers_outside_root_dir = False 89 self.allow_handlers_outside_root_dir = False
90 self.websock_handlers_map_file = None 90 self.websock_handlers_map_file = None
91 self.cgi_directories = [] 91 self.cgi_directories = []
92 self.is_executable_method = None 92 self.is_executable_method = None
93 self.allow_draft75 = False 93 self.allow_draft75 = False
94 self.strict = True 94 self.strict = True
95 95
96 # TODO(toyoshim): Support SSL and authenticates (http://crbug.com/137639)
97 self.use_tls = False 96 self.use_tls = False
98 self.private_key = None 97 self.private_key = None
99 self.certificate = None 98 self.certificate = None
99 self.tls_client_auth = False
100 self.tls_client_ca = None 100 self.tls_client_ca = None
101 self.use_basic_auth = False 101 self.use_basic_auth = False
102 102
103 class RecordingSSLSessionCache(object): 103 class RecordingSSLSessionCache(object):
104 """RecordingSSLSessionCache acts as a TLS session cache and maintains a log of 104 """RecordingSSLSessionCache acts as a TLS session cache and maintains a log of
105 lookups and inserts in order to test session cache behaviours.""" 105 lookups and inserts in order to test session cache behaviours."""
106 106
107 def __init__(self): 107 def __init__(self):
108 self.log = [] 108 self.log = []
109 109
(...skipping 2118 matching lines...) Expand 10 before | Expand all | Expand 10 after
2228 minica.GenerateCertKeyAndOCSP( 2228 minica.GenerateCertKeyAndOCSP(
2229 subject = "127.0.0.1", 2229 subject = "127.0.0.1",
2230 ocsp_url = ("http://%s:%d/ocsp" % 2230 ocsp_url = ("http://%s:%d/ocsp" %
2231 (host, ocsp_server.server_port)), 2231 (host, ocsp_server.server_port)),
2232 ocsp_state = ocsp_state) 2232 ocsp_state = ocsp_state)
2233 2233
2234 ocsp_server.ocsp_response = ocsp_der 2234 ocsp_server.ocsp_response = ocsp_der
2235 2235
2236 for ca_cert in options.ssl_client_ca: 2236 for ca_cert in options.ssl_client_ca:
2237 if not os.path.isfile(ca_cert): 2237 if not os.path.isfile(ca_cert):
2238 print 'specified trusted client CA file not found: ' + ca_cert + \ 2238 print ('specified trusted client CA file not found: ' + ca_cert +
2239 ' exiting...' 2239 ' exiting...')
2240 return 2240 return
2241 server = HTTPSServer((host, port), TestPageHandler, pem_cert_and_key, 2241 server = HTTPSServer((host, port), TestPageHandler, pem_cert_and_key,
2242 options.ssl_client_auth, options.ssl_client_ca, 2242 options.ssl_client_auth, options.ssl_client_ca,
2243 options.ssl_bulk_cipher, options.record_resume, 2243 options.ssl_bulk_cipher, options.record_resume,
2244 options.tls_intolerant) 2244 options.tls_intolerant)
2245 print 'HTTPS server started on %s:%d...' % (host, server.server_port) 2245 print 'HTTPS server started on %s:%d...' % (host, server.server_port)
2246 else: 2246 else:
2247 server = HTTPServer((host, port), TestPageHandler) 2247 server = HTTPServer((host, port), TestPageHandler)
2248 print 'HTTP server started on %s:%d...' % (host, server.server_port) 2248 print 'HTTP server started on %s:%d...' % (host, server.server_port)
2249 2249
2250 server.data_dir = MakeDataDir() 2250 server.data_dir = MakeDataDir()
2251 server.file_root_url = options.file_root_url 2251 server.file_root_url = options.file_root_url
2252 server_data['port'] = server.server_port 2252 server_data['port'] = server.server_port
2253 server._device_management_handler = None 2253 server._device_management_handler = None
2254 server.policy_keys = options.policy_keys 2254 server.policy_keys = options.policy_keys
2255 server.policy_user = options.policy_user 2255 server.policy_user = options.policy_user
2256 server.gdata_auth_token = options.auth_token 2256 server.gdata_auth_token = options.auth_token
2257 elif options.server_type == SERVER_WEBSOCKET: 2257 elif options.server_type == SERVER_WEBSOCKET:
2258 # Launch pywebsocket via WebSocketServer. 2258 # Launch pywebsocket via WebSocketServer.
2259 logger = logging.getLogger() 2259 logger = logging.getLogger()
2260 logger.addHandler(logging.StreamHandler()) 2260 logger.addHandler(logging.StreamHandler())
2261 # TODO(toyoshim): Remove following os.chdir. Currently this operation 2261 # TODO(toyoshim): Remove following os.chdir. Currently this operation
2262 # is required to work correctly. It should be fixed from pywebsocket side. 2262 # is required to work correctly. It should be fixed from pywebsocket side.
2263 os.chdir(MakeDataDir()) 2263 os.chdir(MakeDataDir())
2264 server = WebSocketServer(WebSocketOptions(host, port, '.')) 2264 websocket_options = WebSocketOptions(host, port, '.')
2265 if options.cert_and_key_file:
2266 websocket_options.use_tls = True
2267 websocket_options.private_key = options.cert_and_key_file
2268 websocket_options.certificate = options.cert_and_key_file
2269 if options.ssl_client_auth:
2270 websocket_options.tls_client_auth = True
2271 if len(options.ssl_client_ca) != 1:
2272 # TODO(toyoshim): Provide non-zero exit code for these error cases.
2273 # Ditto on other paths here and there.
2274 # http://crbug.com/156539
2275 print 'one trusted client CA file should be specified'
2276 return
2277 if not os.path.isfile(options.ssl_client_ca[0]):
2278 print ('specified trusted client CA file not found: ' +
2279 options.ssl_client_ca[0] + ' exiting...')
2280 return
2281 websocket_options.tls_client_ca = options.ssl_client_ca[0]
2282 server = WebSocketServer(websocket_options)
2265 print 'WebSocket server started on %s:%d...' % (host, server.server_port) 2283 print 'WebSocket server started on %s:%d...' % (host, server.server_port)
2266 server_data['port'] = server.server_port 2284 server_data['port'] = server.server_port
2267 elif options.server_type == SERVER_SYNC: 2285 elif options.server_type == SERVER_SYNC:
2268 xmpp_port = options.xmpp_port 2286 xmpp_port = options.xmpp_port
2269 server = SyncHTTPServer((host, port), xmpp_port, SyncPageHandler) 2287 server = SyncHTTPServer((host, port), xmpp_port, SyncPageHandler)
2270 print 'Sync HTTP server started on port %d...' % server.server_port 2288 print 'Sync HTTP server started on port %d...' % server.server_port
2271 print 'Sync XMPP server started on port %d...' % server.xmpp_port 2289 print 'Sync XMPP server started on port %d...' % server.xmpp_port
2272 server_data['port'] = server.server_port 2290 server_data['port'] = server.server_port
2273 server_data['xmpp_port'] = server.xmpp_port 2291 server_data['xmpp_port'] = server.xmpp_port
2274 elif options.server_type == SERVER_TCP_ECHO: 2292 elif options.server_type == SERVER_TCP_ECHO:
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
2447 dest='host', 2465 dest='host',
2448 help='Hostname or IP upon which the server will ' 2466 help='Hostname or IP upon which the server will '
2449 'listen. Client connections will also only be ' 2467 'listen. Client connections will also only be '
2450 'allowed from this address.') 2468 'allowed from this address.')
2451 option_parser.add_option('', '--auth-token', dest='auth_token', 2469 option_parser.add_option('', '--auth-token', dest='auth_token',
2452 help='Specify the auth token which should be used' 2470 help='Specify the auth token which should be used'
2453 'in the authorization header for GData.') 2471 'in the authorization header for GData.')
2454 options, args = option_parser.parse_args() 2472 options, args = option_parser.parse_args()
2455 2473
2456 sys.exit(main(options, args)) 2474 sys.exit(main(options, args))
OLDNEW
« no previous file with comments | « net/test/base_test_server.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698