Skip to content

Commit

Permalink
Fixes W002 warning when SITE_ID is set (fixes AngellusMortis#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
AngellusMortis committed Jul 20, 2019
1 parent 3119d2d commit 501a8ed
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
32 changes: 18 additions & 14 deletions microsoft_auth/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ def microsoft_auth_validator(app_configs, **kwargs):
)

try:
request = RequestFactory().get("/", HTTP_HOST="example.com")
Site.objects.get_current(request)
if not hasattr(config, "SITE_ID"):
request = RequestFactory().get("/", HTTP_HOST="example.com")
current_site = Site.objects.get_current(request)
else:
current_site = Site.objects.get_current()
except Site.DoesNotExist:
pass
except (OperationalError, ProgrammingError):
Expand All @@ -46,19 +49,20 @@ def microsoft_auth_validator(app_configs, **kwargs):
)
)
else:
errors.append(
Warning(
(
"`example.com` is still a valid site, Microsoft "
"auth might not work"
),
hint=(
"Microsoft/Xbox auth uses OAuth, which requires "
"a real redirect URI to come back to"
),
id="microsoft_auth.W002",
if current_site.domain == "example.com":
errors.append(
Warning(
(
"`example.com` is still a valid site, Microsoft "
"auth might not work"
),
hint=(
"Microsoft/Xbox auth uses OAuth, which requires "
"a real redirect URI to come back to"
),
id="microsoft_auth.W002",
)
)
)

if config.MICROSOFT_AUTH_LOGIN_ENABLED: # pragma: no branch
if config.MICROSOFT_AUTH_CLIENT_ID == "":
Expand Down
15 changes: 15 additions & 0 deletions tests/test_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ def test_sites_migrations_fails(self):

self.assertIn("microsoft_auth.W001", self.captured.getvalue())

def test_sites_default_name_fails_multi_site(self):
self.site.domain = "example.com"
self.site.save()

call_command("check")

self.assertIn("microsoft_auth.W002", self.captured.getvalue())

@override_settings(SITE_ID=1)
def test_sites_default_name_fails(self):
self.site.domain = "example.com"
self.site.save()
Expand All @@ -53,6 +62,12 @@ def test_sites_default_name_fails(self):

self.assertIn("microsoft_auth.W002", self.captured.getvalue())

@override_settings(SITE_ID=1)
def test_sites_default_name_passes_site_id(self):
call_command("check")

self.assertNotIn("microsoft_auth.W002", self.captured.getvalue())

@override_settings(MICROSOFT_AUTH_CLIENT_ID="")
def test_config_client_id_fails(self):
call_command("check")
Expand Down

0 comments on commit 501a8ed

Please sign in to comment.