Fix ASTRO_API_TOKEN context expiry set ~57 years out instead of ~1 year - #2217
Open
jlaneve wants to merge 1 commit into
Open
Fix ASTRO_API_TOKEN context expiry set ~57 years out instead of ~1 year#2217jlaneve wants to merge 1 commit into
jlaneve wants to merge 1 commit into
Conversation
setup.go passed SetExpiresIn a Unix timestamp (time.Now().AddDate(1,0,0).Unix(), ~1.8 billion) while SetExpiresIn treated its argument as a count of seconds to add to now. The result: contexts written by ASTRO_API_TOKEN got an expiry around year 2083 and were never treated as expired, so refresh/re-auth never triggered. SetExpiresIn now takes a time.Duration instead of a bare int64, so the unit is part of the type and this mistake can't be expressed again. Converted its four callers (setup.go's token-refresh and API-key paths, cloud/auth's OAuth result handler, and the ASTRO_API_TOKEN path, which now passes 365 * 24 * time.Hour) plus the three test call sites. Added a test that asserts the ASTRO_API_TOKEN path's stored expiry lands within an hour of one year out, not decades. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Coverage Report for CI Build 29862132715Coverage remained the same at 43.883%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
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.
Description
SetExpiresInadds its argument totime.Now()as a count of seconds, but theASTRO_API_TOKENpath passed it a Unix timestamp (time.Now().AddDate(1, 0, 0).Unix()), landing the stored expiry around the year 2083. Once written to~/.astro/config.yaml, that context was never considered expired, so refresh and re-auth logic never fired for it.What changed:
SetExpiresInnow takes atime.Duration, so the unit lives in the type and this class of mistake stops being expressible. All four callers were converted; the buggy site now passes365 * 24 * time.Hour.Breaking changes
ASTRO_API_TOKENnow actually expire about a year out. Day-to-day use is unaffected — the env-var path rewrites the expiry on every command.Context.SetExpiresInchanged signature from(int64)to(time.Duration)— a Go API change for anyone importingconfigdirectly.Testing
New subtest runs the
ASTRO_API_TOKENpath and asserts the stored expiry lands within an hour of one year out (it would have landed in 2083 before).go build ./...,go test ./cmd/... ./config/... ./cloud/auth/...,go vet, andmake lintpass.🤖 Generated with Claude Code
https://claude.ai/code/session_01P6DEdUpFBFaAiPKEu81Wti