-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: automatically associate user with TransitAgency using SSO domain
this lessens the chance that the user will reach the in_person views without an associated TransitAgency.
- Loading branch information
1 parent
19513cd
commit f0aeef2
Showing
2 changed files
with
34 additions
and
0 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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import pytest | ||
from django.conf import settings | ||
from django.contrib.auth.models import User, Group | ||
|
||
import benefits.core.admin | ||
from benefits.core.admin import GOOGLE_USER_INFO_URL, pre_login_user | ||
|
||
|
@@ -94,3 +95,27 @@ def test_pre_login_user_does_not_add_transit_staff_to_group(mocker, settings): | |
staff_group = Group.objects.get(name=settings.STAFF_GROUP_NAME) | ||
assert staff_group.user_set.count() == 0 | ||
assert agency_user.groups.count() == 0 | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_pre_login_user_add_transit_staff_to_transit_staff_group(mocker, settings, model_TransitAgency): | ||
mocked_request = mocker.Mock() | ||
mocked_request.session.get.return_value = None | ||
|
||
transit_agency_staff_group = Group.objects.create(name="CST Staff") | ||
model_TransitAgency.pk = None | ||
model_TransitAgency.staff_group = transit_agency_staff_group | ||
model_TransitAgency.sso_domain = "cst.org" | ||
model_TransitAgency.save() | ||
|
||
settings.GOOGLE_SSO_STAFF_LIST = ["*"] | ||
settings.GOOGLE_SSO_ALLOWABLE_DOMAINS = ["cst.org"] | ||
|
||
# simulate what `django_google_sso` does for us (sets is_staff to True) | ||
agency_user = User.objects.create_user(username="agency_user", email="[email protected]", is_staff=True) | ||
|
||
pre_login_user(agency_user, mocked_request) | ||
|
||
# assert that a transit agency user gets added to their TransitAgency's staff group based on SSO domain | ||
assert agency_user.groups.count() == 1 | ||
assert agency_user.groups.first() == transit_agency_staff_group |