jazzband / django-two-factor-auth

Complete Two-Factor Authentication for Django providing the easiest integration into most Django projects.
MIT License
1.7k stars 447 forks source link

Invalid checking if otp_yubikey should be used #252

Open mrowqa opened 6 years ago

mrowqa commented 6 years ago

Expected Behavior

If otp_yubikey is installed in current environment (venv), but absent in INSTALLED_APPS, then tests which use login should work.

Current Behavior

Tests crash with:

RuntimeError: Model class otp_yubikey.models.YubikeyDevice doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

Possible Solution

Instead of trying to import otp_yubikey and catching ImportError you can check if otp_yubikey is present in INSTALLED_APPS.

Steps to Reproduce (for bugs)

Well, I don't have minimal example, but here is the change I am working (patchset 2 failed due to this problem). I have ran it locally and pasted the reason above. https://gerrit.sio2project.mimuw.edu.pl/#/c/2946/

Your Environment

Bouke commented 6 years ago

This is the current check, it already checks INSTALLED_APPS:

https://github.com/Bouke/django-two-factor-auth/blob/7684b9a08f63ffa0ee79c3ac94a0f67ba864730a/two_factor/models.py#L16-L19

https://github.com/Bouke/django-two-factor-auth/blob/7684b9a08f63ffa0ee79c3ac94a0f67ba864730a/two_factor/models.py#L39-L43

A pull request that solves your problem would be welcome.