Skip to content

Commit

Permalink
core: fix default for UNAUTHORIZED_VIEW
Browse files Browse the repository at this point in the history
* Changes default to `None` to be consistent with documentation.
  (closes pallets-eco#724)
  • Loading branch information
jirikuncar committed Jan 5, 2018
1 parent 3f9b75b commit a2f35df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion flask_security/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
'POST_CONFIRM_VIEW': None,
'POST_RESET_VIEW': None,
'POST_CHANGE_VIEW': None,
'UNAUTHORIZED_VIEW': lambda: None,
'UNAUTHORIZED_VIEW': None,
'FORGOT_PASSWORD_TEMPLATE': 'security/forgot_password.html',
'LOGIN_USER_TEMPLATE': 'security/login_user.html',
'REGISTER_USER_TEMPLATE': 'security/register_user.html',
Expand Down
8 changes: 7 additions & 1 deletion tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import base64

import pytest

from utils import authenticate, json_authenticate, logout

try:
Expand Down Expand Up @@ -130,9 +132,10 @@ def test_authorized_access(client):
def test_unauthorized_access(client, get_message):
authenticate(client, "[email protected]")
response = client.get("/admin", follow_redirects=True)
assert get_message('UNAUTHORIZED') in response.data
assert response.status_code == 403


@pytest.mark.settings(unauthorized_view=lambda: None)
def test_unauthorized_access_with_referrer(client, get_message):
authenticate(client, '[email protected]')
response = client.get('/admin', headers={'referer': '/admin'})
Expand All @@ -152,6 +155,7 @@ def test_unauthorized_access_with_referrer(client, get_message):
assert response.data.count(get_message('UNAUTHORIZED')) == 1


@pytest.mark.settings(unauthorized_view='/')
def test_roles_accepted(client):
for user in ("[email protected]", "[email protected]"):
authenticate(client, user)
Expand All @@ -164,11 +168,13 @@ def test_roles_accepted(client):
assert b'Home Page' in response.data


@pytest.mark.settings(unauthorized_view='/')
def test_unauthenticated_role_required(client, get_message):
response = client.get('/admin', follow_redirects=True)
assert get_message('UNAUTHORIZED') in response.data


@pytest.mark.settings(unauthorized_view='/')
def test_multiple_role_required(client):
for user in ("[email protected]", "[email protected]"):
authenticate(client, user)
Expand Down

0 comments on commit a2f35df

Please sign in to comment.