Skip to content

fix: propagate JSON decode errors in TestCallback_sessionsWithoutRefreshCookieName_returns500#154

Merged
veverkap merged 2 commits into
mainfrom
copilot/fix-json-decode-error-handling
Apr 28, 2026
Merged

fix: propagate JSON decode errors in TestCallback_sessionsWithoutRefreshCookieName_returns500#154
veverkap merged 2 commits into
mainfrom
copilot/fix-json-decode-error-handling

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 28, 2026

The last of 28 silently-discarded json.Decode errors in the test suite — a failed decode leaves body as a zero-value map, so body["error"] returns "" and require.Contains(t, "", "configuration") fails with a misleading assertion message instead of surfacing the actual decode failure.

Change

  • handler/oidc_test.go: replace _ = json.NewDecoder(w.Body).Decode(&body) with require.NoError(t, ...) so decode failures are immediately surfaced.
// before
_ = json.NewDecoder(w.Body).Decode(&body)
require.Contains(t, body["error"], "configuration")

// after
require.NoError(t, json.NewDecoder(w.Body).Decode(&body))
require.Contains(t, body["error"], "configuration")

Greptile Summary

This PR fixes two test functions — TestCallback_sessionsWithoutRefreshCookieName_returns500 and TestMiddleware_invalidToken — where JSON decode errors were silently discarded, causing misleading assertion failures on a zero-value map rather than surfacing the root decode failure. Both changes swap _ = json.NewDecoder(...).Decode(&body) for require.NoError(t, ...), which is correct and consistent with the broader cleanup described in the PR.

Confidence Score: 5/5

Safe to merge — test-only change with no impact on production code paths

Both changes are mechanically correct, test-only, and improve diagnostic clarity. No production code is touched, and no logic is altered beyond surfacing previously hidden errors.

No files require special attention

Important Files Changed

Filename Overview
handler/oidc_test.go Replaces silently-discarded JSON decode error in TestCallback_sessionsWithoutRefreshCookieName_returns500 with require.NoError, surfacing decode failures immediately
auth/middleware_test.go Replaces silently-discarded JSON decode error in TestMiddleware_invalidToken with require.NoError, consistent with the same fix applied across the test suite

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Test makes HTTP request] --> B[Record response via httptest.ResponseRecorder]
    B --> C{json.NewDecoder.Decode}
    C -- Before: discard error --> D[Error silently dropped]
    D --> E[body is zero-value map]
    E --> F[body error is empty string]
    F --> G[require.Contains fails with misleading message]
    C -- After: require.NoError --> H[Decode error surfaces immediately]
    H --> I[body populated correctly]
    I --> J[require.Contains passes or fails clearly]
Loading

Reviews (2): Last reviewed commit: "fix: use require.NoError for JSON decode..." | Re-trigger Greptile

…outRefreshCookieName_returns500

Agent-Logs-Url: https://github.com/amalgamated-tools/goauth/sessions/87e2e101-4355-478e-ac12-7c2dc83f1903

Co-authored-by: veverkap <22348+veverkap@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves reliability of the OIDC callback config-validation test by surfacing JSON decode failures instead of silently ignoring them, aligning the test suite with the broader goal of eliminating hidden json.Decode failures.

Changes:

  • Replace ignored json.NewDecoder(...).Decode(...) error with require.NoError(...) in the affected test.
Show a summary per file
File Description
handler/oidc_test.go Ensures JSON decode errors fail the test immediately for clearer failures in the OIDC callback test.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment thread handler/oidc_test.go
Address remaining silently-discarded json.Decode error in
auth/middleware_test.go that was missed in the previous fix.
@veverkap veverkap merged commit 330b409 into main Apr 28, 2026
7 checks passed
@veverkap veverkap deleted the copilot/fix-json-decode-error-handling branch April 28, 2026 18:15
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.

3 participants