Skip to content

Commit

Permalink
Test without MIRROR_GROUPS
Browse files Browse the repository at this point in the history
  • Loading branch information
stephane committed Sep 24, 2022
1 parent c956402 commit e440441
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions tests/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,31 @@ def test_group_claim_with_mirror_groups(self):
Group.objects.filter(name="group1").delete()

backend = AdfsAuthCodeBackend()
with patch("django_auth_adfs.backend.settings.GROUPS_CLAIM", "group"):
with patch("django_auth_adfs.backend.settings.MIRROR_GROUPS", True):
user = backend.authenticate(self.request, authorization_code="dummycode")
self.assertIsInstance(user, User)
self.assertEqual(user.first_name, "John")
self.assertEqual(user.last_name, "Doe")
self.assertEqual(user.email, "[email protected]")
# Group restored
self.assertEqual(len(user.groups.all()), 2)
with patch("django_auth_adfs.backend.settings.MIRROR_GROUPS", True):
user = backend.authenticate(self.request, authorization_code="dummycode")
self.assertIsInstance(user, User)
self.assertEqual(user.first_name, "John")
self.assertEqual(user.last_name, "Doe")
self.assertEqual(user.email, "[email protected]")
# group1 is restored
group_names = user.groups.order_by("name").values_list("name", flat=True)
self.assertSequenceEqual(group_names, ['group1', 'group2'])

@mock_adfs("2016")
def test_group_claim_without_mirror_groups(self):
# Remove one group
Group.objects.filter(name="group1").delete()

backend = AdfsAuthCodeBackend()
with patch("django_auth_adfs.backend.settings.MIRROR_GROUPS", False):
user = backend.authenticate(self.request, authorization_code="dummycode")
self.assertIsInstance(user, User)
self.assertEqual(user.first_name, "John")
self.assertEqual(user.last_name, "Doe")
self.assertEqual(user.email, "[email protected]")
# User is not added to group1 because the group doesn't exist
group_names = user.groups.values_list("name", flat=True)
self.assertSequenceEqual(group_names, ['group2'])

@mock_adfs("2016", empty_keys=True)
def test_empty_keys(self):
Expand Down

0 comments on commit e440441

Please sign in to comment.