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

ensure redirect to index if no justice id regardless of route hit #1283

Merged
merged 4 commits into from
Apr 9, 2024
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
9 changes: 9 additions & 0 deletions controlpanel/oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,22 @@ def verify_claims(self, claims):


class StateMismatchHandler(OIDCAuthenticationCallbackView):

def get(self, *args, **kwargs):
try:
return super().get(*args, **kwargs)
except SuspiciousOperation as e:
log.warning(f"Caught {e}: redirecting to login")
return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL_FAILURE)

@property
def success_url(self):

if not self.user.justice_email:
return reverse("index")

return super().success_url


def logout(request):
params = urlencode(
Expand Down
21 changes: 21 additions & 0 deletions tests/test_oidc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest
from controlpanel.oidc import StateMismatchHandler
from unittest.mock import Mock


@pytest.mark.parametrize(
"email, success_url",
[
("", "/"),
("[email protected]", "/tools/"),
],
)
def test_success_url(users, email, success_url):
request = Mock()
jamesstottmoj marked this conversation as resolved.
Show resolved Hide resolved
request.session.get.return_value = "/tools/"
user = users["normal_user"]
user.justice_email = email
view = StateMismatchHandler()
view.request = request
view.user = user
assert view.success_url == success_url
Loading