Return fallback context for incomplete current-user payload #92
|
|
@ -79,6 +79,8 @@ async def context() -> JSONResponse:
|
||||||
)
|
)
|
||||||
if not isinstance(user_data, dict):
|
if not isinstance(user_data, dict):
|
||||||
raise ValueError("Gitea current-user response was not an object")
|
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:
|
except Exception as e:
|
||||||
error_message = (
|
error_message = (
|
||||||
f"Gitea context request timed out after {CONTEXT_TIMEOUT_SECONDS:g}s"
|
f"Gitea context request timed out after {CONTEXT_TIMEOUT_SECONDS:g}s"
|
||||||
|
|
|
||||||
|
|
@ -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"
|
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
|
@pytest.mark.anyio
|
||||||
async def test_context_skips_malformed_repository_entries(monkeypatch):
|
async def test_context_skips_malformed_repository_entries(monkeypatch):
|
||||||
async def user():
|
async def user():
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user