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

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

Issue 10073033: Run safebrowsing_service_test through the net testserver code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 8 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
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 import simplejson as json 57 import simplejson as json
58 58
59 if sys.platform == 'win32': 59 if sys.platform == 'win32':
60 import msvcrt 60 import msvcrt
61 61
62 SERVER_HTTP = 0 62 SERVER_HTTP = 0
63 SERVER_FTP = 1 63 SERVER_FTP = 1
64 SERVER_SYNC = 2 64 SERVER_SYNC = 2
65 SERVER_TCP_ECHO = 3 65 SERVER_TCP_ECHO = 3
66 SERVER_UDP_ECHO = 4 66 SERVER_UDP_ECHO = 4
67 SERVER_SAFEBROWSING = 5
67 68
68 # Using debug() seems to cause hangs on XP: see http://crbug.com/64515 . 69 # Using debug() seems to cause hangs on XP: see http://crbug.com/64515 .
69 debug_output = sys.stderr 70 debug_output = sys.stderr
70 def debug(str): 71 def debug(str):
71 debug_output.write(str + "\n") 72 debug_output.write(str + "\n")
72 debug_output.flush() 73 debug_output.flush()
73 74
74 class RecordingSSLSessionCache(object): 75 class RecordingSSLSessionCache(object):
75 """RecordingSSLSessionCache acts as a TLS session cache and maintains a log of 76 """RecordingSSLSessionCache acts as a TLS session cache and maintains a log of
76 lookups and inserts in order to test session cache behaviours.""" 77 lookups and inserts in order to test session cache behaviours."""
(...skipping 1994 matching lines...) Expand 10 before | Expand all | Expand 10 after
2071 server = TCPEchoServer((host, port), TCPEchoHandler) 2072 server = TCPEchoServer((host, port), TCPEchoHandler)
2072 print 'Echo TCP server started on port %d...' % server.server_port 2073 print 'Echo TCP server started on port %d...' % server.server_port
2073 server_data['port'] = server.server_port 2074 server_data['port'] = server.server_port
2074 elif options.server_type == SERVER_UDP_ECHO: 2075 elif options.server_type == SERVER_UDP_ECHO:
2075 # Used for generating the key (randomly) that encodes the "echo request" 2076 # Used for generating the key (randomly) that encodes the "echo request"
2076 # message. 2077 # message.
2077 random.seed() 2078 random.seed()
2078 server = UDPEchoServer((host, port), UDPEchoHandler) 2079 server = UDPEchoServer((host, port), UDPEchoHandler)
2079 print 'Echo UDP server started on port %d...' % server.server_port 2080 print 'Echo UDP server started on port %d...' % server.server_port
2080 server_data['port'] = server.server_port 2081 server_data['port'] = server.server_port
2081 # means FTP Server 2082 elif options.server_type == SERVER_FTP:
2082 else:
2083 my_data_dir = MakeDataDir() 2083 my_data_dir = MakeDataDir()
2084 2084
2085 # Instantiate a dummy authorizer for managing 'virtual' users 2085 # Instantiate a dummy authorizer for managing 'virtual' users
2086 authorizer = pyftpdlib.ftpserver.DummyAuthorizer() 2086 authorizer = pyftpdlib.ftpserver.DummyAuthorizer()
2087 2087
2088 # Define a new user having full r/w permissions and a read-only 2088 # Define a new user having full r/w permissions and a read-only
2089 # anonymous user 2089 # anonymous user
2090 authorizer.add_user('chrome', 'chrome', my_data_dir, perm='elradfmw') 2090 authorizer.add_user('chrome', 'chrome', my_data_dir, perm='elradfmw')
2091 2091
2092 authorizer.add_anonymous(my_data_dir) 2092 authorizer.add_anonymous(my_data_dir)
2093 2093
2094 # Instantiate FTP handler class 2094 # Instantiate FTP handler class
2095 ftp_handler = pyftpdlib.ftpserver.FTPHandler 2095 ftp_handler = pyftpdlib.ftpserver.FTPHandler
2096 ftp_handler.authorizer = authorizer 2096 ftp_handler.authorizer = authorizer
2097 2097
2098 # Define a customized banner (string returned when client connects) 2098 # Define a customized banner (string returned when client connects)
2099 ftp_handler.banner = ("pyftpdlib %s based ftpd ready." % 2099 ftp_handler.banner = ("pyftpdlib %s based ftpd ready." %
2100 pyftpdlib.ftpserver.__ver__) 2100 pyftpdlib.ftpserver.__ver__)
2101 2101
2102 # Instantiate FTP server class and listen to address:port 2102 # Instantiate FTP server class and listen to address:port
2103 server = pyftpdlib.ftpserver.FTPServer((host, port), ftp_handler) 2103 server = pyftpdlib.ftpserver.FTPServer((host, port), ftp_handler)
2104 server_data['port'] = server.socket.getsockname()[1] 2104 server_data['port'] = server.socket.getsockname()[1]
2105 print 'FTP server started on port %d...' % server_data['port'] 2105 print 'FTP server started on port %d...' % server_data['port']
2106 elif options.server_type == SERVER_SAFEBROWSING:
2107 sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)),
2108 '..', '..', '..', 'third_party',
2109 'safe_browsing', 'testing'))
2110 import safebrowsing_test_server
2111 server = safebrowsing_test_server.SetupServer(
2112 options.data_dir, host, port, opt_enforce_caching=False,
2113 opt_validate_database=True)
2114 print 'Safebrowsing HTTP server started on port %d...' % server.server_port
2115 server_data['port'] = server.server_port
2116 else:
2117 print 'unknown server type', options.server_type
2118 return 1
2106 2119
2107 # Notify the parent that we've started. (BaseServer subclasses 2120 # Notify the parent that we've started. (BaseServer subclasses
2108 # bind their sockets on construction.) 2121 # bind their sockets on construction.)
2109 if options.startup_pipe is not None: 2122 if options.startup_pipe is not None:
2110 server_data_json = json.dumps(server_data) 2123 server_data_json = json.dumps(server_data)
2111 server_data_len = len(server_data_json) 2124 server_data_len = len(server_data_json)
2112 print 'sending server_data: %s (%d bytes)' % ( 2125 print 'sending server_data: %s (%d bytes)' % (
2113 server_data_json, server_data_len) 2126 server_data_json, server_data_len)
2114 if sys.platform == 'win32': 2127 if sys.platform == 'win32':
2115 fd = msvcrt.open_osfhandle(options.startup_pipe, 0) 2128 fd = msvcrt.open_osfhandle(options.startup_pipe, 0)
(...skipping 29 matching lines...) Expand all
2145 dest='server_type', 2158 dest='server_type',
2146 help='start up a sync server.') 2159 help='start up a sync server.')
2147 option_parser.add_option('', '--tcp-echo', action='store_const', 2160 option_parser.add_option('', '--tcp-echo', action='store_const',
2148 const=SERVER_TCP_ECHO, default=SERVER_HTTP, 2161 const=SERVER_TCP_ECHO, default=SERVER_HTTP,
2149 dest='server_type', 2162 dest='server_type',
2150 help='start up a tcp echo server.') 2163 help='start up a tcp echo server.')
2151 option_parser.add_option('', '--udp-echo', action='store_const', 2164 option_parser.add_option('', '--udp-echo', action='store_const',
2152 const=SERVER_UDP_ECHO, default=SERVER_HTTP, 2165 const=SERVER_UDP_ECHO, default=SERVER_HTTP,
2153 dest='server_type', 2166 dest='server_type',
2154 help='start up a udp echo server.') 2167 help='start up a udp echo server.')
2168 option_parser.add_option('', '--safebrowsing', action='store_const',
2169 const=SERVER_SAFEBROWSING, default=SERVER_HTTP,
2170 dest='server_type',
2171 help='start up a safebrowsing test server.')
2155 option_parser.add_option('', '--log-to-console', action='store_const', 2172 option_parser.add_option('', '--log-to-console', action='store_const',
2156 const=True, default=False, 2173 const=True, default=False,
2157 dest='log_to_console', 2174 dest='log_to_console',
2158 help='Enables or disables sys.stdout logging to ' 2175 help='Enables or disables sys.stdout logging to '
2159 'the console.') 2176 'the console.')
2160 option_parser.add_option('', '--port', default='0', type='int', 2177 option_parser.add_option('', '--port', default='0', type='int',
2161 help='Port used by the server. If unspecified, the ' 2178 help='Port used by the server. If unspecified, the '
2162 'server will listen on an ephemeral port.') 2179 'server will listen on an ephemeral port.')
2163 option_parser.add_option('', '--data-dir', dest='data_dir', 2180 option_parser.add_option('', '--data-dir', dest='data_dir',
2164 help='Directory from which to read the files.') 2181 help='Directory from which to read the files.')
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2217 dest='host', 2234 dest='host',
2218 help='Hostname or IP upon which the server will ' 2235 help='Hostname or IP upon which the server will '
2219 'listen. Client connections will also only be ' 2236 'listen. Client connections will also only be '
2220 'allowed from this address.') 2237 'allowed from this address.')
2221 option_parser.add_option('', '--auth-token', dest='auth_token', 2238 option_parser.add_option('', '--auth-token', dest='auth_token',
2222 help='Specify the auth token which should be used' 2239 help='Specify the auth token which should be used'
2223 'in the authorization header for GData.') 2240 'in the authorization header for GData.')
2224 options, args = option_parser.parse_args() 2241 options, args = option_parser.parse_args()
2225 2242
2226 sys.exit(main(options, args)) 2243 sys.exit(main(options, args))
OLDNEW
« net/test/remote_test_server.cc ('K') | « net/test/remote_test_server.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698