diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2017-12-17 12:34:32 -0500 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2017-12-17 12:38:41 -0500 |
| commit | 661dc06ffa9a872824d628975657b21325654f2e (patch) | |
| tree | 36027d71593578354faf50c5a227cf637388a4ff /cherrypy/lib/auth_basic.py | |
| parent | 49bc467811b74e100a6f5e007409e9d9baaa5f6a (diff) | |
| parent | 0e4542295a33fd776f2ca5f1bb151eb8ddf919a0 (diff) | |
| download | cherrypy-git-archive/1285-always-bytes.tar.gz | |
Merge branch 'master' into bb-pr-85archive/1285-always-bytes
Diffstat (limited to 'cherrypy/lib/auth_basic.py')
| -rw-r--r-- | cherrypy/lib/auth_basic.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/cherrypy/lib/auth_basic.py b/cherrypy/lib/auth_basic.py index 5ba16f7f..44eb9b14 100644 --- a/cherrypy/lib/auth_basic.py +++ b/cherrypy/lib/auth_basic.py @@ -2,6 +2,12 @@ # -*- coding: utf-8 -*- # vim:ts=4:sw=4:expandtab:fileencoding=utf-8 +import binascii + +import cherrypy +from cherrypy._cpcompat import base64_decode + + __doc__ = """This module provides a CherryPy 3.x tool which implements the server-side of HTTP Basic Access Authentication, as described in :rfc:`2617`. @@ -22,10 +28,6 @@ as the credentials store:: __author__ = 'visteya' __date__ = 'April 2009' -import binascii -from cherrypy._cpcompat import base64_decode -import cherrypy - def checkpassword_dict(user_password_dict): """Returns a checkpassword function which checks credentials @@ -70,7 +72,9 @@ def basic_auth(realm, checkpassword, debug=False): auth_header = request.headers.get('authorization') if auth_header is not None: - try: + # split() error, base64.decodestring() error + msg = 'Bad Request' + with cherrypy.HTTPError.handle((ValueError, binascii.Error), 400, msg): scheme, params = auth_header.split(' ', 1) if scheme.lower() == 'basic': username, password = base64_decode(params).split(':', 1) @@ -79,12 +83,9 @@ def basic_auth(realm, checkpassword, debug=False): cherrypy.log('Auth succeeded', 'TOOLS.AUTH_BASIC') request.login = username return # successful authentication - # split() error, base64.decodestring() error - except (ValueError, binascii.Error): - raise cherrypy.HTTPError(400, 'Bad Request') # Respond with 401 status and a WWW-Authenticate header cherrypy.serving.response.headers[ 'www-authenticate'] = 'Basic realm="%s"' % realm raise cherrypy.HTTPError( - 401, "You are not authorized to access that resource") + 401, 'You are not authorized to access that resource') |
