Skip to content

Commit

Permalink
Add deployment check that dummy provider is not configured (#3340)
Browse files Browse the repository at this point in the history
  • Loading branch information
amickan authored May 3, 2024
1 parent 17691db commit 0233c26
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/grandchallenge/profiles/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.core.checks import Error, register


@register(deploy=True)
def check_dummy_provider_is_not_used(app_configs, **kwargs):
from django.conf import settings

errors = []

if (
"dummy" in settings.SOCIALACCOUNT_PROVIDERS.keys()
or "allauth.socialaccount.providers.dummy" in settings.INSTALLED_APPS
):
errors.append(
Error(
"The dummy social account provider is configured. This provider should only be used for testing purposes and not in production.",
hint="Remove the dummy provider from SOCIALACCOUNT_PROVIDERS and INSTALLED_APPS in your settings.",
id="grandchallenge.profiles.E001",
)
)

return errors
25 changes: 25 additions & 0 deletions app/tests/profiles_tests/test_checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from grandchallenge.profiles import check_dummy_provider_is_not_used


def test_check_dummy_provider_is_not_used(settings):

errors = check_dummy_provider_is_not_used(None)

assert len(errors) == 1
assert errors[0].id == "grandchallenge.profiles.E001"
assert (
errors[0].msg
== "The dummy social account provider is configured. This provider should only be used for testing purposes and not in production."
)

settings.SOCIALACCOUNT_PROVIDERS = {"dummy": {}}
settings.INSTALLED_APPS.remove("allauth.socialaccount.providers.dummy")

errors = check_dummy_provider_is_not_used(None)

assert len(errors) == 1
assert errors[0].id == "grandchallenge.profiles.E001"
assert (
errors[0].msg
== "The dummy social account provider is configured. This provider should only be used for testing purposes and not in production."
)

0 comments on commit 0233c26

Please sign in to comment.