Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

test(report): stop the security-defaults test rewriting the real config

Darshan Jaine249efcf0bec
diff --git a/internal/cli/report/security_test.go b/internal/cli/report/security_test.go
index 5e3b0f01..70bb68de 100644
--- a/internal/cli/report/security_test.go
+++ b/internal/cli/report/security_test.go
@@ -5,6 +5,7 @@ import (
"errors"
"os"
"path/filepath"
+ "strings"
"testing"
"github.com/pinchtab/pinchtab/internal/config"
@@ -376,9 +377,29 @@ func TestRestoreSecurityDefaults_RefusesToProvisionIntoAnOperatorConfig(t *testi
func TestRestoreSecurityDefaults_TokenOnlyChangeOnTheDefaultPathIsSaved(t *testing.T) {
tmpHome := t.TempDir()
+ // This test clears PINCHTAB_CONFIG on purpose, so restoreSecurityDefaults
+ // resolves the real default path. Redirecting that default therefore has to
+ // work on every platform: HOME only moves it on darwin and linux, because
+ // config.userConfigDir falls through to os.UserConfigDir elsewhere, which
+ // reads %AppData% and never consults HOME. Both spellings are set because
+ // os.Getenv is case-sensitive even where Windows is not.
+ configHome := filepath.Join(tmpHome, "AppData", "Roaming")
t.Setenv("HOME", tmpHome)
+ t.Setenv("AppData", configHome)
+ t.Setenv("APPDATA", configHome)
t.Setenv("PINCHTAB_CONFIG", "")
- configPath := filepath.Join(tmpHome, ".pinchtab", "config.json")
+
+ // Ask for the default path rather than assuming its shape. The hardcoded
+ // unix layout was the defect: on Windows the fixture landed in
+ // tmpHome\.pinchtab while restoreSecurityDefaults edited %AppData%.
+ configPath := config.DefaultConfigPath()
+ // A default that escaped tmpHome is the operator's own config, and this test
+ // rewrites what it finds there. Fail loudly rather than proceed: before this
+ // guard the escape was silent and the test still PASSED, because the token it
+ // asserts on was already present in the file it should never have opened.
+ if !strings.HasPrefix(configPath, tmpHome) {
+ t.Fatalf("default config path %q escaped the test's temp dir %q; this test would be rewriting the real config", configPath, tmpHome)
+ }
if err := os.MkdirAll(filepath.Dir(configPath), 0o700); err != nil {
t.Fatal(err)
}