Repository navigation
test(contract): pin request-contract hook header rules - #60
Merged
Merged
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces contract tests for the authentication commands (auth login, auth logout, and auth whoami) along with a file-backed fake keyring implementation to isolate tests from the host OS keychain. Feedback on these changes includes resolving the absolute path of the fake keyring source directory using runtime.Caller to prevent build failures when tests are executed from different working directories, and gracefully handling empty keyring files in the fake keyring loader to avoid JSON unmarshalling errors.
auth login and logout write to the OS keychain, so running them from the contract suite would read and delete the keychain entries of whoever runs the tests. testdata/fakekeyring wraps the CLI with a file-backed keychain (config.SetKeyringBackend), built once next to the contract binary. Covers dry-run no-ops, login without credential flags, storage in the keychain or the 0600 config-file fallback, whoami sources and masking, the credential reaching the wire, and logout clearing both stores while keeping other settings. auth login/logout/whoami join the command inventory.
auth login/logout, the keychain fallback and whoami are generated code, covered by the generator's own suite; drop auth_test.go and the fake-keychain entrypoint. Cover the custom request hook instead: a custom Authorization header displaces the API key on generated requests, and x-goog-user-project is sent only when set and non-empty. isolatedEnv also points USERPROFILE at the temporary home, which os.UserHomeDir reads on Windows.
2ynn
marked this pull request as ready for review
October 1, 2026 20:33
wanlin31
approved these changes
Oct 1, 2026
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.
request_contract.gois the custom hook that shapes every generated request. Two of its header rules had no contract coverage:Authorizationheader must displacex-goog-api-key(only the rawfiles uploadtransport was pinned);x-goog-user-projectis sent only when the user project is set and non-empty.Tests
TestAuthenticationHeadersAndPrecedence/custom Authorization header displaces API keyconfig.yaml+--header "Authorization: Bearer …"→ onlyAuthorizationreaches the wireTestUserProjectHeader/set,unset,empty--user-projectvalue is sent; nox-goog-user-projectheader at all when the flag is absent or emptyRemoving either hook branch fails the matching case.
Also:
isolatedEnvnow setsUSERPROFILEalongsideHOME;os.UserHomeDirreads it on Windows, where tests would otherwise read the developer's realconfig.yaml.