fix(auth): recognize API keys and bearer token in 'pup auth status'#484
Merged
Conversation
`pup auth status` previously only inspected OAuth2 token storage. When a user authenticated via DD_API_KEY+DD_APP_KEY (or DD_ACCESS_TOKEN), the command reported `❌ Not authenticated` / `"status": "no token"` even though every command worked — confusing wrapping agents into believing auth was broken. Status now delegates auth-type detection to `client::get_auth_type`, so the reported method is guaranteed to match the headers the client puts on the wire. The JSON gains an `auth_method` field (`bearer_token` / `api_keys`) on the new authenticated branches; the unauthenticated shape is unchanged. - Extract `build_non_oauth_status()` helper for the no-OAuth-tokens arm - Six unit tests cover every branch including bearer-over-api-keys precedence and partial-key (lone DD_API_KEY) rejection - Two `tokio::test` integration tests cover the `status()` wiring on the api-key and bearer paths Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
pup auth statusonly inspected OAuth2 token storage. When a user authenticated viaDD_API_KEY+DD_APP_KEY(orDD_ACCESS_TOKEN), the command reported❌ Not authenticatedeven though every other command worked — confusing agents that wrap pup into thinking auth was broken.Status now reports the credentials it actually finds, matching the auth headers the client puts on the wire.
Changes
src/commands/auth.rs— extractbuild_non_oauth_status()for the no-OAuth-tokens arm ofstatus(). The helper delegates auth-type detection toclient::get_auth_typeso this command can never disagree with the client about which credentials are in use.auth_methodfield (bearer_token/api_keys) on the two new authenticated branches; the unauthenticated payload is unchanged for backward compatibility.Behavior
Before, with
DD_API_KEY/DD_APP_KEYset:After:
Testing
build_non_oauth_status, including bearer-takes-precedence-over-api-keys (matchesclient::get_auth_type) and partial-key (loneDD_API_KEY) rejection.tokio::testintegration tests cover thestatus()wiring on the api-key and bearer paths.commands::authtests pass;cargo fmt --checkandcargo clippy --all-targets -- -D warningsare clean.Test plan
cargo test --bin pup commands::authpup auth statuswith onlyDD_API_KEY+DD_APP_KEYset and confirm authenticated outputpup auth statuswith onlyDD_ACCESS_TOKENset and confirm authenticated outputpup auth statusafterpup auth loginstill shows OAuth token details unchanged🤖 Generated with Claude Code