Skip to content

fix(websocket): retain server authentication failure context - #629

Closed
snehaapratap wants to merge 1 commit into
massive-com:masterfrom
snehaapratap:fix/628-authentication-context
Closed

snehaapratap wants to merge 1 commit into
massive-com:masterfrom
snehaapratap:fix/628-authentication-context

Conversation

@snehaapratap

Copy link
Copy Markdown

An auth_failed response currently loses the server's message, so callers see only authentication failed: closing connection even when the server explains a missing entitlement. Include the server's reason, using the existing status-message sanitizer, while retaining the old error text when no reason is supplied.

Fixes #628. This forwards the server's explanation; it does not infer an account's subscription or invent an entitlement diagnosis.

The local WebSocket integration test now verifies the reason reaches Client.Error(). A table test covers a supplied reason, an absent reason, and newline sanitization. The reason assertions failed before the fix.

Validation:

  • go test -race ./..., go build ./..., and go vet ./... passed on Go 1.27.3.
  • go mod tidy left dependency files unchanged; gofmt and git diff --check passed.
  • golangci-lint v1.64.8 with Go 1.24.9 passed for ./websocket/.... The full lint command reports an existing unchecked json.Unmarshal at rest/iterator.go:127, outside this diff. Running that older linter with Go 1.27 instead fails to decode newer export data, so the scoped lint used Go 1.24.9.
  • Only local test servers and synthetic credentials were used; no live API requests.

AI assistance: implemented and validated with OpenAI Codex.

@snehaapratap
snehaapratap requested a review from a team as a code owner November 7, 2026 04:57
Comment thread websocket/client_test.go
err = c.WriteMessage(mt, data)
} else {
res := []models.ControlMessage{{EventType: models.EventType{EventType: "status"}, Status: "auth_failed"}}
res := []models.ControlMessage{{EventType: models.EventType{EventType: "status"}, Status: "auth_failed", Message: "missing entitlement"}}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you inver auth_failed correlates to only a bad entitlement or would (should) the backend provide this additional context?

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.

Authentication Failed - missing context

3 participants