Skip to content

Treat a list error answer without a JSON error body as an error - #220

Open
topperge wants to merge 2 commits into
go-oidfed:mainfrom
topperge:fix/list-error-without-json-body
Open

topperge wants to merge 2 commits into
go-oidfed:mainfrom
topperge:fix/list-error-without-json-body

Conversation

@topperge

Copy link
Copy Markdown
Contributor

Fixes #218. Builds on #219 (#217): this branch contains that PR's commit, so please merge #219 first. The diff of its own is the second commit.

internal/http reports an error response only when its body decodes into an OpenID Federation error object. For any other error answer, httpFetchList read the empty result it passed in. That covers a reverse proxy's plain-text 401 in front of a private list endpoint, or an HTML 502. The authority then looked as if it had no subordinates, and SimpleEntityCollector silently dropped its subtree.

httpFetchList now checks resp.IsError() after the error-body check:

  • a 401 or 403 is a *ListRefusedError;
  • any other non-2xx answer is list endpoint of <entity> answered HTTP <status>;
  • an empty 200 list is still an empty list.

Tests (entity_collection_refusal_test.go):

  • TestCollectorReportsPlainErrorResponses: plain-text and HTML 401/403 and a 502, with httpmock string responders. It fails on Report list endpoint errors from SimpleEntityCollector #219's code and passes with this change.
  • TestCollectorEmptyListIsNotAnError: an empty [] answer with 200 is neither a refusal nor an error.

go test ./... passes.

As the issue notes, other GetCtx/PostCtx callers that pass a result type (resolve, collection) follow the same pattern. This PR leaves them alone.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QYDqsx3UGxpCKvCiUxShZq

topperge and others added 2 commits November 12, 2026 10:43
SimpleEntityCollector only logged a failed federation_list_endpoint or
federation_collection_endpoint request, so a caller got an empty or
partial collection whether the federation had no members, refused the
request (401/403, or required client authentication), or was down.

The collector now calls an optional OnListError hook wherever it logged
such an error. Refusals are reported as *ListRefusedError{Authority,
Status}: httpFetchList returns it for a 401 or 403 answer, and without
sending a request (Status 0) when federation_list_endpoint_auth_methods
lacks "none" and no client authentication can satisfy it (private_key_jwt
with DefaultClientAuth set is not a refusal). A failed collection
endpoint is reported only when no list traversal follows it, since a
failing list traversal reports itself. A nil hook changes nothing.

Fixes go-oidfed#217

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QYDqsx3UGxpCKvCiUxShZq
internal/http reports an error response only when its body decodes into
an OpenID Federation error object. For any other error answer, such as a
reverse proxy's plain-text 401 in front of a private list endpoint or an
HTML 502, httpFetchList read the empty result it passed in, so the
authority looked as if it had no subordinates and SimpleEntityCollector
silently dropped its subtree.

httpFetchList now checks resp.IsError() after the error-body check: a
401 or 403 is a *ListRefusedError, any other non-2xx answer an error
naming the entity and status. An empty 200 list is still an empty list.

Fixes go-oidfed#218

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QYDqsx3UGxpCKvCiUxShZq
@deepsource-io

deepsource-io Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

DeepSource Code Review

We reviewed changes in be2f2ed...5dcda48 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Go Nov 12, 2026 3:46p.m. Review ↗
Code coverage Nov 12, 2026 4:16p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

httpFetchList: a non-2xx answer without an OpenID Federation error body is taken as an empty list

1 participant