Skip to content

Commit

Permalink
Merge pull request #40 from onaio/fix-error-template
Browse files Browse the repository at this point in the history
Fix template syntax
  • Loading branch information
DavisRayM authored Nov 1, 2021
2 parents 5440769 + 2999aae commit 765dc4f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion oidc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
Main init file for oidc app
"""

VERSION = (0, 0, 8)
VERSION = (0, 0, 9)
__version__ = ".".join(str(v) for v in VERSION)
default_app_config = "oidc.apps.oidcConfig"
2 changes: 1 addition & 1 deletion oidc/templates/oidc/oidc_unrecoverable_error.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base.html' %}
{% load rest_framework %}

{% block title %}Error: {{ error-title }}{% endblock %}
{% block title %}Error: {{ error_title }}{% endblock %}

{% block content %}
<div class="content">
Expand Down
4 changes: 2 additions & 2 deletions oidc/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def callback(self, request: HttpRequest, **kwargs: dict) -> HttpResponse:
"error": _(
f"Missing required fields: {missing_fields}"
),
"error-title": _("Missing details in ID Token"),
"error_title": _("Missing details in ID Token"),
},
status=status.HTTP_400_BAD_REQUEST,
template_name="oidc/oidc_unrecoverable_error.html",
Expand All @@ -289,7 +289,7 @@ def callback(self, request: HttpRequest, **kwargs: dict) -> HttpResponse:
"error": _(
"Unable to validate authentication request; Nonce verification has failed. Kindly retry authentication process."
),
"error-title": _(
"error_title": _(
"Authentication request verification failed"
),
},
Expand Down
25 changes: 24 additions & 1 deletion tests/test_viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def setUp(self):
TestCase().setUp()
self.factory = APIRequestFactory()

def test_returns_data_entry_template_on_missing_creation_claim(self):
def test_returns_data_entry_template_on_missing_username_claim(self):
"""
Test that users are redirected to the data entry
page when username is not present in decoded token
Expand All @@ -75,6 +75,29 @@ def test_returns_data_entry_template_on_missing_creation_claim(self):
response = view(request, auth_server="default")
self.assertEqual(response.status_code, 200)
self.assertEqual(response.template_name, "oidc/oidc_user_data_entry.html")

def test_unrecoverable_error_on_missing_claim(self):
"""
Test that an error is returned when a required claim field other than the
username is missing from the ID Token
"""
view = UserModelOpenIDConnectViewset.as_view({"post": "callback"})
with patch(
"oidc.viewsets.OpenIDClient.verify_and_decode_id_token"
) as mock_func:
mock_func.return_value = {
"username": "bob",
"email": "[email protected]",
}

data = {"id_token": "sadsdaio3209lkasdlkas0d.sdojdsiad.iosdadia"}
request = self.factory.post("/", data=data)
response = view(request, auth_server="default")
self.assertEqual(response.status_code, 400)
self.assertEqual(response.template_name, "oidc/oidc_unrecoverable_error.html")
self.assertEqual(
response.data.get('error'),
'Missing required fields: first_name')

def test_create_non_existing_user(self):
"""
Expand Down

0 comments on commit 765dc4f

Please sign in to comment.