From 0b6e6ecebfce7f1377a36b10c6c69b0bd2b56803 Mon Sep 17 00:00:00 2001 From: amickan Date: Fri, 3 May 2024 07:31:28 +0200 Subject: [PATCH 1/2] Add deployment check that dummy provider is not configured --- app/grandchallenge/components/__init__.py | 18 ++++++++++++++++++ app/tests/components_tests/test_checks.py | 18 +++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/grandchallenge/components/__init__.py b/app/grandchallenge/components/__init__.py index d934c8d974..30e6835282 100644 --- a/app/grandchallenge/components/__init__.py +++ b/app/grandchallenge/components/__init__.py @@ -23,3 +23,21 @@ def check_sagemaker_is_used(app_configs, **kwargs): ) return errors + + +@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(): + 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 in your settings.", + id="grandchallenge.components.E002", + ) + ) + + return errors diff --git a/app/tests/components_tests/test_checks.py b/app/tests/components_tests/test_checks.py index e65d9e06cf..ff121aecf2 100644 --- a/app/tests/components_tests/test_checks.py +++ b/app/tests/components_tests/test_checks.py @@ -1,4 +1,7 @@ -from grandchallenge.components import check_sagemaker_is_used +from grandchallenge.components import ( + check_dummy_provider_is_not_used, + check_sagemaker_is_used, +) from grandchallenge.components.backends.amazon_sagemaker_training import ( AmazonSageMakerTrainingExecutor, ) @@ -13,3 +16,16 @@ def test_check_sagemaker_is_used(settings): assert len(errors) == 1 assert errors[0].id == "grandchallenge.components.E001" assert errors[0].msg == f"{expected_backend} is not the default backend." + + +def test_check_dummy_provider_is_not_used(settings): + settings.SOCIALACCOUNT_PROVIDERS = {"dummy": {}} + + errors = check_dummy_provider_is_not_used(None) + + assert len(errors) == 1 + assert errors[0].id == "grandchallenge.components.E002" + assert ( + errors[0].msg + == "The dummy social account provider is configured. This provider should only be used for testing purposes and not in production." + ) From 842255b7efd9a81960dc16ce345872683b1f28fb Mon Sep 17 00:00:00 2001 From: amickan Date: Fri, 3 May 2024 10:43:03 +0200 Subject: [PATCH 2/2] Move check to profiles app --- app/grandchallenge/components/__init__.py | 18 ---------------- app/grandchallenge/profiles/__init__.py | 22 ++++++++++++++++++++ app/tests/components_tests/test_checks.py | 18 +--------------- app/tests/profiles_tests/test_checks.py | 25 +++++++++++++++++++++++ 4 files changed, 48 insertions(+), 35 deletions(-) create mode 100644 app/tests/profiles_tests/test_checks.py diff --git a/app/grandchallenge/components/__init__.py b/app/grandchallenge/components/__init__.py index 30e6835282..d934c8d974 100644 --- a/app/grandchallenge/components/__init__.py +++ b/app/grandchallenge/components/__init__.py @@ -23,21 +23,3 @@ def check_sagemaker_is_used(app_configs, **kwargs): ) return errors - - -@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(): - 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 in your settings.", - id="grandchallenge.components.E002", - ) - ) - - return errors 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/components_tests/test_checks.py b/app/tests/components_tests/test_checks.py index ff121aecf2..e65d9e06cf 100644 --- a/app/tests/components_tests/test_checks.py +++ b/app/tests/components_tests/test_checks.py @@ -1,7 +1,4 @@ -from grandchallenge.components import ( - check_dummy_provider_is_not_used, - check_sagemaker_is_used, -) +from grandchallenge.components import check_sagemaker_is_used from grandchallenge.components.backends.amazon_sagemaker_training import ( AmazonSageMakerTrainingExecutor, ) @@ -16,16 +13,3 @@ def test_check_sagemaker_is_used(settings): assert len(errors) == 1 assert errors[0].id == "grandchallenge.components.E001" assert errors[0].msg == f"{expected_backend} is not the default backend." - - -def test_check_dummy_provider_is_not_used(settings): - settings.SOCIALACCOUNT_PROVIDERS = {"dummy": {}} - - errors = check_dummy_provider_is_not_used(None) - - assert len(errors) == 1 - assert errors[0].id == "grandchallenge.components.E002" - assert ( - errors[0].msg - == "The dummy social account provider is configured. This provider should only be used for testing purposes and not in production." - ) 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." + )