Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deployment check that dummy provider is not configured #3340

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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."
)