From 9c02cdbad91c98083b4d1536361cfa0ae90700ab Mon Sep 17 00:00:00 2001 From: Raphael Deem Date: Thu, 21 Dec 2017 17:54:57 -0800 Subject: [PATCH] double quotes in unauthorized exception per rfc7230 --- sanic/exceptions.py | 2 +- tests/test_exceptions.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sanic/exceptions.py b/sanic/exceptions.py index 0133fd64..6da747f2 100644 --- a/sanic/exceptions.py +++ b/sanic/exceptions.py @@ -263,7 +263,7 @@ class Unauthorized(SanicException): # if auth-scheme is specified, set "WWW-Authenticate" header if scheme is not None: - values = ["{!s}={!r}".format(k, v) for k, v in kwargs.items()] + values = ['{!s}="{!s}"'.format(k, v) for k, v in kwargs.items()] challenge = ', '.join(values) self.headers = { diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 16d08459..b4e2c6ea 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -138,7 +138,7 @@ def test_unauthorized_exception(exception_app): request, response = exception_app.test_client.get('/401/basic') assert response.status == 401 assert response.headers.get('WWW-Authenticate') is not None - assert response.headers.get('WWW-Authenticate') == "Basic realm='Sanic'" + assert response.headers.get('WWW-Authenticate') == 'Basic realm="Sanic"' request, response = exception_app.test_client.get('/401/digest') assert response.status == 401 @@ -146,10 +146,10 @@ def test_unauthorized_exception(exception_app): auth_header = response.headers.get('WWW-Authenticate') assert auth_header is not None assert auth_header.startswith('Digest') - assert "qop='auth, auth-int'" in auth_header - assert "algorithm='MD5'" in auth_header - assert "nonce='abcdef'" in auth_header - assert "opaque='zyxwvu'" in auth_header + assert 'qop="auth, auth-int"' in auth_header + assert 'algorithm="MD5"' in auth_header + assert 'nonce="abcdef"' in auth_header + assert 'opaque="zyxwvu"' in auth_header request, response = exception_app.test_client.get('/401/bearer') assert response.status == 401