-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Provide test utility to disable MFA (during tests)
TODO: need to look into django-webtest backend and add it to the list.
- Loading branch information
1 parent
a806a3b
commit 7bcb7ec
Showing
2 changed files
with
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from django.conf import settings | ||
from django.test import override_settings | ||
|
||
|
||
def disable_admin_mfa(): | ||
""" | ||
Test helper to disable MFA requirements in the admin. | ||
Based on :func:`django.test.override_settings`, so you can use it as a decorator | ||
or context manager. | ||
""" | ||
return override_settings( | ||
MAYKIN_2FA_ALLOW_MFA_BYPASS_BACKENDS=settings.AUTHENTICATION_BACKENDS, | ||
) |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from django.contrib.auth.models import User | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
from maykin_2fa.test import disable_admin_mfa | ||
|
||
|
||
class TestHelperTests(TestCase): | ||
|
||
def test_mfa_disabling(self): | ||
User.objects.create_user(username="johny", password="password", is_staff=True) | ||
self.client.login(username="johny", password="password") | ||
|
||
with disable_admin_mfa(): | ||
response = self.client.get(reverse("admin:index")) | ||
|
||
self.assertEqual(response.status_code, 200) |