mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
feat: Experimental Sandbox Support (#101)
* feat: Sandbox implementation with seatbelt * refactor: Remove concept of PM_CACHE * fix: Misc fixes * refactor: Sandbox for separation of boundaries * fix: Apply API * fix: Add support for sandbox cleanup * test: Add variable interpolation test * fix: Misc cleanup fixes * chore: Cleanup sandbox registry * chore: Cleanup sandbox policy * chore: Cleanup sandbox * fix: Misc cleanup fixes * fix: Remove violation mode * fix: Update config template * chore: Go mod cleanup * fix: Handle the case when package manager policy is explicitly disabled * fix: Sandbox executor * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Abhisek Datta <abhisek.datta@gmail.com> * test: Remove unused var * test: Add test for seatbelt sandbox driver * fix: Sandbox profile loader from file should use path for caching * test: Add policy test * feat: Add support for config templates * fix: Seatbelt translator handle glob * fix: Merge conflicts * fix: Fix sandbox policy generator for MacOS min permissions * fix: Sandbox path handling bugs * fix: Deny read to dangerous directories * fix: Deny read to dangerous directories * add sandbox e2e (#112) * fix: Sandbox E2E test * fix: Code review fixes * fix: Code review fixes * doc: Add sandbox debugging guide * doc: Update sandbox doc * docs: Add sandbox usage doc * fix: Use better error for sandbox without policy * fix: Add sandbox for npx * fix: Enable PTY for npm --------- Signed-off-by: Abhisek Datta <abhisek.datta@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Sahil Bansal <bansalsahil315@gmail.com>
This commit is contained in:
co-authored by
Copilot
Sahil Bansal
parent
c0122898ca
commit
9693428171
@@ -0,0 +1,70 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetTmpdirParent(t *testing.T) {
|
||||
// Save original TMPDIR
|
||||
originalTmpdir := os.Getenv("TMPDIR")
|
||||
defer os.Setenv("TMPDIR", originalTmpdir)
|
||||
|
||||
t.Run("macOS pattern with /var prefix", func(t *testing.T) {
|
||||
os.Setenv("TMPDIR", "/var/folders/ab/cd1234ef/T/")
|
||||
parents := GetTmpdirParent()
|
||||
|
||||
assert.Len(t, parents, 2)
|
||||
assert.Contains(t, parents, "/var/folders/ab/cd1234ef")
|
||||
assert.Contains(t, parents, "/private/var/folders/ab/cd1234ef")
|
||||
})
|
||||
|
||||
t.Run("macOS pattern with /private/var prefix", func(t *testing.T) {
|
||||
os.Setenv("TMPDIR", "/private/var/folders/xy/z9876543/T/")
|
||||
parents := GetTmpdirParent()
|
||||
|
||||
assert.Len(t, parents, 2)
|
||||
assert.Contains(t, parents, "/private/var/folders/xy/z9876543")
|
||||
assert.Contains(t, parents, "/var/folders/xy/z9876543")
|
||||
})
|
||||
|
||||
t.Run("macOS pattern without trailing slash", func(t *testing.T) {
|
||||
os.Setenv("TMPDIR", "/var/folders/12/abcdefgh/T")
|
||||
parents := GetTmpdirParent()
|
||||
|
||||
assert.Len(t, parents, 2)
|
||||
assert.Contains(t, parents, "/var/folders/12/abcdefgh")
|
||||
assert.Contains(t, parents, "/private/var/folders/12/abcdefgh")
|
||||
})
|
||||
|
||||
t.Run("non-macOS pattern returns empty", func(t *testing.T) {
|
||||
testCases := []string{
|
||||
"/tmp",
|
||||
"/var/tmp",
|
||||
"/custom/temp",
|
||||
"/var/folders/",
|
||||
"/var/folders/ab/",
|
||||
"/var/folders/abc/def/T/", // XX should be 2 chars, not 3
|
||||
}
|
||||
|
||||
for _, tmpdir := range testCases {
|
||||
os.Setenv("TMPDIR", tmpdir)
|
||||
parents := GetTmpdirParent()
|
||||
assert.Empty(t, parents, "Expected empty result for TMPDIR=%s", tmpdir)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("empty TMPDIR returns empty", func(t *testing.T) {
|
||||
os.Setenv("TMPDIR", "")
|
||||
parents := GetTmpdirParent()
|
||||
assert.Empty(t, parents)
|
||||
})
|
||||
|
||||
t.Run("unset TMPDIR returns empty", func(t *testing.T) {
|
||||
os.Unsetenv("TMPDIR")
|
||||
parents := GetTmpdirParent()
|
||||
assert.Empty(t, parents)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user