Skip to content

Conversation

mdewhirst
Copy link
Contributor

This test-base branch has a prototype partial test suite covering base testing infrastructure with helpers plus only one method 'totp' set of tests.

The idea is to decide if this is an appropriate way to unit-test django-mfa2. In theory, this will delete tests.py and create a mfa/tests directory. The PR includes a README.md in that tests directory.

@mdewhirst
Copy link
Contributor Author

@mkialoby, just tried running the tests again after applying the latest mfa2 changes and encountered a csp dependency and a number of errors so please don't try and merge this PR. I'll investigate and get back to you.

@mkalioby
Copy link
Owner

mkalioby commented Sep 1, 2025

Thanks for the headsup. I was planning to check it soon.

@mdewhirst
Copy link
Contributor Author

@mkialoby, I avoided the example app testing errors as follows ...

  1. Installed django-csp==3.8 and some errors went away.

However, django-csp has moved on and is now at version 4.0 which is backwardly incompatible with django-csp 3.8. That introduced more errors which were resolved when I migrated from 3.8 to 4.0. Removing django-csp completely resolved all those errors.

  1. In the example app, adjusted urlpatterns to include mfa.urls with "mfa/" instead of "mfa2/"
urlpatterns = [
    path("admin/", admin.site.urls),
    #path("mfa2/", include("mfa.urls")),
    path("mfa/", include("mfa.urls")),
    path("auth/login", auth.loginView, name="login"),
    path("auth/logout", auth.logoutView, name="logout"),
    path("devices/add/", TrustedDevice.add, name="add_trusted_device"),
    re_path("^$", views.home, name="home"),
    path("registered/", views.registered, name="registered"),
]

Alternatively, and just as easily, I could adjust 9 tests to change '/mfa/...' to '/mfa2/...'

The way to go depends on your selection of the standard mfa namespace.

If mfa2, I'll adjust the tests.

@mkalioby
Copy link
Owner

mkalioby commented Sep 6, 2025

mfa is better options.

# Simulate the validation logic
if session["email_secret"] == token.strip():
# Simulate key creation when MFA_ENFORCE_EMAIL_TOKEN is True
uk = User_Keys()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really a weird way to do unit test, as the function in the view shall do email adding, so the code branch inside the package gets executed. Here the test case tests itself and not the written code inside the package. Do you get me concern?

@mdewhirst
Copy link
Contributor Author

mdewhirst commented Sep 10, 2025 via email

@mkalioby
Copy link
Owner

Sure Mike, tyt.

Thanks for the great work.

I tried coverage to see the missed lines.

You can try that to check what I'm talking about.

@mdewhirst
Copy link
Contributor Author

@mkialoby, I avoided the example app testing errors as follows ...

  1. Installed django-csp==3.8 and some errors went away.

However, django-csp has moved on and is now at version 4.0 which is backwardly incompatible with django-csp 3.8. That introduced more errors which were resolved when I migrated from 3.8 to 4.0. Removing django-csp completely resolved all those errors.

  1. In the example app, adjusted urlpatterns to include mfa.urls with "mfa/" instead of "mfa2/"
urlpatterns = [
    path("admin/", admin.site.urls),
    #path("mfa2/", include("mfa.urls")),
    path("mfa/", include("mfa.urls")),
    path("auth/login", auth.loginView, name="login"),
    path("auth/logout", auth.logoutView, name="logout"),
    path("devices/add/", TrustedDevice.add, name="add_trusted_device"),
    re_path("^$", views.home, name="home"),
    path("registered/", views.registered, name="registered"),
]

Alternatively, and just as easily, I could adjust 9 tests to change '/mfa/...' to '/mfa2/...'

The way to go depends on your selection of the standard mfa namespace.

If mfa2, I'll adjust the tests.

@mdewhirst mdewhirst closed this Oct 3, 2025
@mdewhirst
Copy link
Contributor Author

Getting ready to deliver a smaller PR so it can be reviewed more easily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants