zerver/decorator.py: Correctly encode/decode strings.

This commit is contained in:
Eklavya Sharma 2016-07-04 11:13:27 +05:30 committed by Tim Abbott
parent 4e698ab1f6
commit 6a63870136
2 changed files with 2 additions and 3 deletions

View File

@ -40,7 +40,6 @@ zerver/tests/test_narrow.py
exclude_py2 = []
exclude_py3 = """
zerver/decorator.py
zerver/lib/actions.py
zerver/lib/bugdown/__init__.py
zerver/lib/bugdown/codehilite.py

View File

@ -348,11 +348,11 @@ def authenticated_rest_api_view(is_webhook=False):
try:
# Grab the base64-encoded authentication string, decode it, and split it into
# the email and API key
auth_type, encoded_value = request.META['HTTP_AUTHORIZATION'].split()
auth_type, b64encoded_credentials = request.META['HTTP_AUTHORIZATION'].split()
# case insensitive per RFC 1945
if auth_type.lower() != "basic":
return json_error(_("Only Basic authentication is supported."))
role, api_key = base64.b64decode(encoded_value).split(":")
role, api_key = base64.b64decode(b64encoded_credentials.encode('utf-8')).decode('utf-8').split(":")
except ValueError:
json_error(_("Invalid authorization header for basic auth"))
except KeyError: