diff --git a/src/documents/tests/test_api_status.py b/src/documents/tests/test_api_status.py index 1f8940ea9..eb35974a6 100644 --- a/src/documents/tests/test_api_status.py +++ b/src/documents/tests/test_api_status.py @@ -46,7 +46,7 @@ class TestSystemStatus(APITestCase): self.assertEqual(response.data["database"]["status"], "OK") self.assertIsNone(response.data["database"]["error"]) self.assertIsNotNone(response.data["database"]["migration_status"]) - self.assertEqual(response.data["tasks"]["redis_url"], "redis://localhost:6379") + self.assertEqual(response.data["tasks"]["redis_url"], "localhost:6379") self.assertEqual(response.data["tasks"]["redis_status"], "ERROR") self.assertIsNotNone(response.data["tasks"]["redis_error"]) @@ -100,6 +100,21 @@ class TestSystemStatus(APITestCase): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data["tasks"]["redis_status"], "OK") + def test_system_status_redis_no_credentials(self): + """ + GIVEN: + - Redis URL with credentials + WHEN: + - The user requests the system status + THEN: + - The response contains the redis URL but no credentials + """ + with override_settings(_CELERY_REDIS_URL="redis://:password@localhost:6379/0"): + self.client.force_login(self.user) + response = self.client.get(self.ENDPOINT) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data["tasks"]["redis_url"], "localhost:6379") + @mock.patch("celery.app.control.Inspect.ping") def test_system_status_celery_ping(self, mock_ping): """ diff --git a/src/documents/views.py b/src/documents/views.py index 99db0a5d8..6d1d0a7c9 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -12,6 +12,7 @@ from pathlib import Path from time import mktime from unicodedata import normalize from urllib.parse import quote +from urllib.parse import urlparse import pathvalidate from django.apps import apps @@ -1617,6 +1618,7 @@ class SystemStatusView(GenericAPIView, PassUserMixin): media_stats = os.statvfs(settings.MEDIA_ROOT) redis_url = settings._CHANNELS_REDIS_URL + redis_url_parsed = urlparse(settings._CHANNELS_REDIS_URL) redis_error = None with Redis.from_url(url=redis_url) as client: try: @@ -1728,7 +1730,7 @@ class SystemStatusView(GenericAPIView, PassUserMixin): }, }, "tasks": { - "redis_url": redis_url, + "redis_url": f"{redis_url_parsed.hostname}:{redis_url_parsed.port}", "redis_status": redis_status, "redis_error": redis_error, "celery_status": celery_active,