From e861807bdc05b73e4172ecc494342b412a05358c Mon Sep 17 00:00:00 2001 From: Adrien P Date: Thu, 17 Jul 2025 18:26:54 +0200 Subject: [PATCH] Added tests for new checks --- modoboa/core/tests/test_checks.py | 39 ++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/modoboa/core/tests/test_checks.py b/modoboa/core/tests/test_checks.py index 65e1fc8c1..31f2a5a59 100644 --- a/modoboa/core/tests/test_checks.py +++ b/modoboa/core/tests/test_checks.py @@ -1,15 +1,18 @@ import os import shutil import tempfile +import uuid +from django.core.management import call_command from django.test.utils import override_settings +from oauth2_provider.models import get_application_model + from modoboa.core import checks from modoboa.lib.tests import SimpleModoTestCase class CheckSessionCookieSecureTest(SimpleModoTestCase): - def setUp(self): self.workdir = tempfile.mkdtemp() @@ -35,3 +38,37 @@ class CheckSessionCookieSecureTest(SimpleModoTestCase): os.environ["OIDC_RSA_PRIVATE_KEY"] = "KEY" msgs = checks.check_rsa_private_key_exists(None) self.assertEqual(len(msgs), 0) + + def test_dovecot_oauth_app_exists(self): + get_application_model().objects.filter(name="Dovecot").delete() + msgs = checks.check_dovecot_oauth_app() + self.assertEqual(len(msgs), 1) + client_secret = str(uuid.uuid4()) + call_command( + "createapplication", + "--name=Dovecot", + "--skip-authorization", + "--client-id=dovecot", + f"--client-secret={client_secret}", + "confidential", + "client-credentials", + ) + msgs = checks.check_dovecot_oauth_app() + self.assertEqual(len(msgs), 0) + + def test_redicale_oauth_app_exists(self): + get_application_model().objects.filter(name="Radicale").delete() + msgs = checks.check_dovecot_oauth_app() + self.assertEqual(len(msgs), 1) + client_secret = str(uuid.uuid4()) + call_command( + "createapplication", + "--name=Radicale", + "--skip-authorization", + "--client-id=radicale", + f"--client-secret={client_secret}", + "confidential", + "client-credentials", + ) + msgs = checks.check_dovecot_oauth_app() + self.assertEqual(len(msgs), 0)