Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: fix default for UNAUTHORIZED_VIEW (opr #726) #68

Merged
merged 2 commits into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flask_security/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,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
2 changes: 1 addition & 1 deletion flask_security/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _get_unauthorized_response(text=None, headers=None):


def _get_unauthorized_view():
view = utils.get_url(utils.config_value('UNAUTHORIZED_VIEW'))
view = utils.config_value('UNAUTHORIZED_VIEW')
if view:
if callable(view):
view = view()
Expand Down
6 changes: 5 additions & 1 deletion tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,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 @@ -154,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 @@ -166,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