| OLD | NEW |
| 1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
| 2 # Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2010 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 server used for testing Chrome. | 6 """This is a simple HTTP 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 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 return True | 906 return True |
| 907 | 907 |
| 908 def AuthBasicHandler(self): | 908 def AuthBasicHandler(self): |
| 909 """This handler tests 'Basic' authentication. It just sends a page with | 909 """This handler tests 'Basic' authentication. It just sends a page with |
| 910 title 'user/pass' if you succeed.""" | 910 title 'user/pass' if you succeed.""" |
| 911 | 911 |
| 912 if not self._ShouldHandleRequest("/auth-basic"): | 912 if not self._ShouldHandleRequest("/auth-basic"): |
| 913 return False | 913 return False |
| 914 | 914 |
| 915 username = userpass = password = b64str = "" | 915 username = userpass = password = b64str = "" |
| 916 expected_password = 'secret' |
| 917 realm = 'testrealm' |
| 918 set_cookie_if_challenged = False |
| 916 | 919 |
| 917 set_cookie_if_challenged = self.path.find('?set-cookie-if-challenged') > 0 | 920 _, _, url_path, _, query, _ = urlparse.urlparse(self.path) |
| 921 query_params = cgi.parse_qs(query, True) |
| 922 if 'set-cookie-if-challenged' in query_params: |
| 923 set_cookie_if_challenged = True |
| 924 if 'password' in query_params: |
| 925 expected_password = query_params['password'][0] |
| 926 if 'realm' in query_params: |
| 927 realm = query_params['realm'][0] |
| 918 | 928 |
| 919 auth = self.headers.getheader('authorization') | 929 auth = self.headers.getheader('authorization') |
| 920 try: | 930 try: |
| 921 if not auth: | 931 if not auth: |
| 922 raise Exception('no auth') | 932 raise Exception('no auth') |
| 923 b64str = re.findall(r'Basic (\S+)', auth)[0] | 933 b64str = re.findall(r'Basic (\S+)', auth)[0] |
| 924 userpass = base64.b64decode(b64str) | 934 userpass = base64.b64decode(b64str) |
| 925 username, password = re.findall(r'([^:]+):(\S+)', userpass)[0] | 935 username, password = re.findall(r'([^:]+):(\S+)', userpass)[0] |
| 926 if password != 'secret': | 936 if password != expected_password: |
| 927 raise Exception('wrong password') | 937 raise Exception('wrong password') |
| 928 except Exception, e: | 938 except Exception, e: |
| 929 # Authentication failed. | 939 # Authentication failed. |
| 930 self.send_response(401) | 940 self.send_response(401) |
| 931 self.send_header('WWW-Authenticate', 'Basic realm="testrealm"') | 941 self.send_header('WWW-Authenticate', 'Basic realm="%s"' % realm) |
| 932 self.send_header('Content-type', 'text/html') | 942 self.send_header('Content-type', 'text/html') |
| 933 if set_cookie_if_challenged: | 943 if set_cookie_if_challenged: |
| 934 self.send_header('Set-Cookie', 'got_challenged=true') | 944 self.send_header('Set-Cookie', 'got_challenged=true') |
| 935 self.end_headers() | 945 self.end_headers() |
| 936 self.wfile.write('<html><head>') | 946 self.wfile.write('<html><head>') |
| 937 self.wfile.write('<title>Denied: %s</title>' % e) | 947 self.wfile.write('<title>Denied: %s</title>' % e) |
| 938 self.wfile.write('</head><body>') | 948 self.wfile.write('</head><body>') |
| 939 self.wfile.write('auth=%s<p>' % auth) | 949 self.wfile.write('auth=%s<p>' % auth) |
| 940 self.wfile.write('b64str=%s<p>' % b64str) | 950 self.wfile.write('b64str=%s<p>' % b64str) |
| 941 self.wfile.write('username: %s<p>' % username) | 951 self.wfile.write('username: %s<p>' % username) |
| 942 self.wfile.write('userpass: %s<p>' % userpass) | 952 self.wfile.write('userpass: %s<p>' % userpass) |
| 943 self.wfile.write('password: %s<p>' % password) | 953 self.wfile.write('password: %s<p>' % password) |
| 944 self.wfile.write('You sent:<br>%s<p>' % self.headers) | 954 self.wfile.write('You sent:<br>%s<p>' % self.headers) |
| 945 self.wfile.write('</body></html>') | 955 self.wfile.write('</body></html>') |
| 946 return True | 956 return True |
| 947 | 957 |
| 948 # Authentication successful. (Return a cachable response to allow for | 958 # Authentication successful. (Return a cachable response to allow for |
| 949 # testing cached pages that require authentication.) | 959 # testing cached pages that require authentication.) |
| 950 if_none_match = self.headers.getheader('if-none-match') | 960 if_none_match = self.headers.getheader('if-none-match') |
| 951 if if_none_match == "abc": | 961 if if_none_match == "abc": |
| 952 self.send_response(304) | 962 self.send_response(304) |
| 953 self.end_headers() | 963 self.end_headers() |
| 964 elif url_path.endswith(".gif"): |
| 965 # Using chrome/test/data/google/logo.gif as the test image |
| 966 test_image_path = ['google', 'logo.gif'] |
| 967 gif_path = os.path.join(self.server.data_dir, *test_image_path) |
| 968 if not os.path.isfile(gif_path): |
| 969 self.send_error(404) |
| 970 return True |
| 971 |
| 972 f = open(gif_path, "rb") |
| 973 data = f.read() |
| 974 f.close() |
| 975 |
| 976 self.send_response(200) |
| 977 self.send_header('Content-type', 'image/gif') |
| 978 self.send_header('Cache-control', 'max-age=60000') |
| 979 self.send_header('Etag', 'abc') |
| 980 self.end_headers() |
| 981 self.wfile.write(data) |
| 954 else: | 982 else: |
| 955 self.send_response(200) | 983 self.send_response(200) |
| 956 self.send_header('Content-type', 'text/html') | 984 self.send_header('Content-type', 'text/html') |
| 957 self.send_header('Cache-control', 'max-age=60000') | 985 self.send_header('Cache-control', 'max-age=60000') |
| 958 self.send_header('Etag', 'abc') | 986 self.send_header('Etag', 'abc') |
| 959 self.end_headers() | 987 self.end_headers() |
| 960 self.wfile.write('<html><head>') | 988 self.wfile.write('<html><head>') |
| 961 self.wfile.write('<title>%s/%s</title>' % (username, password)) | 989 self.wfile.write('<title>%s/%s</title>' % (username, password)) |
| 962 self.wfile.write('</head><body>') | 990 self.wfile.write('</head><body>') |
| 963 self.wfile.write('auth=%s<p>' % auth) | 991 self.wfile.write('auth=%s<p>' % auth) |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1470 'option may appear multiple times, indicating ' | 1498 'option may appear multiple times, indicating ' |
| 1471 'multiple algorithms should be enabled.'); | 1499 'multiple algorithms should be enabled.'); |
| 1472 option_parser.add_option('', '--file-root-url', default='/files/', | 1500 option_parser.add_option('', '--file-root-url', default='/files/', |
| 1473 help='Specify a root URL for files served.') | 1501 help='Specify a root URL for files served.') |
| 1474 option_parser.add_option('', '--startup-pipe', type='int', | 1502 option_parser.add_option('', '--startup-pipe', type='int', |
| 1475 dest='startup_pipe', | 1503 dest='startup_pipe', |
| 1476 help='File handle of pipe to parent process') | 1504 help='File handle of pipe to parent process') |
| 1477 options, args = option_parser.parse_args() | 1505 options, args = option_parser.parse_args() |
| 1478 | 1506 |
| 1479 sys.exit(main(options, args)) | 1507 sys.exit(main(options, args)) |
| OLD | NEW |