-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perms: Remove the
HIJACK_ALLOWED_USER_EMAILS
settings
- Loading branch information
Showing
3 changed files
with
2 additions
and
32 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
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 |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
|
||
import pytest | ||
from django.contrib.auth.models import Permission | ||
from django.test import override_settings | ||
from django.urls import reverse | ||
from pytest_django.asserts import assertRedirects | ||
|
||
|
@@ -56,13 +55,6 @@ def test_disallowed_hijackers(self, client): | |
response = client.post(reverse("hijack:acquire"), {"user_pk": hijacked.pk, "next": "/foo/"}) | ||
assert response.status_code == 403 | ||
|
||
with override_settings(HIJACK_ALLOWED_USER_EMAILS=["[email protected]", "[email protected]"]): | ||
# active staff but not superuser and email not in the whitelist | ||
hijacker = ItouStaffFactory(email="[email protected]") | ||
client.force_login(hijacker) | ||
response = client.post(reverse("hijack:acquire"), {"user_pk": hijacked.pk, "next": "/foo/"}) | ||
assert response.status_code == 403 | ||
|
||
@pytest.mark.parametrize("param", ["is_active", "is_superuser", "is_staff"]) | ||
def test_disallowed_hijacked(self, client, param): | ||
hijacker = ItouStaffFactory(is_superuser=True) | ||
|
@@ -72,23 +64,6 @@ def test_disallowed_hijacked(self, client, param): | |
response = client.post(reverse("hijack:acquire"), {"user_pk": hijacked.pk, "next": "/foo/"}) | ||
assert response.status_code == 403 | ||
|
||
def test_allowed_staff_hijacker(self, client, caplog, settings): | ||
settings.HIJACK_ALLOWED_USER_EMAILS = ["[email protected]", "[email protected]"] | ||
hijacked = PrescriberFactory() | ||
hijacker = ItouStaffFactory(email="[email protected]") | ||
client.force_login(hijacker) | ||
|
||
response = client.post(reverse("hijack:acquire"), {"user_pk": hijacked.pk, "next": "/foo/"}) | ||
assert response.status_code == 302 | ||
assert response["Location"] == "/foo/" | ||
assert caplog.records[0].message == f"admin={hijacker} has started impersonation of user={hijacked}" | ||
caplog.clear() | ||
|
||
response = client.post(reverse("hijack:release"), {"user_pk": hijacked.pk, "next": "/bar/"}) | ||
assert response.status_code == 302 | ||
assert response["Location"] == "/bar/" | ||
assert caplog.records[0].message == f"admin={hijacker} has ended impersonation of user={hijacked}" | ||
|
||
def test_permission_staff_hijacker(self, client, caplog): | ||
hijacked = PrescriberFactory() | ||
hijacker = ItouStaffFactory(is_staff=True) | ||
|
@@ -107,9 +82,8 @@ def test_permission_staff_hijacker(self, client, caplog): | |
assert caplog.records[0].message == f"admin={hijacker} has ended impersonation of user={hijacked}" | ||
|
||
def test_allowed_django_prescriber(self, client, caplog, settings): | ||
settings.HIJACK_ALLOWED_USER_EMAILS = ["[email protected]", "[email protected]"] | ||
hijacked = PrescriberFactory(identity_provider=IdentityProvider.DJANGO) | ||
hijacker = ItouStaffFactory(email="[email protected]") | ||
hijacker = ItouStaffFactory(is_superuser=True) | ||
client.force_login(hijacker) | ||
|
||
response = client.post(reverse("hijack:acquire"), {"user_pk": hijacked.pk, "next": "/foo/"}) | ||
|