| OLD | NEW |
| 1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
| 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2008 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 It defaults to living on localhost:8888. | 9 It defaults to living on localhost:8888. |
| 10 It can use https if you specify the flag --https=CERT where CERT is the path | 10 It can use https if you specify the flag --https=CERT where CERT is the path |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 | 684 |
| 685 def AuthBasicHandler(self): | 685 def AuthBasicHandler(self): |
| 686 """This handler tests 'Basic' authentication. It just sends a page with | 686 """This handler tests 'Basic' authentication. It just sends a page with |
| 687 title 'user/pass' if you succeed.""" | 687 title 'user/pass' if you succeed.""" |
| 688 | 688 |
| 689 if not self._ShouldHandleRequest("/auth-basic"): | 689 if not self._ShouldHandleRequest("/auth-basic"): |
| 690 return False | 690 return False |
| 691 | 691 |
| 692 username = userpass = password = b64str = "" | 692 username = userpass = password = b64str = "" |
| 693 | 693 |
| 694 set_cookie_if_challenged = self.path.find('?set-cookie-if-challenged') > 0 |
| 695 |
| 694 auth = self.headers.getheader('authorization') | 696 auth = self.headers.getheader('authorization') |
| 695 try: | 697 try: |
| 696 if not auth: | 698 if not auth: |
| 697 raise Exception('no auth') | 699 raise Exception('no auth') |
| 698 b64str = re.findall(r'Basic (\S+)', auth)[0] | 700 b64str = re.findall(r'Basic (\S+)', auth)[0] |
| 699 userpass = base64.b64decode(b64str) | 701 userpass = base64.b64decode(b64str) |
| 700 username, password = re.findall(r'([^:]+):(\S+)', userpass)[0] | 702 username, password = re.findall(r'([^:]+):(\S+)', userpass)[0] |
| 701 if password != 'secret': | 703 if password != 'secret': |
| 702 raise Exception('wrong password') | 704 raise Exception('wrong password') |
| 703 except Exception, e: | 705 except Exception, e: |
| 704 # Authentication failed. | 706 # Authentication failed. |
| 705 self.send_response(401) | 707 self.send_response(401) |
| 706 self.send_header('WWW-Authenticate', 'Basic realm="testrealm"') | 708 self.send_header('WWW-Authenticate', 'Basic realm="testrealm"') |
| 707 self.send_header('Content-type', 'text/html') | 709 self.send_header('Content-type', 'text/html') |
| 710 if set_cookie_if_challenged: |
| 711 self.send_header('Set-Cookie', 'got_challenged=true') |
| 708 self.end_headers() | 712 self.end_headers() |
| 709 self.wfile.write('<html><head>') | 713 self.wfile.write('<html><head>') |
| 710 self.wfile.write('<title>Denied: %s</title>' % e) | 714 self.wfile.write('<title>Denied: %s</title>' % e) |
| 711 self.wfile.write('</head><body>') | 715 self.wfile.write('</head><body>') |
| 712 self.wfile.write('auth=%s<p>' % auth) | 716 self.wfile.write('auth=%s<p>' % auth) |
| 713 self.wfile.write('b64str=%s<p>' % b64str) | 717 self.wfile.write('b64str=%s<p>' % b64str) |
| 714 self.wfile.write('username: %s<p>' % username) | 718 self.wfile.write('username: %s<p>' % username) |
| 715 self.wfile.write('userpass: %s<p>' % userpass) | 719 self.wfile.write('userpass: %s<p>' % userpass) |
| 716 self.wfile.write('password: %s<p>' % password) | 720 self.wfile.write('password: %s<p>' % password) |
| 717 self.wfile.write('You sent:<br>%s<p>' % self.headers) | 721 self.wfile.write('You sent:<br>%s<p>' % self.headers) |
| 718 self.wfile.write('</body></html>') | 722 self.wfile.write('</body></html>') |
| 719 return True | 723 return True |
| 720 | 724 |
| 721 # Authentication successful. (Return a cachable response to allow for | 725 # Authentication successful. (Return a cachable response to allow for |
| 722 # testing cached pages that require authentication.) | 726 # testing cached pages that require authentication.) |
| 723 if_none_match = self.headers.getheader('if-none-match') | 727 if_none_match = self.headers.getheader('if-none-match') |
| 724 if if_none_match == "abc": | 728 if if_none_match == "abc": |
| 725 self.send_response(304) | 729 self.send_response(304) |
| 726 self.end_headers() | 730 self.end_headers() |
| 727 else: | 731 else: |
| 728 self.send_response(200) | 732 self.send_response(200) |
| 729 self.send_header('Content-type', 'text/html') | 733 self.send_header('Content-type', 'text/html') |
| 730 self.send_header('Cache-control', 'max-age=60000') | 734 self.send_header('Cache-control', 'max-age=60000') |
| 731 self.send_header('Etag', 'abc') | 735 self.send_header('Etag', 'abc') |
| 732 self.end_headers() | 736 self.end_headers() |
| 733 self.wfile.write('<html><head>') | 737 self.wfile.write('<html><head>') |
| 734 self.wfile.write('<title>%s/%s</title>' % (username, password)) | 738 self.wfile.write('<title>%s/%s</title>' % (username, password)) |
| 735 self.wfile.write('</head><body>') | 739 self.wfile.write('</head><body>') |
| 736 self.wfile.write('auth=%s<p>' % auth) | 740 self.wfile.write('auth=%s<p>' % auth) |
| 741 self.wfile.write('You sent:<br>%s<p>' % self.headers) |
| 737 self.wfile.write('</body></html>') | 742 self.wfile.write('</body></html>') |
| 738 | 743 |
| 739 return True | 744 return True |
| 740 | 745 |
| 741 def AuthDigestHandler(self): | 746 def AuthDigestHandler(self): |
| 742 """This handler tests 'Digest' authentication. It just sends a page with | 747 """This handler tests 'Digest' authentication. It just sends a page with |
| 743 title 'user/pass' if you succeed.""" | 748 title 'user/pass' if you succeed.""" |
| 744 | 749 |
| 745 if not self._ShouldHandleRequest("/auth-digest"): | 750 if not self._ShouldHandleRequest("/auth-digest"): |
| 746 return False | 751 return False |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 help='Port used by the server') | 1098 help='Port used by the server') |
| 1094 option_parser.add_option('', '--data-dir', dest='data_dir', | 1099 option_parser.add_option('', '--data-dir', dest='data_dir', |
| 1095 help='Directory from which to read the files') | 1100 help='Directory from which to read the files') |
| 1096 option_parser.add_option('', '--https', dest='cert', | 1101 option_parser.add_option('', '--https', dest='cert', |
| 1097 help='Specify that https should be used, specify ' | 1102 help='Specify that https should be used, specify ' |
| 1098 'the path to the cert containing the private key ' | 1103 'the path to the cert containing the private key ' |
| 1099 'the server should use') | 1104 'the server should use') |
| 1100 options, args = option_parser.parse_args() | 1105 options, args = option_parser.parse_args() |
| 1101 | 1106 |
| 1102 sys.exit(main(options, args)) | 1107 sys.exit(main(options, args)) |
| OLD | NEW |