Skip to content

Commit

Permalink
[#2076] Upgrade mayin-2fa to 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Feb 5, 2024
1 parent cfb3236 commit 113def7
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 20 deletions.
14 changes: 9 additions & 5 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# This file is autogenerated by pip-compile with python 3.11
# To update, run:
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# ./bin/compile_dependencies.sh
#
Expand Down Expand Up @@ -307,7 +307,9 @@ face==20.1.1
fontawesomefree==6.4.2
# via -r requirements/base.in
fonttools[woff]==4.29.1
# via weasyprint
# via
# fonttools
# weasyprint
furl==2.1.3
# via
# -r requirements/base.in
Expand Down Expand Up @@ -361,7 +363,7 @@ markdown==3.3.6
# via -r requirements/base.in
markuppy==1.14
# via tablib
maykin-2fa==0.2.0
maykin-2fa==1.0.0
# via -r requirements/base.in
maykin-python3-saml==1.14.0.post0
# via
Expand Down Expand Up @@ -497,7 +499,9 @@ sqlparse==0.4.4
svglib==1.5.1
# via easy-thumbnails
tablib[html,ods,xls,xlsx,yaml]==3.1.0
# via django-import-export
# via
# django-import-export
# tablib
tinycss2==1.1.1
# via
# -r requirements/base.in
Expand Down
10 changes: 7 additions & 3 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# This file is autogenerated by pip-compile with python 3.11
# To update, run:
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# ./bin/compile_dependencies.sh
#
Expand Down Expand Up @@ -426,6 +426,7 @@ django-two-factor-auth[phonenumberslite,webauthn]==1.15.5
# via
# -c requirements/base.txt
# -r requirements/base.txt
# django-two-factor-auth
# maykin-2fa
django-view-breadcrumbs==2.2.4
# via
Expand Down Expand Up @@ -487,6 +488,7 @@ easy-thumbnails[svg]==2.8.5
# -r requirements/base.txt
# django-filer
# djangocms-picture
# easy-thumbnails
ecs-logging==2.1.0
# via
# -c requirements/base.txt
Expand Down Expand Up @@ -528,6 +530,7 @@ fonttools[woff]==4.29.1
# via
# -c requirements/base.txt
# -r requirements/base.txt
# fonttools
# weasyprint
freezegun==1.1.0
# via -r requirements/test-tools.in
Expand Down Expand Up @@ -638,7 +641,7 @@ markuppy==1.14
# -c requirements/base.txt
# -r requirements/base.txt
# tablib
maykin-2fa==0.2.0
maykin-2fa==1.0.0
# via
# -c requirements/base.txt
# -r requirements/base.txt
Expand Down Expand Up @@ -897,6 +900,7 @@ tablib[html,ods,xls,xlsx,yaml]==3.1.0
# -c requirements/base.txt
# -r requirements/base.txt
# django-import-export
# tablib
tblib==1.7.0
# via -r requirements/test-tools.in
text-unidecode==1.3
Expand Down
10 changes: 7 additions & 3 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# This file is autogenerated by pip-compile with python 3.11
# To update, run:
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# ./bin/compile_dependencies.sh
#
Expand Down Expand Up @@ -465,6 +465,7 @@ django-two-factor-auth[phonenumberslite,webauthn]==1.15.5
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
# django-two-factor-auth
# maykin-2fa
django-view-breadcrumbs==2.2.4
# via
Expand Down Expand Up @@ -532,6 +533,7 @@ easy-thumbnails[svg]==2.8.5
# -r requirements/ci.txt
# django-filer
# djangocms-picture
# easy-thumbnails
ecs-logging==2.1.0
# via
# -c requirements/ci.txt
Expand Down Expand Up @@ -589,6 +591,7 @@ fonttools[woff]==4.29.1
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
# fonttools
# weasyprint
freezegun==1.1.0
# via
Expand Down Expand Up @@ -733,7 +736,7 @@ markupsafe==2.1.3
# via
# jinja2
# werkzeug
maykin-2fa==0.2.0
maykin-2fa==1.0.0
# via
# -c requirements/ci.txt
# -r requirements/ci.txt
Expand Down Expand Up @@ -1065,6 +1068,7 @@ tablib[html,ods,xls,xlsx,yaml]==3.1.0
# -c requirements/ci.txt
# -r requirements/ci.txt
# django-import-export
# tablib
tblib==1.7.0
# via
# -c requirements/ci.txt
Expand Down
18 changes: 10 additions & 8 deletions src/open_inwoner/accounts/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.utils.translation import ugettext as _

from django_webtest import WebTest
from maykin_2fa.test import disable_admin_mfa
from webtest import Upload

from open_inwoner.utils.tests.helpers import create_image_bytes
Expand All @@ -11,14 +12,15 @@
from .factories import UserFactory


@disable_admin_mfa()
class TestAdminUser(WebTest):
def setUp(self):
self.user = UserFactory(
is_superuser=True, is_staff=True, email="john@example.com"
)
self.assertEqual(User.objects.count(), 1)

def test_user_is_created_without_case_sensitive_email(self):
def test_user_is_created_without_case_sensitive_email(self, m):
response = self.app.get(reverse("admin:accounts_user_add"), user=self.user)
form = response.forms["user_form"]
form["email"] = "john2@example.com"
Expand All @@ -28,7 +30,7 @@ def test_user_is_created_without_case_sensitive_email(self):

self.assertEqual(User.objects.count(), 2)

def test_user_is_updated_without_case_sensitive_email(self):
def test_user_is_updated_without_case_sensitive_email(self, m):
response = self.app.get(
reverse("admin:accounts_user_change", kwargs={"object_id": self.user.pk}),
user=self.user,
Expand All @@ -41,7 +43,7 @@ def test_user_is_updated_without_case_sensitive_email(self):

self.assertEqual(existing_user.email, "john2@example.com")

def test_user_is_updated_without_modifying_email(self):
def test_user_is_updated_without_modifying_email(self, m):
response = self.app.get(
reverse("admin:accounts_user_change", kwargs={"object_id": self.user.pk}),
user=self.user,
Expand All @@ -55,7 +57,7 @@ def test_user_is_updated_without_modifying_email(self):
self.assertEqual(existing_user.first_name, "Updated")
self.assertEqual(existing_user.email, self.user.email)

def test_user_not_created_with_case_sensitive_email(self):
def test_user_not_created_with_case_sensitive_email(self, m):
response = self.app.get(reverse("admin:accounts_user_add"), user=self.user)
form = response.forms["user_form"]
form["email"] = "John@example.com"
Expand All @@ -66,7 +68,7 @@ def test_user_not_created_with_case_sensitive_email(self):
self.assertContains(response, _("The user with this email already exists."))
self.assertEqual(User.objects.count(), 1)

def test_user_not_updated_with_case_sensitive_email(self):
def test_user_not_updated_with_case_sensitive_email(self, m):
response = self.app.get(
reverse("admin:accounts_user_change", kwargs={"object_id": self.user.pk}),
user=self.user,
Expand All @@ -80,7 +82,7 @@ def test_user_not_updated_with_case_sensitive_email(self):
self.assertContains(response, _("The user with this email already exists."))
self.assertEqual(self.user.email, updated_user.email)

def test_validation_error_is_raised_when_wrong_format_email(self):
def test_validation_error_is_raised_when_wrong_format_email(self, m):
response = self.app.get(
reverse("admin:accounts_user_change", kwargs={"object_id": self.user.pk}),
user=self.user,
Expand All @@ -91,7 +93,7 @@ def test_validation_error_is_raised_when_wrong_format_email(self):

self.assertContains(response, _("Voer een geldig e-mailadres in."))

def test_begeleider_can_add_an_image(self):
def test_begeleider_can_add_an_image(self, m):
self.user.contact_type = ContactTypeChoices.begeleider
self.user.save()

Expand All @@ -114,7 +116,7 @@ def test_begeleider_can_add_an_image(self):

self.assertIsNotNone(self.user.image.file)

def test_non_begeleider_cannot_add_an_image(self):
def test_non_begeleider_cannot_add_an_image(self, m):
img_bytes = create_image_bytes()

response = self.app.get(
Expand Down
8 changes: 7 additions & 1 deletion src/open_inwoner/accounts/tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from django_webtest import WebTest
from freezegun import freeze_time
from maykin_2fa.test import disable_admin_mfa
from privates.test import temp_private_root
from timeline_logger.models import TimelineLog

Expand All @@ -30,6 +31,7 @@
)


@disable_admin_mfa()
@freeze_time("2021-10-18 13:00:00")
@override_settings(ROOT_URLCONF="open_inwoner.cms.tests.urls")
class TestProfile(WebTest):
Expand Down Expand Up @@ -115,7 +117,11 @@ def test_user_notifications_update_is_logged(self, mock_cms_page_display):
)

def test_login_via_admin_is_logged(self):
self.app.post(reverse("admin:login"), user=self.user)
login_page = self.app.get(reverse("admin:login"))
login_page.form["auth-username"] = self.user.email
login_page.form["auth-password"] = "secret"
login_page.form.submit()

log_entry = TimelineLog.objects.get()

self.assertEqual(
Expand Down
2 changes: 2 additions & 0 deletions src/open_inwoner/cms/tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
from django.test import TestCase, override_settings
from django.urls import reverse

from maykin_2fa.test import disable_admin_mfa
from pyquery import PyQuery as pq

from open_inwoner.cms.tests import cms_tools
from open_inwoner.cms.utils.middleware import DropToolbarMiddleware
from open_inwoner.utils.tests.helpers import TwoFactorUserTestMixin


@disable_admin_mfa()
@override_settings(TWO_FACTOR_FORCE_OTP_ADMIN=False)
class TestDropToolbarMiddleware(TwoFactorUserTestMixin, TestCase):
@classmethod
Expand Down
4 changes: 4 additions & 0 deletions src/open_inwoner/conf/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@

TWO_FACTOR_PATCH_ADMIN = False

# Disable two-factor authentication by default for development
if config("DISABLE_2FA", default=True):
MAYKIN_2FA_ALLOW_MFA_BYPASS_BACKENDS = AUTHENTICATION_BACKENDS

# playwright multi browser
PLAYWRIGHT_MULTI_ONLY_DEFAULT = True

Expand Down
3 changes: 3 additions & 0 deletions src/open_inwoner/configurations/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
from django.utils.translation import ugettext_lazy as _

from django_webtest import WebTest
from maykin_2fa.test import disable_admin_mfa
from pyquery import PyQuery

from open_inwoner.accounts.tests.factories import UserFactory

from ..models import SiteConfiguration


@disable_admin_mfa()
class TestAdminSite(WebTest):
csrf_checks = False

Expand Down Expand Up @@ -102,6 +104,7 @@ def test_bulk_delete_fail(self):
)


@disable_admin_mfa()
class TestAdminForm(WebTest):
def setUp(self):
self.user = UserFactory(is_superuser=True, is_staff=True)
Expand Down
2 changes: 2 additions & 0 deletions src/open_inwoner/configurations/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
from django.utils.translation import gettext as _

from django_webtest import WebTest
from maykin_2fa.test import disable_admin_mfa

from open_inwoner.accounts.tests.factories import UserFactory


@disable_admin_mfa()
class TestConfigurationColors(WebTest):
def setUp(self):
super().setUp()
Expand Down
2 changes: 2 additions & 0 deletions src/open_inwoner/configurations/tests/test_oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.utils.translation import gettext_lazy as _

from django_webtest import WebTest
from maykin_2fa.test import disable_admin_mfa
from mozilla_django_oidc_db.models import OpenIDConnectConfig

from open_inwoner.accounts.tests.factories import UserFactory
Expand All @@ -11,6 +12,7 @@
from ..choices import OpenIDDisplayChoices


@disable_admin_mfa()
class OIDCConfigTest(ClearCachesMixin, WebTest):
csrf_checks = False

Expand Down
2 changes: 2 additions & 0 deletions src/open_inwoner/media/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

from cms.utils.permissions import set_current_user
from django_webtest import WebTest
from maykin_2fa.test import disable_admin_mfa

from open_inwoner.accounts.tests.factories import UserFactory

from .factories import VideoFactory


@disable_admin_mfa()
class VideoAdminTests(WebTest):
def setUp(self):
set_current_user(
Expand Down
2 changes: 2 additions & 0 deletions src/open_inwoner/openzaak/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
from django.utils.translation import gettext_lazy as _

from django_webtest import WebTest
from maykin_2fa.test import disable_admin_mfa

from open_inwoner.accounts.tests.factories import UserFactory

from .factories import ZaakTypeConfigFactory, ZaakTypeInformatieObjectTypeConfigFactory


@disable_admin_mfa()
class TestZaakTypeConfigAdmin(WebTest):
def setUp(self):
self.user = UserFactory(is_superuser=True, is_staff=True)
Expand Down
2 changes: 2 additions & 0 deletions src/open_inwoner/pdc/tests/test_category_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.utils.translation import gettext as _

from django_webtest import WebTest
from maykin_2fa.test import disable_admin_mfa

from open_inwoner.accounts.tests.factories import GroupFactory, UserFactory
from open_inwoner.openzaak.tests.factories import ZaakTypeConfigFactory
Expand All @@ -13,6 +14,7 @@
from .factories import CategoryFactory


@disable_admin_mfa()
class TestAdminCategoryForm(WebTest):
def setUp(self):
self.user = UserFactory(is_superuser=True, is_staff=True)
Expand Down
Loading

0 comments on commit 113def7

Please sign in to comment.