MCPcopy Create free account
hub / github.com/github/gh-aw / TestSpec_PublicAPI_ValidatePathWithinBase

Function TestSpec_PublicAPI_ValidatePathWithinBase

pkg/fileutil/spec_test.go:72–91  ·  view source on GitHub ↗

TestSpec_PublicAPI_ValidatePathWithinBase validates that candidate must be within the base directory. Spec: "prevents both .. traversal and symlink escapes"

(t *testing.T)

Source from the content-addressed store, hash-verified

70// TestSpec_PublicAPI_ValidatePathWithinBase validates that candidate must be within the base directory.
71// Spec: "prevents both .. traversal and symlink escapes"
72func TestSpec_PublicAPI_ValidatePathWithinBase(t *testing.T) {
73 base := t.TempDir()
74 within := filepath.Join(base, "subdir", "file.txt")
75 outside := filepath.Join(base, "..", "outside")
76
77 t.Run("accepts path within base", func(t *testing.T) {
78 err := fileutil.ValidatePathWithinBase(base, within)
79 assert.NoError(t, err, "path within base should be accepted")
80 })
81
82 t.Run("rejects path outside base", func(t *testing.T) {
83 err := fileutil.ValidatePathWithinBase(base, outside)
84 assert.Error(t, err, "path outside base should be rejected")
85 })
86
87 t.Run("accepts base path itself", func(t *testing.T) {
88 err := fileutil.ValidatePathWithinBase(base, base)
89 assert.NoError(t, err, "base path itself should be accepted")
90 })
91}
92
93// TestSpec_PublicAPI_FileExists validates the documented behavior:
94// returns true for regular files, false for directories and non-existent paths.

Callers

nothing calls this directly

Calls 3

ValidatePathWithinBaseFunction · 0.92
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected