TestSpec_PublicAPI_ValidatePathWithinBase validates that candidate must be within the base directory. Spec: "prevents both .. traversal and symlink escapes"
(t *testing.T)
| 70 | // TestSpec_PublicAPI_ValidatePathWithinBase validates that candidate must be within the base directory. |
| 71 | // Spec: "prevents both .. traversal and symlink escapes" |
| 72 | func 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. |
nothing calls this directly
no test coverage detected