mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
parent
76eaa0805b
commit
f12ef22281
@ -471,10 +471,7 @@ class Logger(object):
|
|||||||
if PY3: # b64decode returns a byte string in Python 3
|
if PY3: # b64decode returns a byte string in Python 3
|
||||||
auth = auth.decode('utf-8')
|
auth = auth.decode('utf-8')
|
||||||
auth = auth.split(":", 1)
|
auth = auth.split(":", 1)
|
||||||
except TypeError as exc:
|
except (TypeError, binascii.Error, UnicodeDecodeError) as exc:
|
||||||
self.debug("Couldn't get username: %s", exc)
|
|
||||||
return user
|
|
||||||
except binascii.Error as exc:
|
|
||||||
self.debug("Couldn't get username: %s", exc)
|
self.debug("Couldn't get username: %s", exc)
|
||||||
return user
|
return user
|
||||||
if len(auth) == 2:
|
if len(auth) == 2:
|
||||||
|
|||||||
@ -46,3 +46,22 @@ def test_get_username_from_basic_auth_header():
|
|||||||
logger = Logger(Config())
|
logger = Logger(Config())
|
||||||
atoms = logger.atoms(response, request, environ, datetime.timedelta(seconds=1))
|
atoms = logger.atoms(response, request, environ, datetime.timedelta(seconds=1))
|
||||||
assert atoms['u'] == 'brk0v'
|
assert atoms['u'] == 'brk0v'
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_username_handles_malformed_basic_auth_header():
|
||||||
|
"""Should catch a malformed auth header"""
|
||||||
|
request = SimpleNamespace(headers=())
|
||||||
|
response = SimpleNamespace(
|
||||||
|
status='200', response_length=1024, sent=1024,
|
||||||
|
headers=(('Content-Type', 'text/plain'),),
|
||||||
|
)
|
||||||
|
environ = {
|
||||||
|
'REQUEST_METHOD': 'GET', 'RAW_URI': '/my/path?foo=bar',
|
||||||
|
'PATH_INFO': '/my/path', 'QUERY_STRING': 'foo=bar',
|
||||||
|
'SERVER_PROTOCOL': 'HTTP/1.1',
|
||||||
|
'HTTP_AUTHORIZATION': 'Basic ixsTtkKzIpVTncfQjbBcnoRNoDfbnaXG',
|
||||||
|
}
|
||||||
|
logger = Logger(Config())
|
||||||
|
|
||||||
|
atoms = logger.atoms(response, request, environ, datetime.timedelta(seconds=1))
|
||||||
|
assert atoms['u'] == '-'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user