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

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

Issue 8015004: webRequest.onAuthRequired listeners can provide authentication credentials. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Handle multiple blocking onAuthRequired Created 9 years, 2 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/python2.4 1 #!/usr/bin/python2.4
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 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 962 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 if 'set-cookie-if-challenged' in query_params: 973 if 'set-cookie-if-challenged' in query_params:
974 set_cookie_if_challenged = True 974 set_cookie_if_challenged = True
975 if 'password' in query_params: 975 if 'password' in query_params:
976 expected_password = query_params['password'][0] 976 expected_password = query_params['password'][0]
977 if 'realm' in query_params: 977 if 'realm' in query_params:
978 realm = query_params['realm'][0] 978 realm = query_params['realm'][0]
979 979
980 auth = self.headers.getheader('authorization') 980 auth = self.headers.getheader('authorization')
981 try: 981 try:
982 if not auth: 982 if not auth:
983 print "No Auth"
983 raise Exception('no auth') 984 raise Exception('no auth')
984 b64str = re.findall(r'Basic (\S+)', auth)[0] 985 b64str = re.findall(r'Basic (\S+)', auth)[0]
985 userpass = base64.b64decode(b64str) 986 userpass = base64.b64decode(b64str)
986 username, password = re.findall(r'([^:]+):(\S+)', userpass)[0] 987 username, password = re.findall(r'([^:]+):(\S+)', userpass)[0]
987 if password != expected_password: 988 if password != expected_password:
989 print "Wrong Password, given %s" % password
988 raise Exception('wrong password') 990 raise Exception('wrong password')
989 except Exception, e: 991 except Exception, e:
990 # Authentication failed. 992 # Authentication failed.
991 self.send_response(401) 993 self.send_response(401)
992 self.send_header('WWW-Authenticate', 'Basic realm="%s"' % realm) 994 self.send_header('WWW-Authenticate', 'Basic realm="%s"' % realm)
993 self.send_header('Content-type', 'text/html') 995 self.send_header('Content-type', 'text/html')
994 if set_cookie_if_challenged: 996 if set_cookie_if_challenged:
995 self.send_header('Set-Cookie', 'got_challenged=true') 997 self.send_header('Set-Cookie', 'got_challenged=true')
996 self.end_headers() 998 self.end_headers()
997 self.wfile.write('<html><head>') 999 self.wfile.write('<html><head>')
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after
1825 'random key if none is specified on the command ' 1827 'random key if none is specified on the command '
1826 'line.') 1828 'line.')
1827 option_parser.add_option('', '--policy-user', default='user@example.com', 1829 option_parser.add_option('', '--policy-user', default='user@example.com',
1828 dest='policy_user', 1830 dest='policy_user',
1829 help='Specify the user name the server should ' 1831 help='Specify the user name the server should '
1830 'report back to the client as the user owning the ' 1832 'report back to the client as the user owning the '
1831 'token used for making the policy request.') 1833 'token used for making the policy request.')
1832 options, args = option_parser.parse_args() 1834 options, args = option_parser.parse_args()
1833 1835
1834 sys.exit(main(options, args)) 1836 sys.exit(main(options, args))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698