fixed tests for djangooidc

This commit is contained in:
David Kennedy 2023-12-08 11:05:07 -05:00
parent 3bbfd5cd88
commit a6ae9ad74e
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
2 changed files with 30 additions and 3 deletions

View file

@ -0,0 +1,29 @@
import logging
from django.test import TestCase
from django.conf import settings
from djangooidc.oidc import Client
logger = logging.getLogger(__name__)
class OidcTest(TestCase):
def test_oidc_create_authn_request_with_acr_value(self):
"""Test that create_authn_request returns a redirect with an acr_value
when an acr_value is passed through session."""
try:
# Initialize provider using pyOICD
OP = getattr(settings, "OIDC_ACTIVE_PROVIDER")
CLIENT = Client(OP)
logger.debug("client initialized %s" % CLIENT)
except Exception as err:
CLIENT = None # type: ignore
logger.warning(err)
logger.warning("Unable to configure OpenID Connect provider. Users cannot log in.")
session = {"acr_value": "some_acr_value_maybe_ial2"}
response = CLIENT.create_authn_request(session)
self.assertEqual(response.status_code, 302)
self.assertIn("some_acr_value_maybe_ial2", response.url)

View file

@ -73,9 +73,7 @@ def login_callback(request):
if requires_step_up_auth(userinfo):
# add acr_value to request.session
request.session["acr_value"] = CLIENT.get_step_up_acr_value()
test = CLIENT.create_authn_request(request.session)
logger.info(test)
return test
return CLIENT.create_authn_request(request.session)
user = authenticate(request=request, **userinfo)
if user:
login(request, user)