ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
fix(notifications): hide connection test errors
Marcos Paulo Dinize3e399c59d43
diff --git a/backend/app/api/notifications.py b/backend/app/api/notifications.pyindex 388398ff..ac9c4b3f 100644--- a/backend/app/api/notifications.py+++ b/backend/app/api/notifications.py@@ -429,8 +429,11 @@ def add_chat_connection():def update_chat_connection(conn_id):"""Update mutable chat connection metadata and credentials."""from app.services.chat_webhook_service import ChatWebhookService+ data = request.get_json()+ if data is None:+ data = {}try:- conn = ChatWebhookService.update(conn_id, request.get_json() or {})+ conn = ChatWebhookService.update(conn_id, data)except ValueError as exc:return jsonify({'error': str(exc)}), 400if conn is None:diff --git a/backend/app/services/chat_webhook_service.py b/backend/app/services/chat_webhook_service.pyindex 05ae743d..b1742167 100644--- a/backend/app/services/chat_webhook_service.py+++ b/backend/app/services/chat_webhook_service.py@@ -286,10 +286,8 @@ class ChatWebhookService:delivery_result = cls._deliver_chat(conn, credentials, notification)success = delivery_result.ok- error = delivery_result.error- except Exception as exc: # pragma: no cover - defensive formatter guard+ except Exception: # pragma: no cover - defensive formatter guardsuccess = False- error = str(exc)conn.last_tested_at = datetime.utcnow()conn.last_test_ok = success@@ -297,10 +295,12 @@ class ChatWebhookService:if success:return {'success': True, 'message': 'Test notification sent'}- return {- 'success': False,- 'error': str(error or 'test notification failed')[:300],- }+ logger.warning(+ 'Chat connection test failed (id=%s, kind=%s)',+ conn.id,+ conn.kind,+ )+ return {'success': False, 'error': 'Test notification failed'}# ------------------------------------------------------------------# Delivery (called by the chat channel adapter for ``conn:<id>`` targets)diff --git a/backend/tests/test_notification_chat_connections.py b/backend/tests/test_notification_chat_connections.pyindex 686377b9..1b57dca4 100644--- a/backend/tests/test_notification_chat_connections.py+++ b/backend/tests/test_notification_chat_connections.py@@ -325,11 +325,13 @@ class TestConnectionTesting:result = ChatWebhookService.test(conn.id)- assert result == {'success': False, 'error': 'webhook returned 503'}+ assert result == {+ 'success': False, 'error': 'Test notification failed',+ }assert conn.last_tested_at is not Noneassert conn.last_test_ok is False- def test_connection_test_bounds_transport_errors(self, app, monkeypatch):+ def test_connection_test_hides_transport_errors(self, app, monkeypatch):def fail_post(*args, **kwargs):raise RuntimeError('x' * 500)@@ -340,10 +342,30 @@ class TestConnectionTesting:result = ChatWebhookService.test(conn.id)- assert result['success'] is False- assert result['error'] == 'x' * 300+ assert result == {+ 'success': False, 'error': 'Test notification failed',+ }assert conn.last_test_ok is False+ def test_connection_test_does_not_expose_transport_secrets(self, app, monkeypatch):+ def fail_post(url, *args, **kwargs):+ raise RuntimeError(f'failed POST {url}')++ monkeypatch.setattr(+ 'app.services.chat_webhook_service.requests.post', fail_post,+ )+ secret_url = 'https://hooks.example/super-secret-token'+ conn = ChatWebhookService.add({+ 'kind': 'webhook', 'name': 'Ops', 'url': secret_url,+ })++ result = ChatWebhookService.test(conn.id)++ assert result == {+ 'success': False, 'error': 'Test notification failed',+ }+ assert secret_url not in json.dumps(result)+def test_connection_test_returns_none_for_unknown_id(self, app):assert ChatWebhookService.test(999999) is None@@ -429,6 +451,22 @@ class TestApi:assert resp.status_code == 400assert 'kind cannot be changed' in resp.get_json()['error']+ @pytest.mark.parametrize('payload', [[], False])+ def test_update_connection_rejects_falsy_non_object_json(self, app, client,+ auth_headers, payload):+ conn = ChatWebhookService.add({+ 'kind': 'discord', 'name': 'Ops', 'url': 'https://discord/hook',+ })++ resp = client.put(+ f'/api/v1/notifications/admin/chat-connections/{conn.id}',+ json=payload,+ headers=auth_headers,+ )++ assert resp.status_code == 400+ assert resp.get_json() == {'error': 'request body must be an object'}+def test_test_connection_returns_200_on_delivery(self, app, client, auth_headers,monkeypatch):class _Resp:@@ -479,7 +517,7 @@ class TestApi:assert resp.status_code == 400assert resp.get_json() == {- 'success': False, 'error': 'webhook returned 503',+ 'success': False, 'error': 'Test notification failed',}def test_test_connection_returns_404_for_unknown_id(self, app, client, auth_headers):