mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-03 09:43:33 +02:00
Lint
This commit is contained in:
parent
8febad976d
commit
e7e3df0422
6 changed files with 107 additions and 99 deletions
|
@ -69,7 +69,7 @@ class OpenIdConnectBackend(ModelBackend):
|
|||
# Overwrite first_name and last_name if not empty string
|
||||
for key, value in kwargs.items():
|
||||
# Check if the key is not first_name or last_name or value is not empty string
|
||||
if key not in ['first_name', 'last_name'] or value:
|
||||
if key not in ["first_name", "last_name"] or value:
|
||||
setattr(user, key, value)
|
||||
user.save()
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ from django.utils import timezone
|
|||
from registrar.models import User
|
||||
from ..backends import OpenIdConnectBackend # Adjust the import path based on your project structure
|
||||
|
||||
class OpenIdConnectBackendTestCase(TestCase):
|
||||
|
||||
class OpenIdConnectBackendTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.backend = OpenIdConnectBackend()
|
||||
self.kwargs = {
|
||||
|
@ -56,10 +56,10 @@ class OpenIdConnectBackendTestCase(TestCase):
|
|||
"""Test that authenticate updates an existing user if it finds one.
|
||||
For this test, given_name and family_name are not supplied"""
|
||||
# Create an existing user with the same username and with first and last names
|
||||
existing_user = User.objects.create_user(username="test_user",first_name="John",last_name="Doe")
|
||||
existing_user = User.objects.create_user(username="test_user", first_name="John", last_name="Doe")
|
||||
|
||||
# Remove given_name and family_name from the input, self.kwargs
|
||||
self.kwargs.pop("given_name", None)
|
||||
self.kwargs.pop("given_name", None)
|
||||
self.kwargs.pop("family_name", None)
|
||||
|
||||
# Ensure that the authenticate method updates the existing user
|
||||
|
@ -79,7 +79,7 @@ class OpenIdConnectBackendTestCase(TestCase):
|
|||
"""Test that authenticate updates an existing user if it finds one.
|
||||
For this test, given_name and family_name are supplied and overwrite"""
|
||||
# Create an existing user with the same username and with first and last names
|
||||
existing_user = User.objects.create_user(username="test_user",first_name="WillBe",last_name="Replaced")
|
||||
existing_user = User.objects.create_user(username="test_user", first_name="WillBe", last_name="Replaced")
|
||||
|
||||
# Ensure that the authenticate method updates the existing user
|
||||
# and preserves existing first and last names
|
||||
|
|
|
@ -58,7 +58,7 @@ def openid(request):
|
|||
request.session["next"] = request.GET.get("next", "/")
|
||||
|
||||
try:
|
||||
logger.info('openid() calls create_authn_request in oidc')
|
||||
logger.info("openid() calls create_authn_request in oidc")
|
||||
return CLIENT.create_authn_request(request.session)
|
||||
except Exception as err:
|
||||
return error_page(request, err)
|
||||
|
@ -72,22 +72,23 @@ def login_callback(request):
|
|||
# test for need for identity verification and if it is satisfied
|
||||
# if not satisfied, redirect user to login with stepped up acr_value
|
||||
if requires_step_up_auth(userinfo):
|
||||
logger.info('login_callback() calls get_step_up_acr_value and create_authn_request in oidc')
|
||||
logger.info("login_callback() calls get_step_up_acr_value and create_authn_request in oidc")
|
||||
# add acr_value to request.session
|
||||
request.session["acr_value"] = CLIENT.get_step_up_acr_value()
|
||||
return CLIENT.create_authn_request(request.session)
|
||||
|
||||
logger.info(f'login_callback() before calling authenticate: {userinfo}')
|
||||
|
||||
|
||||
logger.info(f"login_callback() before calling authenticate: {userinfo}")
|
||||
|
||||
try:
|
||||
user_in_db = User.objects.get(username=userinfo["sub"])
|
||||
|
||||
|
||||
if user_in_db:
|
||||
logger.info(f"This user exists in the DB (before authenticate): {user_in_db.first_name} {user_in_db.last_name}")
|
||||
logger.info(
|
||||
f"This user exists in the DB (before authenticate): {user_in_db.first_name} {user_in_db.last_name}"
|
||||
)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
user = authenticate(request=request, **userinfo)
|
||||
if user:
|
||||
login(request, user)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue