| OLD | NEW |
| 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 1952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1963 return False | 1963 return False |
| 1964 result, raw_reply = self.server._sync_handler.HandleCreateSyncedBookmarks() | 1964 result, raw_reply = self.server._sync_handler.HandleCreateSyncedBookmarks() |
| 1965 self.send_response(result) | 1965 self.send_response(result) |
| 1966 self.send_header('Content-Type', 'text/html') | 1966 self.send_header('Content-Type', 'text/html') |
| 1967 self.send_header('Content-Length', len(raw_reply)) | 1967 self.send_header('Content-Length', len(raw_reply)) |
| 1968 self.end_headers() | 1968 self.end_headers() |
| 1969 self.wfile.write(raw_reply) | 1969 self.wfile.write(raw_reply) |
| 1970 return True; | 1970 return True; |
| 1971 | 1971 |
| 1972 | 1972 |
| 1973 def MakeDataDir(): | 1973 def MakeDataDir(options): |
| 1974 if options.data_dir: | 1974 if options.data_dir: |
| 1975 if not os.path.isdir(options.data_dir): | 1975 if not os.path.isdir(options.data_dir): |
| 1976 print 'specified data dir not found: ' + options.data_dir + ' exiting...' | 1976 print 'specified data dir not found: ' + options.data_dir + ' exiting...' |
| 1977 return None | 1977 return None |
| 1978 my_data_dir = options.data_dir | 1978 my_data_dir = options.data_dir |
| 1979 else: | 1979 else: |
| 1980 # Create the default path to our data dir, relative to the exe dir. | 1980 # Create the default path to our data dir, relative to the exe dir. |
| 1981 my_data_dir = os.path.dirname(sys.argv[0]) | 1981 my_data_dir = os.path.dirname(sys.argv[0]) |
| 1982 my_data_dir = os.path.join(my_data_dir, "..", "..", "..", "..", | 1982 my_data_dir = os.path.join(my_data_dir, "..", "..", "..", "..", |
| 1983 "test", "data") | 1983 "test", "data") |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2156 def do_HEAD(self): | 2156 def do_HEAD(self): |
| 2157 self._do_common_method() | 2157 self._do_common_method() |
| 2158 | 2158 |
| 2159 | 2159 |
| 2160 class FileMultiplexer: | 2160 class FileMultiplexer: |
| 2161 def __init__(self, fd1, fd2) : | 2161 def __init__(self, fd1, fd2) : |
| 2162 self.__fd1 = fd1 | 2162 self.__fd1 = fd1 |
| 2163 self.__fd2 = fd2 | 2163 self.__fd2 = fd2 |
| 2164 | 2164 |
| 2165 def __del__(self) : | 2165 def __del__(self) : |
| 2166 if self.__fd1 != sys.stdout and self.__fd1 != sys.stderr: | 2166 self.close() |
| 2167 self.__fd1.close() | |
| 2168 if self.__fd2 != sys.stdout and self.__fd2 != sys.stderr: | |
| 2169 self.__fd2.close() | |
| 2170 | 2167 |
| 2171 def write(self, text) : | 2168 def write(self, text) : |
| 2172 self.__fd1.write(text) | 2169 self.__fd1.write(text) |
| 2173 self.__fd2.write(text) | 2170 self.__fd2.write(text) |
| 2174 | 2171 |
| 2175 def flush(self) : | 2172 def flush(self) : |
| 2176 self.__fd1.flush() | 2173 self.__fd1.flush() |
| 2177 self.__fd2.flush() | 2174 self.__fd2.flush() |
| 2178 | 2175 |
| 2176 def close(self): |
| 2177 if self.__fd1 != sys.stdout and self.__fd1 != sys.stderr: |
| 2178 self.__fd1.close() |
| 2179 if self.__fd2 != sys.stdout and self.__fd2 != sys.stderr: |
| 2180 self.__fd2.close() |
| 2181 |
| 2182 |
| 2179 def main(options, args): | 2183 def main(options, args): |
| 2180 logfile = open('testserver.log', 'w') | 2184 logfile = open('testserver.log', 'w') |
| 2181 sys.stderr = FileMultiplexer(sys.stderr, logfile) | 2185 sys.stderr = FileMultiplexer(sys.stderr, logfile) |
| 2182 if options.log_to_console: | 2186 if options.log_to_console: |
| 2183 sys.stdout = FileMultiplexer(sys.stdout, logfile) | 2187 sys.stdout = FileMultiplexer(sys.stdout, logfile) |
| 2184 else: | 2188 else: |
| 2185 sys.stdout = logfile | 2189 sys.stdout = logfile |
| 2186 | 2190 |
| 2187 port = options.port | 2191 port = options.port |
| 2188 host = options.host | 2192 host = options.host |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2240 return | 2244 return |
| 2241 server = HTTPSServer((host, port), TestPageHandler, pem_cert_and_key, | 2245 server = HTTPSServer((host, port), TestPageHandler, pem_cert_and_key, |
| 2242 options.ssl_client_auth, options.ssl_client_ca, | 2246 options.ssl_client_auth, options.ssl_client_ca, |
| 2243 options.ssl_bulk_cipher, options.record_resume, | 2247 options.ssl_bulk_cipher, options.record_resume, |
| 2244 options.tls_intolerant) | 2248 options.tls_intolerant) |
| 2245 print 'HTTPS server started on %s:%d...' % (host, server.server_port) | 2249 print 'HTTPS server started on %s:%d...' % (host, server.server_port) |
| 2246 else: | 2250 else: |
| 2247 server = HTTPServer((host, port), TestPageHandler) | 2251 server = HTTPServer((host, port), TestPageHandler) |
| 2248 print 'HTTP server started on %s:%d...' % (host, server.server_port) | 2252 print 'HTTP server started on %s:%d...' % (host, server.server_port) |
| 2249 | 2253 |
| 2250 server.data_dir = MakeDataDir() | 2254 server.data_dir = MakeDataDir(options) |
| 2251 server.file_root_url = options.file_root_url | 2255 server.file_root_url = options.file_root_url |
| 2252 server_data['port'] = server.server_port | 2256 server_data['port'] = server.server_port |
| 2253 server._device_management_handler = None | 2257 server._device_management_handler = None |
| 2254 server.policy_keys = options.policy_keys | 2258 server.policy_keys = options.policy_keys |
| 2255 server.policy_user = options.policy_user | 2259 server.policy_user = options.policy_user |
| 2256 server.gdata_auth_token = options.auth_token | 2260 server.gdata_auth_token = options.auth_token |
| 2257 elif options.server_type == SERVER_WEBSOCKET: | 2261 elif options.server_type == SERVER_WEBSOCKET: |
| 2258 # Launch pywebsocket via WebSocketServer. | 2262 # Launch pywebsocket via WebSocketServer. |
| 2259 logger = logging.getLogger() | 2263 logger = logging.getLogger() |
| 2260 logger.addHandler(logging.StreamHandler()) | 2264 logger.addHandler(logging.StreamHandler()) |
| 2261 # TODO(toyoshim): Remove following os.chdir. Currently this operation | 2265 # TODO(toyoshim): Remove following os.chdir. Currently this operation |
| 2262 # is required to work correctly. It should be fixed from pywebsocket side. | 2266 # is required to work correctly. It should be fixed from pywebsocket side. |
| 2263 os.chdir(MakeDataDir()) | 2267 os.chdir(MakeDataDir(options)) |
| 2264 websocket_options = WebSocketOptions(host, port, '.') | 2268 websocket_options = WebSocketOptions(host, port, '.') |
| 2265 if options.cert_and_key_file: | 2269 if options.cert_and_key_file: |
| 2266 websocket_options.use_tls = True | 2270 websocket_options.use_tls = True |
| 2267 websocket_options.private_key = options.cert_and_key_file | 2271 websocket_options.private_key = options.cert_and_key_file |
| 2268 websocket_options.certificate = options.cert_and_key_file | 2272 websocket_options.certificate = options.cert_and_key_file |
| 2269 if options.ssl_client_auth: | 2273 if options.ssl_client_auth: |
| 2270 websocket_options.tls_client_auth = True | 2274 websocket_options.tls_client_auth = True |
| 2271 if len(options.ssl_client_ca) != 1: | 2275 if len(options.ssl_client_ca) != 1: |
| 2272 # TODO(toyoshim): Provide non-zero exit code for these error cases. | 2276 # TODO(toyoshim): Provide non-zero exit code for these error cases. |
| 2273 # Ditto on other paths here and there. | 2277 # Ditto on other paths here and there. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2302 random.seed() | 2306 random.seed() |
| 2303 server = UDPEchoServer((host, port), UDPEchoHandler) | 2307 server = UDPEchoServer((host, port), UDPEchoHandler) |
| 2304 print 'Echo UDP server started on port %d...' % server.server_port | 2308 print 'Echo UDP server started on port %d...' % server.server_port |
| 2305 server_data['port'] = server.server_port | 2309 server_data['port'] = server.server_port |
| 2306 elif options.server_type == SERVER_BASIC_AUTH_PROXY: | 2310 elif options.server_type == SERVER_BASIC_AUTH_PROXY: |
| 2307 server = HTTPServer((host, port), BasicAuthProxyRequestHandler) | 2311 server = HTTPServer((host, port), BasicAuthProxyRequestHandler) |
| 2308 print 'BasicAuthProxy server started on port %d...' % server.server_port | 2312 print 'BasicAuthProxy server started on port %d...' % server.server_port |
| 2309 server_data['port'] = server.server_port | 2313 server_data['port'] = server.server_port |
| 2310 # means FTP Server | 2314 # means FTP Server |
| 2311 else: | 2315 else: |
| 2312 my_data_dir = MakeDataDir() | 2316 my_data_dir = MakeDataDir(options) |
| 2313 | 2317 |
| 2314 # Instantiate a dummy authorizer for managing 'virtual' users | 2318 # Instantiate a dummy authorizer for managing 'virtual' users |
| 2315 authorizer = pyftpdlib.ftpserver.DummyAuthorizer() | 2319 authorizer = pyftpdlib.ftpserver.DummyAuthorizer() |
| 2316 | 2320 |
| 2317 # Define a new user having full r/w permissions and a read-only | 2321 # Define a new user having full r/w permissions and a read-only |
| 2318 # anonymous user | 2322 # anonymous user |
| 2319 authorizer.add_user('chrome', 'chrome', my_data_dir, perm='elradfmw') | 2323 authorizer.add_user('chrome', 'chrome', my_data_dir, perm='elradfmw') |
| 2320 | 2324 |
| 2321 authorizer.add_anonymous(my_data_dir) | 2325 authorizer.add_anonymous(my_data_dir) |
| 2322 | 2326 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2465 dest='host', | 2469 dest='host', |
| 2466 help='Hostname or IP upon which the server will ' | 2470 help='Hostname or IP upon which the server will ' |
| 2467 'listen. Client connections will also only be ' | 2471 'listen. Client connections will also only be ' |
| 2468 'allowed from this address.') | 2472 'allowed from this address.') |
| 2469 option_parser.add_option('', '--auth-token', dest='auth_token', | 2473 option_parser.add_option('', '--auth-token', dest='auth_token', |
| 2470 help='Specify the auth token which should be used' | 2474 help='Specify the auth token which should be used' |
| 2471 'in the authorization header for GData.') | 2475 'in the authorization header for GData.') |
| 2472 options, args = option_parser.parse_args() | 2476 options, args = option_parser.parse_args() |
| 2473 | 2477 |
| 2474 sys.exit(main(options, args)) | 2478 sys.exit(main(options, args)) |
| OLD | NEW |