From 1bacc889ad7c4db5ff60d969bf4e28d9395e96be Mon Sep 17 00:00:00 2001 From: MrSphay Date: Wed, 8 Jul 2026 11:56:56 +0200 Subject: [PATCH] Use authenticated Gitea integration health check --- routes/auth_routes.py | 6 ++++-- tests/test_integrations_store_shape.py | 28 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/routes/auth_routes.py b/routes/auth_routes.py index 5c7a4e0..a78a9a6 100644 --- a/routes/auth_routes.py +++ b/routes/auth_routes.py @@ -818,11 +818,13 @@ def setup_auth_routes(auth_manager: AuthManager) -> APIRouter: except Exception as e: return {"ok": False, "message": f"Request failed: {e}"[:400]} - # All other presets: GET against a known health endpoint. + # All other presets: GET against a known health endpoint. Prefer + # authenticated endpoints where available; public version endpoints + # can make a broken token look healthy. # Fall back to detecting from name if preset is missing. health_paths = { "miniflux": "/v1/me", - "gitea": "/api/v1/version", + "gitea": "/api/v1/user", "linkding": "/api/tags/", "homeassistant": "/api/", "home assistant": "/api/", diff --git a/tests/test_integrations_store_shape.py b/tests/test_integrations_store_shape.py index c97f71b..4a70bed 100644 --- a/tests/test_integrations_store_shape.py +++ b/tests/test_integrations_store_shape.py @@ -1,6 +1,7 @@ import json import asyncio from types import SimpleNamespace +from unittest.mock import AsyncMock import pytest @@ -177,3 +178,30 @@ def test_update_integration_rejects_invalid_base_url_without_changing_existing( assert exc.value.status_code == 400 assert exc.value.detail == message assert integrations.load_integrations()[0]["base_url"] == "https://example.test" + + +def test_gitea_integration_test_uses_authenticated_endpoint(integrations_routes, monkeypatch): + endpoint, session_cookie, _http_exception = integrations_routes + test_integration = endpoint("/api/auth/integrations/{integration_id}/test", "POST") + integrations.save_integrations([ + { + "id": "gitea-id", + "name": "Gitea", + "preset": "gitea", + "base_url": "https://git.example.test", + "auth_type": "header", + "auth_header": "Authorization", + "api_key": "token test", + } + ]) + + execute = AsyncMock(return_value={"output": "HTTP 200\n{}", "exit_code": 0}) + monkeypatch.setattr("routes.auth_routes.execute_api_call", execute) + + result = asyncio.run(test_integration( + integration_id="gitea-id", + request=_JsonRequest({}, session_cookie), + )) + + assert result == {"ok": True, "message": "Connection successful"} + execute.assert_awaited_once_with("gitea-id", "GET", "/api/v1/user")