forked from pallets-eco/flask-security-3.0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow overriding of unauthorized callback.
Related to issue pallets-eco#255.
- Loading branch information
Showing
3 changed files
with
43 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,3 +192,19 @@ def test_password_unicode_password_salt(client): | |
assert response.status_code == 302 | ||
response = authenticate(client, follow_redirects=True) | ||
assert b'Hello [email protected]' in response.data | ||
|
||
|
||
def test_set_unauthorized_handler(app, client): | ||
@app.security.unauthorized_handler | ||
def unauthorized(): | ||
app.unauthorized_handler_set = True | ||
return 'unauthorized-handler-set', 401 | ||
|
||
app.unauthorized_handler_set = False | ||
|
||
authenticate(client, "[email protected]") | ||
response = client.get("/admin", follow_redirects=True) | ||
|
||
assert app.unauthorized_handler_set is True | ||
assert b'unauthorized-handler-set' in response.data | ||
assert response.status_code == 401 |