-
-
Notifications
You must be signed in to change notification settings - Fork 101
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
25 additions
and
9 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 |
---|---|---|
|
@@ -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): | ||
|