Files
zero/internal/sandbox/scope_windows_test.go
Anandan 644f61fa58 Fix shared temp roots in sandbox scope (#314)
Treat platform temp directories as default writable roots so file tools, shell commands, and sandbox profiles share the same temp view.

On Linux, bind host temp roots instead of mounting an isolated tmpfs at /tmp so artifacts created under /tmp remain visible across tool and shell calls.

Tests: GOCACHE=/tmp/zero-go-cache go test ./internal/sandbox ./internal/tools ./internal/cli ./internal/agent
2026-06-25 09:47:55 +05:30

46 lines
1.6 KiB
Go

//go:build windows
package sandbox
import (
"path/filepath"
"testing"
)
// On Windows a workspace created under an 8.3 short path is resolved by
// EvalSymlinks to its long form, so NormalizePrefixForRoot must resolve a raw
// request's prefix to match — the same alias handling it does for macOS
// /var -> /private/var. If the volume root were mishandled (drive path
// mangled to a drive-relative form), the engine gate would fail OPEN or DENY
// legitimate extra-root writes. This pins both directions on Windows. Caught
// on PR #162's windows smoke run.
func TestScopeValidateHandlesVolumePathsOnWindows(t *testing.T) {
workspace := t.TempDir()
extra := t.TempDir()
scope, err := NewScope(workspace, []string{extra})
if err != nil {
t.Fatalf("NewScope: %v", err)
}
// A path inside a granted root must be allowed even when the workspace/
// extra dirs were created under 8.3 short names and the scope stored their
// long forms.
if block := scope.validate(filepath.Join(extra, "ok.txt")); block != nil {
t.Fatalf("validate(extra-root path) = %v, want nil", block)
}
if block := scope.validate(filepath.Join(workspace, "in.txt")); block != nil {
t.Fatalf("validate(workspace path) = %v, want nil", block)
}
// An absolute path outside all roots must still be denied (no fail-open
// from drive-path mangling).
outside := outsideDefaultTempPath(workspace, "escape.txt")
block := scope.validate(outside)
if block == nil {
t.Fatal("validate(outside all roots) = nil, want block (fail-open regression)")
}
if block.Code != BlockOutsideWorkspace {
t.Fatalf("block.Code=%q want %q", block.Code, BlockOutsideWorkspace)
}
}