Skip to content

fix(cli): validate auth token against /api/shares, not /api/me - #53

Merged
scott merged 1 commit into
mainfrom
fix/51-gander-auth-endpoint
Aug 19, 2026
Merged

fix(cli): validate auth token against /api/shares, not /api/me#53
scott merged 1 commit into
mainfrom
fix/51-gander-auth-endpoint

Conversation

@scott

@scott scott commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • gander auth <token> was returning auth: auth: HTTP 401: {"error":"no_session",…}.
    Root cause: the validation probe hit GET /api/me, which does not
    exist on the gandermd server; its must be authenticated middleware
    returns 401 for any unknown authed path. The bearer was valid — the
    endpoint just didn't exist.
  • Switches ValidateToken to GET /api/shares (already a
    lightweight authenticated endpoint used by gander share /
    gander list). No paired server change required.
  • Removes the doubled auth: prefix in the error path: runAuth no
    longer wraps with auth: %w (the dispatcher in main.go adds the
    single prefix). The inner error is now a semantic
    token rejected by server: … so users see what's wrong without the
    duplicated tag.

Related Issue

Refs #51

Test coverage

  • TestRunAuthValidatesAndPersists updated to mock /api/shares and
    asserts both the path and the bearer header carry the new token.
  • TestRunAuthRejectsInvalidToken tightened: now asserts both
    token rejected (the semantic wrapper) and 401 (the inner cause),
    plus the existing ~/.gander byte-equality guard for the
    never-written case.
  • New TestRunAuthErrorNotDoublePrefixed: explicit regression
    guard — fails if runAuth's error starts with auth: (which would
    produce auth: auth: … after main.go's prefix). Pins the fix in
    place.

Commands run

go vet ./...
go test ./...          # all 5 auth tests + full suite pass
CGO_ENABLED=0 go build -o /tmp/check .

All clean.

Out of scope

  • The doubled-prefix pattern still exists in runManage /
    runSignup (same shape). Worth a follow-up to make the
    subcommand-prefix convention consistent across the CLI.

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.
@scott
scott merged commit c926923 into main Aug 19, 2026
1 check passed
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.

1 participant