| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 # Ignore abrupt close. | 173 # Ignore abrupt close. |
| 174 return True | 174 return True |
| 175 except tlslite.api.TLSError, error: | 175 except tlslite.api.TLSError, error: |
| 176 print "Handshake failure:", str(error) | 176 print "Handshake failure:", str(error) |
| 177 return False | 177 return False |
| 178 | 178 |
| 179 | 179 |
| 180 class SyncHTTPServer(ClientRestrictingServerMixIn, StoppableHTTPServer): | 180 class SyncHTTPServer(ClientRestrictingServerMixIn, StoppableHTTPServer): |
| 181 """An HTTP server that handles sync commands.""" | 181 """An HTTP server that handles sync commands.""" |
| 182 | 182 |
| 183 def __init__(self, server_address, request_handler_class): | 183 def __init__(self, server_address, xmpp_port, request_handler_class): |
| 184 # We import here to avoid pulling in chromiumsync's dependencies | 184 # We import here to avoid pulling in chromiumsync's dependencies |
| 185 # unless strictly necessary. | 185 # unless strictly necessary. |
| 186 import chromiumsync | 186 import chromiumsync |
| 187 import xmppserver | 187 import xmppserver |
| 188 StoppableHTTPServer.__init__(self, server_address, request_handler_class) | 188 StoppableHTTPServer.__init__(self, server_address, request_handler_class) |
| 189 self._sync_handler = chromiumsync.TestServer() | 189 self._sync_handler = chromiumsync.TestServer() |
| 190 self._xmpp_socket_map = {} | 190 self._xmpp_socket_map = {} |
| 191 self._xmpp_server = xmppserver.XmppServer( | 191 self._xmpp_server = xmppserver.XmppServer( |
| 192 self._xmpp_socket_map, ('localhost', 0)) | 192 self._xmpp_socket_map, ('localhost', xmpp_port)) |
| 193 self.xmpp_port = self._xmpp_server.getsockname()[1] | 193 self.xmpp_port = self._xmpp_server.getsockname()[1] |
| 194 self.authenticated = True | 194 self.authenticated = True |
| 195 | 195 |
| 196 def GetXmppServer(self): | 196 def GetXmppServer(self): |
| 197 return self._xmpp_server | 197 return self._xmpp_server |
| 198 | 198 |
| 199 def HandleCommand(self, query, raw_request): | 199 def HandleCommand(self, query, raw_request): |
| 200 return self._sync_handler.HandleCommand(query, raw_request) | 200 return self._sync_handler.HandleCommand(query, raw_request) |
| 201 | 201 |
| 202 def HandleRequestNoBlock(self): | 202 def HandleRequestNoBlock(self): |
| (...skipping 1853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2056 print 'HTTP server started on %s:%d...' % (host, server.server_port) | 2056 print 'HTTP server started on %s:%d...' % (host, server.server_port) |
| 2057 | 2057 |
| 2058 server.data_dir = MakeDataDir() | 2058 server.data_dir = MakeDataDir() |
| 2059 server.file_root_url = options.file_root_url | 2059 server.file_root_url = options.file_root_url |
| 2060 server_data['port'] = server.server_port | 2060 server_data['port'] = server.server_port |
| 2061 server._device_management_handler = None | 2061 server._device_management_handler = None |
| 2062 server.policy_keys = options.policy_keys | 2062 server.policy_keys = options.policy_keys |
| 2063 server.policy_user = options.policy_user | 2063 server.policy_user = options.policy_user |
| 2064 server.gdata_auth_token = options.auth_token | 2064 server.gdata_auth_token = options.auth_token |
| 2065 elif options.server_type == SERVER_SYNC: | 2065 elif options.server_type == SERVER_SYNC: |
| 2066 server = SyncHTTPServer((host, port), SyncPageHandler) | 2066 xmpp_port = options.xmpp_port |
| 2067 server = SyncHTTPServer((host, port), xmpp_port, SyncPageHandler) |
| 2067 print 'Sync HTTP server started on port %d...' % server.server_port | 2068 print 'Sync HTTP server started on port %d...' % server.server_port |
| 2068 print 'Sync XMPP server started on port %d...' % server.xmpp_port | 2069 print 'Sync XMPP server started on port %d...' % server.xmpp_port |
| 2069 server_data['port'] = server.server_port | 2070 server_data['port'] = server.server_port |
| 2070 server_data['xmpp_port'] = server.xmpp_port | 2071 server_data['xmpp_port'] = server.xmpp_port |
| 2071 elif options.server_type == SERVER_TCP_ECHO: | 2072 elif options.server_type == SERVER_TCP_ECHO: |
| 2072 # Used for generating the key (randomly) that encodes the "echo request" | 2073 # Used for generating the key (randomly) that encodes the "echo request" |
| 2073 # message. | 2074 # message. |
| 2074 random.seed() | 2075 random.seed() |
| 2075 server = TCPEchoServer((host, port), TCPEchoHandler) | 2076 server = TCPEchoServer((host, port), TCPEchoHandler) |
| 2076 print 'Echo TCP server started on port %d...' % server.server_port | 2077 print 'Echo TCP server started on port %d...' % server.server_port |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2157 dest='server_type', | 2158 dest='server_type', |
| 2158 help='start up a udp echo server.') | 2159 help='start up a udp echo server.') |
| 2159 option_parser.add_option('', '--log-to-console', action='store_const', | 2160 option_parser.add_option('', '--log-to-console', action='store_const', |
| 2160 const=True, default=False, | 2161 const=True, default=False, |
| 2161 dest='log_to_console', | 2162 dest='log_to_console', |
| 2162 help='Enables or disables sys.stdout logging to ' | 2163 help='Enables or disables sys.stdout logging to ' |
| 2163 'the console.') | 2164 'the console.') |
| 2164 option_parser.add_option('', '--port', default='0', type='int', | 2165 option_parser.add_option('', '--port', default='0', type='int', |
| 2165 help='Port used by the server. If unspecified, the ' | 2166 help='Port used by the server. If unspecified, the ' |
| 2166 'server will listen on an ephemeral port.') | 2167 'server will listen on an ephemeral port.') |
| 2168 option_parser.add_option('', '--xmpp-port', default='0', type='int', |
| 2169 help='Port used by the XMPP server. If unspecified, ' |
| 2170 'the XMPP server will listen on an ephemeral port.') |
| 2167 option_parser.add_option('', '--data-dir', dest='data_dir', | 2171 option_parser.add_option('', '--data-dir', dest='data_dir', |
| 2168 help='Directory from which to read the files.') | 2172 help='Directory from which to read the files.') |
| 2169 option_parser.add_option('', '--https', action='store_true', dest='https', | 2173 option_parser.add_option('', '--https', action='store_true', dest='https', |
| 2170 help='Specify that https should be used.') | 2174 help='Specify that https should be used.') |
| 2171 option_parser.add_option('', '--cert-and-key-file', dest='cert_and_key_file', | 2175 option_parser.add_option('', '--cert-and-key-file', dest='cert_and_key_file', |
| 2172 help='specify the path to the file containing the ' | 2176 help='specify the path to the file containing the ' |
| 2173 'certificate and private key for the server in PEM ' | 2177 'certificate and private key for the server in PEM ' |
| 2174 'format') | 2178 'format') |
| 2175 option_parser.add_option('', '--ocsp', dest='ocsp', default='ok', | 2179 option_parser.add_option('', '--ocsp', dest='ocsp', default='ok', |
| 2176 help='The type of OCSP response generated for the ' | 2180 help='The type of OCSP response generated for the ' |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2228 dest='host', | 2232 dest='host', |
| 2229 help='Hostname or IP upon which the server will ' | 2233 help='Hostname or IP upon which the server will ' |
| 2230 'listen. Client connections will also only be ' | 2234 'listen. Client connections will also only be ' |
| 2231 'allowed from this address.') | 2235 'allowed from this address.') |
| 2232 option_parser.add_option('', '--auth-token', dest='auth_token', | 2236 option_parser.add_option('', '--auth-token', dest='auth_token', |
| 2233 help='Specify the auth token which should be used' | 2237 help='Specify the auth token which should be used' |
| 2234 'in the authorization header for GData.') | 2238 'in the authorization header for GData.') |
| 2235 options, args = option_parser.parse_args() | 2239 options, args = option_parser.parse_args() |
| 2236 | 2240 |
| 2237 sys.exit(main(options, args)) | 2241 sys.exit(main(options, args)) |
| OLD | NEW |