Skip to content

Fix test suite leaking Hub credentials, corrupting agent state#125

Closed
scion-gteam[bot] wants to merge 2 commits into
mainfrom
scion/dev-issue-123
Closed

Fix test suite leaking Hub credentials, corrupting agent state#125
scion-gteam[bot] wants to merge 2 commits into
mainfrom
scion/dev-issue-123

Conversation

@scion-gteam
Copy link
Copy Markdown

@scion-gteam scion-gteam Bot commented Jun 2, 2026

Summary

Fixes #123

  • Primary fix: TestInitCommand_Integration in cmd/sciontool/commands/init_test.go builds 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.go and pkg/sciontool/hub/client_test.go used os.Setenv/os.Unsetenv instead of t.Setenv, leaving env vars in a corrupted state if tests failed or panicked. Converted all env var management to t.Setenv for crash-safe, automatic cleanup.

Changes

  1. cmd/sciontool/commands/init_test.go: Added scrubHubEnv(t) and filterHubEnv() helpers. TestInitCommand_Integration now clears Hub env vars before spawning the subprocess, and explicitly filters testCmd.Env as belt-and-suspenders protection.

  2. pkg/sciontool/hooks/handlers/hub_test.go: Converted all os.Setenv("HOME", ...)/defer os.Setenv(...) and os.Setenv("SCION_HUB_ENDPOINT", ...)/defer os.Unsetenv(...) patterns to t.Setenv(). Added scrubHubEnv(t) calls before setting test values. Removed all manual defer cleanup blocks.

  3. pkg/sciontool/hub/client_test.go: Converted all save-restore env var patterns (origX := os.Getenv(...); defer os.Setenv(...)) to t.Setenv(). Removed os import (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 — passes
  • go test ./pkg/sciontool/hooks/handlers/ -v — all hub handler tests pass
  • go test ./pkg/sciontool/hub/ -v — all hub client tests pass
  • go vet ./cmd/sciontool/... ./pkg/sciontool/... — clean
  • make fmt — no formatting changes needed

ptone added 2 commits June 2, 2026 14:28
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
@ptone ptone closed this Jun 2, 2026
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.

Go test suite leaks Hub credentials, corrupts agent state

1 participant