Skip to content

Commit 5f3e5c7

Browse files
committed
Enhance tests for secure environment PATH validation
- Update TestBuildSecureEnvironment to assert inclusion of system paths in the enhanced PATH using assert.Contains. - Improve TestRealWorldNpxScenario to verify enhanced path discovery for executables, providing clearer error messages.
1 parent 0fb2286 commit 5f3e5c7

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

internal/secureenv/manager_test.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package secureenv
33
import (
44
"os"
55
"runtime"
6+
"strings"
67
"testing"
78

89
"github.com/stretchr/testify/assert"
@@ -172,8 +173,11 @@ func TestBuildSecureEnvironment(t *testing.T) {
172173
}
173174
}
174175

175-
// Should include allowed system variables
176-
assert.Equal(t, "/usr/bin:/bin", envMap["PATH"])
176+
// Should include allowed system variables with enhanced PATH discovery
177+
pathValue := envMap["PATH"]
178+
assert.Contains(t, pathValue, "/usr/bin", "PATH should contain /usr/bin")
179+
assert.Contains(t, pathValue, "/bin", "PATH should contain /bin")
180+
// Enhanced PATH discovery may include additional paths like /opt/homebrew/bin
177181
assert.Equal(t, "/home/user", envMap["HOME"])
178182
assert.Equal(t, "en_US.UTF-8", envMap["LC_ALL"])
179183

@@ -406,14 +410,21 @@ func TestRealWorldNpxScenario(t *testing.T) {
406410

407411
// Verify PATH is available for npx to find node/npm
408412
foundPath := false
413+
var actualPath string
409414
for _, envVar := range envVars {
410-
if envVar == "PATH="+testPath {
411-
foundPath = true
412-
break
415+
if strings.HasPrefix(envVar, "PATH=") {
416+
actualPath = envVar[5:] // Remove "PATH=" prefix
417+
// Enhanced path discovery should include the original test paths
418+
if strings.Contains(actualPath, "/usr/local/bin") &&
419+
strings.Contains(actualPath, "/usr/bin") &&
420+
strings.Contains(actualPath, "/bin") {
421+
foundPath = true
422+
break
423+
}
413424
}
414425
}
415426

416-
assert.True(t, foundPath, "PATH should be available for npx to find executables")
427+
assert.True(t, foundPath, "PATH should be available for npx to find executables, got: %s", actualPath)
417428
}
418429

419430
// Helper function to split environment variable string

0 commit comments

Comments
 (0)