-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
27 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ class OIDCFlowTests(TestCase): | |
) | ||
@patch( | ||
"open_inwoner.configurations.models.SiteConfiguration.get_solo", | ||
return_value=SiteConfiguration(id=1, openid_display=OpenIDDisplayChoices.admin), | ||
return_value=SiteConfiguration(openid_display=OpenIDDisplayChoices.admin), | ||
) | ||
def test_existing_email_updates_admin_user( | ||
self, | ||
|
@@ -73,16 +73,13 @@ def test_existing_email_updates_admin_user( | |
callback_response, reverse("admin:index"), fetch_redirect_response=True | ||
) | ||
|
||
self.assertEqual(User.objects.count(), 1) | ||
|
||
user.refresh_from_db() | ||
|
||
self.assertTrue(User.objects.filter(oidc_id="some_username").exists()) | ||
self.assertEqual(user.oidc_id, "some_username") | ||
|
||
db_user = User.objects.filter(oidc_id="some_username").first() | ||
|
||
self.assertEqual(db_user.id, user.id) | ||
self.assertEqual(db_user.login_type, LoginTypeChoices.oidc) | ||
self.assertEqual(db_user.is_staff, True) | ||
self.assertEqual(user.login_type, LoginTypeChoices.oidc) | ||
self.assertEqual(user.is_staff, True) | ||
|
||
@patch("mozilla_django_oidc_db.backends.OIDCAuthenticationBackend.get_userinfo") | ||
@patch("mozilla_django_oidc_db.backends.OIDCAuthenticationBackend.store_tokens") | ||
|
@@ -94,9 +91,7 @@ def test_existing_email_updates_admin_user( | |
) | ||
@patch( | ||
"open_inwoner.configurations.models.SiteConfiguration.get_solo", | ||
return_value=SiteConfiguration( | ||
id=1, openid_display=OpenIDDisplayChoices.regular | ||
), | ||
return_value=SiteConfiguration(openid_display=OpenIDDisplayChoices.regular), | ||
) | ||
def test_existing_email_updates_regular_user( | ||
self, | ||
|
@@ -129,30 +124,30 @@ def test_existing_email_updates_regular_user( | |
callback_response, reverse("pages-root"), fetch_redirect_response=True | ||
) | ||
|
||
self.assertEqual(User.objects.count(), 1) | ||
|
||
user.refresh_from_db() | ||
|
||
self.assertTrue(User.objects.filter(oidc_id="some_username").exists()) | ||
self.assertEqual(user.oidc_id, "some_username") | ||
|
||
db_user = User.objects.filter(oidc_id="some_username").first() | ||
|
||
self.assertEqual(db_user.id, user.id) | ||
self.assertEqual(db_user.login_type, LoginTypeChoices.oidc) | ||
self.assertEqual(db_user.is_staff, False) | ||
self.assertEqual(user.login_type, LoginTypeChoices.oidc) | ||
self.assertEqual(user.is_staff, False) | ||
|
||
@patch("mozilla_django_oidc_db.backends.OIDCAuthenticationBackend.get_userinfo") | ||
@patch("mozilla_django_oidc_db.backends.OIDCAuthenticationBackend.store_tokens") | ||
@patch("mozilla_django_oidc_db.backends.OIDCAuthenticationBackend.verify_token") | ||
@patch("mozilla_django_oidc_db.backends.OIDCAuthenticationBackend.get_token") | ||
@patch( | ||
"mozilla_django_oidc_db.mixins.OpenIDConnectConfig.get_solo", | ||
return_value=OpenIDConnectConfig(id=1, enabled=True, make_users_staff=False), | ||
return_value=OpenIDConnectConfig( | ||
id=1, | ||
enabled=True, | ||
make_users_staff=False, | ||
claim_mapping={"first_name": "first_name"}, | ||
), | ||
) | ||
@patch( | ||
"open_inwoner.configurations.models.SiteConfiguration.get_solo", | ||
return_value=SiteConfiguration( | ||
id=1, openid_display=OpenIDDisplayChoices.regular | ||
), | ||
return_value=SiteConfiguration(openid_display=OpenIDDisplayChoices.regular), | ||
) | ||
def test_existing_oidc_id_updates_regular_user( | ||
self, | ||
|
@@ -187,16 +182,13 @@ def test_existing_oidc_id_updates_regular_user( | |
callback_response, reverse("pages-root"), fetch_redirect_response=True | ||
) | ||
|
||
self.assertEqual(User.objects.count(), 1) | ||
|
||
user.refresh_from_db() | ||
|
||
self.assertTrue(User.objects.filter(oidc_id="some_username").exists()) | ||
self.assertEqual(user.oidc_id, "some_username") | ||
|
||
db_user = User.objects.filter(oidc_id="some_username").first() | ||
|
||
self.assertEqual(db_user.id, user.id) | ||
self.assertEqual(db_user.login_type, LoginTypeChoices.oidc) | ||
self.assertEqual(db_user.is_staff, False) | ||
self.assertEqual(user.first_name, "bar") | ||
self.assertEqual(user.is_staff, False) | ||
|
||
@patch("mozilla_django_oidc_db.backends.OIDCAuthenticationBackend.get_userinfo") | ||
@patch("mozilla_django_oidc_db.backends.OIDCAuthenticationBackend.store_tokens") | ||
|
@@ -208,9 +200,7 @@ def test_existing_oidc_id_updates_regular_user( | |
) | ||
@patch( | ||
"open_inwoner.configurations.models.SiteConfiguration.get_solo", | ||
return_value=SiteConfiguration( | ||
id=1, openid_display=OpenIDDisplayChoices.regular | ||
), | ||
return_value=SiteConfiguration(openid_display=OpenIDDisplayChoices.regular), | ||
) | ||
def test_existing_case_sensitive_email_updates_user( | ||
self, | ||
|
@@ -265,7 +255,7 @@ def test_existing_case_sensitive_email_updates_user( | |
) | ||
@patch( | ||
"open_inwoner.configurations.models.SiteConfiguration.get_solo", | ||
return_value=SiteConfiguration(id=1, openid_display=OpenIDDisplayChoices.admin), | ||
return_value=SiteConfiguration(openid_display=OpenIDDisplayChoices.admin), | ||
) | ||
def test_new_admin_user_is_created_when_new_email( | ||
self, | ||
|
@@ -298,9 +288,8 @@ def test_new_admin_user_is_created_when_new_email( | |
callback_response, reverse("admin:index"), fetch_redirect_response=True | ||
) | ||
|
||
new_user = User.objects.filter(email="[email protected]").first() | ||
new_user = User.objects.get(email="[email protected]") | ||
|
||
self.assertIsNotNone(new_user) | ||
self.assertEqual(new_user.oidc_id, "some_username") | ||
self.assertEqual(new_user.login_type, LoginTypeChoices.oidc) | ||
self.assertEqual(new_user.is_staff, True) | ||
|
@@ -315,9 +304,7 @@ def test_new_admin_user_is_created_when_new_email( | |
) | ||
@patch( | ||
"open_inwoner.configurations.models.SiteConfiguration.get_solo", | ||
return_value=SiteConfiguration( | ||
id=1, openid_display=OpenIDDisplayChoices.regular | ||
), | ||
return_value=SiteConfiguration(openid_display=OpenIDDisplayChoices.regular), | ||
) | ||
def test_new_regular_user_is_created_when_new_email( | ||
self, | ||
|
@@ -339,8 +326,6 @@ def test_new_regular_user_is_created_when_new_email( | |
session.save() | ||
callback_url = reverse("oidc_authentication_callback") | ||
|
||
self.assertFalse(User.objects.filter(email="[email protected]").exists()) | ||
|
||
# enter the login flow | ||
callback_response = self.client.get( | ||
callback_url, {"code": "mock", "state": "mock"} | ||
|
@@ -350,9 +335,8 @@ def test_new_regular_user_is_created_when_new_email( | |
callback_response, reverse("pages-root"), fetch_redirect_response=True | ||
) | ||
|
||
new_user = User.objects.filter(email="[email protected]").first() | ||
new_user = User.objects.get(email="[email protected]") | ||
|
||
self.assertIsNotNone(new_user) | ||
self.assertEqual(new_user.oidc_id, "some_username") | ||
self.assertEqual(new_user.login_type, LoginTypeChoices.oidc) | ||
self.assertEqual(new_user.is_staff, False) | ||
|
@@ -374,9 +358,7 @@ def test_error_page_direct_access_forbidden(self): | |
) | ||
@patch( | ||
"open_inwoner.configurations.models.SiteConfiguration.get_solo", | ||
return_value=SiteConfiguration( | ||
id=1, openid_display=OpenIDDisplayChoices.regular | ||
), | ||
return_value=SiteConfiguration(openid_display=OpenIDDisplayChoices.regular), | ||
) | ||
def test_error_first_cleared_after_succesful_login( | ||
self, | ||
|