-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #442 from maykinmedia/feature/2fa-app-title
🔧 Always use requests.hostname for 2FA app title
- Loading branch information
Showing
3 changed files
with
38 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,23 @@ | ||
from django.contrib.sites.models import Site | ||
from django.test import RequestFactory, TestCase, override_settings | ||
from django.urls import resolve | ||
|
||
|
||
@override_settings(ALLOWED_HOSTS=["some-domain.local"], DISABLE_2FA=False) | ||
class TwoFactorQRGeneratorTestCase(TestCase): | ||
def test_qr_code_generator_does_not_use_sites_framework(self): | ||
""" | ||
Regression test for https://github.com/maykinmedia/open-api-framework/issues/40 | ||
Testing the actual QR code output is too much of a hassle, so instead retrieve | ||
the view class based on the URL and check if `get_issuer` behaves as expected | ||
""" | ||
site = Site.objects.get_current() | ||
site.domain = "testserver" | ||
site.save() | ||
|
||
qr_generator_view_class = resolve("/admin/mfa/qrcode/").func.view_class | ||
issuer = qr_generator_view_class( | ||
request=RequestFactory().get("/", headers={"Host": "some-domain.local"}) | ||
).get_issuer() | ||
|
||
self.assertEqual(issuer, "some-domain.local") |
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,8 @@ | ||
from django.contrib.sites.requests import RequestSite | ||
|
||
from maykin_2fa.views import QRGeneratorView as _QRGeneratorView | ||
|
||
|
||
class QRGeneratorView(_QRGeneratorView): | ||
def get_issuer(self): | ||
return RequestSite(self.request).name |
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