Fix test suite leaking Hub credentials, corrupting agent state#125
Closed
scion-gteam[bot] wants to merge 2 commits into
Closed
Fix test suite leaking Hub credentials, corrupting agent state#125scion-gteam[bot] wants to merge 2 commits into
scion-gteam[bot] wants to merge 2 commits into
Conversation
Tests that spawn sciontool (e.g., TestInitCommand_Integration) inherited live Hub env vars from the agent container, causing the subprocess to talk to the real Hub and reset the agent phase to "starting." - Add scrubHubEnv(t) helpers that use t.Setenv to clear Hub env vars (SCION_HUB_ENDPOINT, SCION_HUB_URL, SCION_AUTH_TOKEN, SCION_AGENT_ID, SCION_AGENT_MODE) with automatic restore on test cleanup - Filter Hub env vars from subprocess Cmd.Env in TestInitCommand_Integration as belt-and-suspenders protection - Convert os.Setenv/os.Unsetenv to t.Setenv throughout hub_test.go and client_test.go for crash-safe env var isolation
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
Fixes #123
Primary fix:
TestInitCommand_Integrationincmd/sciontool/commands/init_test.gobuilds and spawns a real sciontool binary as a subprocess. When run inside an agent container, the child process inherited live Hub env vars (SCION_HUB_ENDPOINT,SCION_AUTH_TOKEN,SCION_AGENT_ID, etc.), causing it to talk to the real Hub and corrupt agent state (resetting phase to "starting"). This is how dev-issue-71b got stuck.Secondary fix:
pkg/sciontool/hooks/handlers/hub_test.goandpkg/sciontool/hub/client_test.gousedos.Setenv/os.Unsetenvinstead oft.Setenv, leaving env vars in a corrupted state if tests failed or panicked. Converted all env var management tot.Setenvfor crash-safe, automatic cleanup.Changes
cmd/sciontool/commands/init_test.go: AddedscrubHubEnv(t)andfilterHubEnv()helpers.TestInitCommand_Integrationnow clears Hub env vars before spawning the subprocess, and explicitly filterstestCmd.Envas belt-and-suspenders protection.pkg/sciontool/hooks/handlers/hub_test.go: Converted allos.Setenv("HOME", ...)/defer os.Setenv(...)andos.Setenv("SCION_HUB_ENDPOINT", ...)/defer os.Unsetenv(...)patterns tot.Setenv(). AddedscrubHubEnv(t)calls before setting test values. Removed all manual defer cleanup blocks.pkg/sciontool/hub/client_test.go: Converted all save-restore env var patterns (origX := os.Getenv(...); defer os.Setenv(...)) tot.Setenv(). Removedosimport (no longer needed).Net result: 181 insertions, 225 deletions — the code is shorter and safer.
Test plan
go test ./cmd/sciontool/commands/ -run TestInitCommand -v— passesgo test ./pkg/sciontool/hooks/handlers/ -v— all hub handler tests passgo test ./pkg/sciontool/hub/ -v— all hub client tests passgo vet ./cmd/sciontool/... ./pkg/sciontool/...— cleanmake fmt— no formatting changes needed