fix(cli): validate auth token against /api/shares, not /api/me - #53
Merged
Conversation
The 401 reported by users running 'gander auth <token>' was caused by the validation probe hitting GET /api/me, which doesn't exist on the gandermd server. The server falls through to its 'must be authenticated' middleware, returning a no_session 401 even for valid bearer tokens. Switch ValidateToken to GET /api/shares, which is already a lightweight authenticated endpoint (used by gander share/list) and accepts bearer tokens. No server-side change required. Also clean up the error path: runAuth was wrapping its API error with 'an auth: %w' while main.go's dispatcher also prefixes 'auth: ', giving users 'auth: auth: HTTP 401: ...'. Replace the inner wrap with a semantic 'token rejected by server: %w' message and let main.go do the only prefix. Test coverage: - Update TestRunAuthValidatesAndPersists to mock /api/shares. - Tighten TestRunAuthRejectsInvalidToken to assert both 'token rejected' and HTTP 401. - Add TestRunAuthErrorNotDoublePrefixed to guard against the doubled prefix returning. Docs (man page, README, zsh completion) updated to reference /api/shares instead of /api/me.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
gander auth <token>was returningauth: auth: HTTP 401: {"error":"no_session",…}.Root cause: the validation probe hit
GET /api/me, which does notexist on the gandermd server; its
must be authenticatedmiddlewarereturns 401 for any unknown authed path. The bearer was valid — the
endpoint just didn't exist.
ValidateTokentoGET /api/shares(already alightweight authenticated endpoint used by
gander share/gander list). No paired server change required.auth:prefix in the error path:runAuthnolonger wraps with
auth: %w(the dispatcher inmain.goadds thesingle prefix). The inner error is now a semantic
token rejected by server: …so users see what's wrong without theduplicated tag.
Related Issue
Refs #51
Test coverage
TestRunAuthValidatesAndPersistsupdated to mock/api/sharesandasserts both the path and the bearer header carry the new token.
TestRunAuthRejectsInvalidTokentightened: now asserts bothtoken rejected(the semantic wrapper) and401(the inner cause),plus the existing
~/.ganderbyte-equality guard for thenever-written case.
TestRunAuthErrorNotDoublePrefixed: explicit regressionguard — fails if
runAuth's error starts withauth:(which wouldproduce
auth: auth: …aftermain.go's prefix). Pins the fix inplace.
Commands run
All clean.
Out of scope
runManage/runSignup(same shape). Worth a follow-up to make thesubcommand-prefix convention consistent across the CLI.