mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
feat: Add support for environment protection (scrubbing) (#327)
* feat: Add support for environment variable protection for sandbox * chore: Update dangerous env var list * fix: Split profiles for improved environment protection * fix: pipx sandbox profile separation * chore: Show sandbox scrub info on error exit * fix: Code review fixes * test: Add e2e for sandbox environment scrubbing
This commit is contained in:
@@ -94,6 +94,48 @@ func TestParseSandboxAllowOverrides_ValidFormats(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSandboxAllowOverrides_Env(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
raw string
|
||||
expectedValue string
|
||||
}{
|
||||
{name: "exact name", raw: "env=NPM_TOKEN", expectedValue: "NPM_TOKEN"},
|
||||
{name: "glob name kept verbatim", raw: "env=npm_config_*", expectedValue: "npm_config_*"},
|
||||
{name: "not path resolved", raw: "env=AWS_PROFILE", expectedValue: "AWS_PROFILE"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
overrides, err := parseSandboxAllowOverrides([]string{tt.raw})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, overrides, 1)
|
||||
|
||||
assert.Equal(t, SandboxAllowEnv, overrides[0].Type)
|
||||
// Value is kept verbatim, with no CWD/path resolution.
|
||||
assert.Equal(t, tt.expectedValue, overrides[0].Value)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSandboxAllowOverrides_EnvInvalid(t *testing.T) {
|
||||
invalid := []string{
|
||||
"env=NPM/TOKEN",
|
||||
"env=FOO=BAR",
|
||||
"env=HAS SPACE",
|
||||
"env=HAS\tTAB",
|
||||
"env=HAS\nNEWLINE",
|
||||
"env=HAS\rRETURN",
|
||||
"env=BACK\\SLASH",
|
||||
"env=CTRL\x07CHAR",
|
||||
}
|
||||
|
||||
for _, raw := range invalid {
|
||||
_, err := parseSandboxAllowOverrides([]string{raw})
|
||||
assert.Error(t, err, "expected error for %q", raw)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSandboxAllowOverrides_MultipleValues(t *testing.T) {
|
||||
raw := []string{
|
||||
"write=./.gitignore",
|
||||
|
||||
Reference in New Issue
Block a user