Simplified the Unauthorized.__init__ signature.
It doesn't really make sense to have a `realm` parameter in the method signature. Instead, one can simply set the realm in the `challenge` dict if necessary. Also fixed the tests accordingly (and added a new one for "Bearer" auth-scheme).
This commit is contained in:
@@ -29,17 +29,22 @@ def exception_app():
|
||||
|
||||
@app.route('/401/basic')
|
||||
def handler_401_basic(request):
|
||||
raise Unauthorized("Unauthorized", "Basic", "Sanic")
|
||||
raise Unauthorized("Unauthorized", "Basic", {"realm": "Sanic"})
|
||||
|
||||
@app.route('/401/digest')
|
||||
def handler_401_digest(request):
|
||||
challenge = {
|
||||
"realm": "Sanic",
|
||||
"qop": "auth, auth-int",
|
||||
"algorithm": "MD5",
|
||||
"nonce": "abcdef",
|
||||
"opaque": "zyxwvu",
|
||||
}
|
||||
raise Unauthorized("Unauthorized", "Digest", "Sanic", challenge)
|
||||
raise Unauthorized("Unauthorized", "Digest", challenge)
|
||||
|
||||
@app.route('/401/bearer')
|
||||
def handler_401_bearer(request):
|
||||
raise Unauthorized("Unauthorized", "Bearer")
|
||||
|
||||
@app.route('/invalid')
|
||||
def handler_invalid(request):
|
||||
@@ -126,6 +131,10 @@ def test_unauthorized_exception(exception_app):
|
||||
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
|
||||
assert response.headers.get('WWW-Authenticate') == "Bearer"
|
||||
|
||||
|
||||
def test_handled_unhandled_exception(exception_app):
|
||||
"""Test that an exception not built into sanic is handled"""
|
||||
|
||||
Reference in New Issue
Block a user