High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
refactor(testutil): move security flags to ServerConfig
Bosch222bfcd505e4
diff --git a/tests/integration/config_cli_test.go b/tests/integration/config_cli_test.goindex 38bc4371..8ca4db34 100644--- a/tests/integration/config_cli_test.go+++ b/tests/integration/config_cli_test.go@@ -14,10 +14,16 @@ import (// TestConfigCLI_Init tests `pinchtab config init`func TestConfigCLI_Init(t *testing.T) {tmpDir := t.TempDir()- configPath := filepath.Join(tmpDir, "config.json")+ // config init writes to userConfigDir() which is $HOME/.pinchtab on macOS (legacy path)+ // or ~/Library/Application Support/pinchtab (new path). Create the legacy dir so it's used.+ legacyDir := filepath.Join(tmpDir, ".pinchtab")+ if err := os.MkdirAll(legacyDir, 0755); err != nil {+ t.Fatal(err)+ }+ configPath := filepath.Join(legacyDir, "config.json")cmd := exec.Command(server.BinaryPath, "config", "init")- cmd.Env = append(filterTestEnv(), "PINCHTAB_CONFIG="+configPath, "HOME="+tmpDir)+ cmd.Env = append(filterTestEnv(), "HOME="+tmpDir)out, err := cmd.CombinedOutput()if err != nil {@@ -27,7 +33,7 @@ func TestConfigCLI_Init(t *testing.T) {// Verify file was createddata, err := os.ReadFile(configPath)if err != nil {- t.Fatalf("config file not created: %v", err)+ t.Fatalf("config file not created at %s: %v\nOutput: %s", configPath, err, out)}// Verify it's valid nested JSONdiff --git a/tests/testutil/server.go b/tests/testutil/server.goindex 48eb79d5..d4917a77 100644--- a/tests/testutil/server.go+++ b/tests/testutil/server.go@@ -25,13 +25,25 @@ const (// ServerConfig mirrors key fields from internal/config.RuntimeConfig for test setup.// Only includes fields commonly overridden in tests.type ServerConfig struct {- Port string // default: "19867"+ // Server+ Port string // default: "19867"++ // ChromeHeadless bool // default: trueStealth string // default: "light"- TabEvictionPolicy string // default: "" (uses config default: "reject")- Strategy string // default: "" (uses config default: "simple")- AllocationPolicy string // default: "" (uses config default: "fcfs")MaxTabs int // default: 0 (uses config default: 20)+ TabEvictionPolicy string // default: "" (uses config default: "reject")++ // Security - all default to true for tests (unlike production defaults)+ AllowEvaluate bool // default: true (tests need this)+ AllowMacro bool // default: false+ AllowScreencast bool // default: false+ AllowDownload bool // default: false+ AllowUpload bool // default: false++ // Orchestrator+ Strategy string // default: "" (uses config default: "simple")+ AllocationPolicy string // default: "" (uses config default: "fcfs")}func DefaultConfig() ServerConfig {@@ -40,9 +52,10 @@ func DefaultConfig() ServerConfig {port = "19867"}return ServerConfig{- Port: port,- Headless: true,- Stealth: "light",+ Port: port,+ Headless: true,+ Stealth: "light",+ AllowEvaluate: true, // tests need evaluate for assertions}}@@ -102,6 +115,8 @@ func StartServer(cfg ServerConfig) (*Server, error) {// Strip existing BRIDGE_*/PINCHTAB_* to avoid test pollution from host configenv := filterEnv(os.Environ(), "BRIDGE_", "PINCHTAB_")++ // Core server configenv = append(env,"PINCHTAB_PORT="+cfg.Port,"PINCHTAB_HEADLESS="+boolStr(cfg.Headless),@@ -110,7 +125,17 @@ func StartServer(cfg ServerConfig) (*Server, error) {"PINCHTAB_STATE_DIR="+s.StateDir,"PINCHTAB_PROFILE_DIR="+s.ProfileDir,)- // Optional config overrides++ // Security flags from ServerConfig+ env = append(env,+ "PINCHTAB_ALLOW_EVALUATE="+boolStr(cfg.AllowEvaluate),+ "PINCHTAB_ALLOW_MACRO="+boolStr(cfg.AllowMacro),+ "PINCHTAB_ALLOW_SCREENCAST="+boolStr(cfg.AllowScreencast),+ "PINCHTAB_ALLOW_DOWNLOAD="+boolStr(cfg.AllowDownload),+ "PINCHTAB_ALLOW_UPLOAD="+boolStr(cfg.AllowUpload),+ )++ // Optional config overrides (only set if non-default)if cfg.TabEvictionPolicy != "" {env = append(env, "PINCHTAB_TAB_EVICTION_POLICY="+cfg.TabEvictionPolicy)}@@ -123,21 +148,11 @@ func StartServer(cfg ServerConfig) (*Server, error) {if cfg.MaxTabs > 0 {env = append(env, fmt.Sprintf("PINCHTAB_MAX_TABS=%d", cfg.MaxTabs))}++ // Chrome binary from host (for CI environments)if bin := os.Getenv("CHROME_BINARY"); bin != "" {env = append(env, "CHROME_BINARY="+bin)}- // Pass through feature gates for integration tests- for _, gate := range []string{- "PINCHTAB_ALLOW_EVALUATE",- "PINCHTAB_ALLOW_MACRO",- "PINCHTAB_ALLOW_SCREENCAST",- "PINCHTAB_ALLOW_DOWNLOAD",- "PINCHTAB_ALLOW_UPLOAD",- } {- if v := os.Getenv(gate); v != "" {- env = append(env, gate+"="+v)- }- }s.cmd = exec.Command(s.BinaryPath) // #nosec G204 -- BinaryPath is from os.MkdirTemp, not user inputs.cmd.Env = env