Merge pull request 'Return fallback context for incomplete current-user payload' (#92) from timmy/91-return-fallback-incomplete-current-user into main
All checks were successful
CI / lint (push) Successful in 8s
Release / release-candidate (push) Successful in 4s
CI / build-frontend (push) Successful in 4s

This commit is contained in:
rockachopa 2026-08-06 09:18:02 +00:00
commit 43a2804562
2 changed files with 23 additions and 0 deletions

View File

@ -79,6 +79,8 @@ async def context() -> JSONResponse:
)
if not isinstance(user_data, dict):
raise ValueError("Gitea current-user response was not an object")
if not all(field in user_data for field in ("id", "login")):
raise ValueError("Gitea current-user response did not include id and login")
except Exception as e:
error_message = (
f"Gitea context request timed out after {CONTEXT_TIMEOUT_SECONDS:g}s"

View File

@ -250,6 +250,27 @@ async def test_context_returns_fallback_for_null_current_user_payload(monkeypatc
assert context["error"] == "Gitea current-user response was not an object"
@pytest.mark.anyio
async def test_context_returns_fallback_for_incomplete_current_user_payload(monkeypatch):
async def incomplete_user():
return {"id": 1}
async def empty_collection():
return []
monkeypatch.setattr(main, "current_user", incomplete_user)
monkeypatch.setattr(main, "repos", empty_collection)
monkeypatch.setattr(main, "issues", empty_collection)
monkeypatch.setattr(main, "pull_requests", empty_collection)
response = await main.context()
context = json.loads(response.body)
assert response.status_code == 200
assert context["repos"] == []
assert context["error"] == "Gitea current-user response did not include id and login"
@pytest.mark.anyio
async def test_context_skips_malformed_repository_entries(monkeypatch):
async def user():