From 0233c2605ed65514e924fb5a8b7905264a0be943 Mon Sep 17 00:00:00 2001 From: Anne Mickan Date: Fri, 3 May 2024 11:16:06 +0200 Subject: [PATCH] Add deployment check that dummy provider is not configured (#3340) --- app/grandchallenge/profiles/__init__.py | 22 ++++++++++++++++++++++ app/tests/profiles_tests/test_checks.py | 25 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 app/tests/profiles_tests/test_checks.py diff --git a/app/grandchallenge/profiles/__init__.py b/app/grandchallenge/profiles/__init__.py index e69de29bb2..af4c5a9889 100644 --- a/app/grandchallenge/profiles/__init__.py +++ b/app/grandchallenge/profiles/__init__.py @@ -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 diff --git a/app/tests/profiles_tests/test_checks.py b/app/tests/profiles_tests/test_checks.py new file mode 100644 index 0000000000..1f539f2282 --- /dev/null +++ b/app/tests/profiles_tests/test_checks.py @@ -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." + )