From dcb8ee47d8eb66c8c70ae57eedfe986ed21ded35 Mon Sep 17 00:00:00 2001 From: msramalho <19508417+msramalho@users.noreply.github.com> Date: Thu, 13 Feb 2025 00:35:09 +0000 Subject: [PATCH] drops group info from default endpoint --- app/tests/web/endpoints/test_default.py | 26 ------------------------- app/tests/web/test_main.py | 2 +- app/web/endpoints/default.py | 17 ++++------------ 3 files changed, 5 insertions(+), 40 deletions(-) diff --git a/app/tests/web/endpoints/test_default.py b/app/tests/web/endpoints/test_default.py index 6de2f01..1e0e49f 100644 --- a/app/tests/web/endpoints/test_default.py +++ b/app/tests/web/endpoints/test_default.py @@ -13,32 +13,6 @@ def test_endpoint_home(client_with_auth): assert "breakingChanges" in j assert "groups" not in j - -@patch("app.web.endpoints.default.bearer_security", new_callable=AsyncMock) -@patch("app.web.endpoints.default.get_user_auth", new_callable=AsyncMock, return_value="test@example.com") -@patch("app.web.endpoints.default.crud.get_user_groups", return_value=["group1", "group2"]) -def test_endpoint_home_with_groups(m1, m2, m3, client_with_auth): - r = client_with_auth.get("/") - assert r.status_code == 200 - j = r.json() - assert "version" in j and j["version"] == VERSION - assert "breakingChanges" in j - assert "groups" in j - assert j["groups"] == ["group1", "group2"] - - -@patch("app.web.endpoints.default.bearer_security", new_callable=AsyncMock) -@patch("app.web.endpoints.default.get_user_auth", new_callable=AsyncMock, return_value="test@example.com") -@patch("app.web.endpoints.default.crud.get_user_groups", side_effect=Exception('mocked error')) -def test_endpoint_home_with_groups_exception(m1, m2, m3, client_with_auth): # mocks call that triggers an internal error - r = client_with_auth.get("/") - assert r.status_code == 200 - j = r.json() - assert "version" in j and j["version"] == VERSION - assert "breakingChanges" in j - assert "groups" not in j - - def test_endpoint_health(client_with_auth): r = client_with_auth.get("/health") assert r.status_code == 200 diff --git a/app/tests/web/test_main.py b/app/tests/web/test_main.py index 95cc5d6..8cee578 100644 --- a/app/tests/web/test_main.py +++ b/app/tests/web/test_main.py @@ -17,7 +17,7 @@ def test_alembic(db_session): alembic.config.main(argv=['--raiseerr', 'upgrade', 'head']) alembic.config.main(argv=['--raiseerr', 'downgrade', 'base']) -@patch("app.web.endpoints.default.crud.soft_delete_task", side_effect=Exception('mocked error')) +@patch("app.web.endpoints.url.crud.soft_delete_task", side_effect=Exception('mocked error')) def test_logging_middleware(m1, client_with_auth): from app.web.utils.metrics import EXCEPTION_COUNTER assert len(EXCEPTION_COUNTER.collect()[0].samples) == 0 diff --git a/app/web/endpoints/default.py b/app/web/endpoints/default.py index 2535ae6..9271992 100644 --- a/app/web/endpoints/default.py +++ b/app/web/endpoints/default.py @@ -1,29 +1,20 @@ from typing import Dict -from fastapi import APIRouter, Depends, Request, HTTPException +from fastapi import APIRouter, Depends, HTTPException from fastapi.responses import FileResponse, JSONResponse from app.web.config import VERSION, BREAKING_CHANGES -from app.shared.log import log_error -from app.web.db import crud from app.shared.schemas import ActiveUser, UsageResponse from app.web.db.user_state import UserState -from app.web.security import get_user_auth, bearer_security, get_user_state +from app.web.security import get_user_state from app.shared.user_groups import GroupInfo default_router = APIRouter() @default_router.get("/") -async def home(request: Request): - # TODO: maybe split into 2 routes: one non authenticated and one authenticated for the groups info only, necessary only for the extension - status = {"version": VERSION, "breakingChanges": BREAKING_CHANGES} - try: - email = await get_user_auth(await bearer_security(request)) - status["groups"] = crud.get_user_groups(email) - except HTTPException: pass # not authenticated is fine - except Exception as e: log_error(e) - return JSONResponse(status) +async def home(): + return JSONResponse({"version": VERSION, "breakingChanges": BREAKING_CHANGES}) @default_router.get("/health")