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

Function TestSpec_PublicAPI_ValidateAbsolutePath

pkg/fileutil/spec_test.go:20–68  ·  view source on GitHub ↗

TestSpec_PublicAPI_ValidateAbsolutePath validates the documented behavior: rejects empty paths, cleans with filepath.Clean, verifies cleaned path is absolute.

(t *testing.T)

Source from the content-addressed store, hash-verified

18// TestSpec_PublicAPI_ValidateAbsolutePath validates the documented behavior:
19// rejects empty paths, cleans with filepath.Clean, verifies cleaned path is absolute.
20func TestSpec_PublicAPI_ValidateAbsolutePath(t *testing.T) {
21 tests := []struct {
22 name string
23 input string
24 wantErr bool
25 expectedOut string
26 }{
27 {
28 name: "rejects empty path",
29 input: "",
30 wantErr: true,
31 },
32 {
33 name: "rejects relative path",
34 input: "relative/path",
35 wantErr: true,
36 },
37 {
38 name: "accepts and returns clean absolute path",
39 input: "/usr/local/bin",
40 wantErr: false,
41 expectedOut: "/usr/local/bin",
42 },
43 {
44 name: "cleans dot components from absolute path",
45 input: "/usr/./local/bin",
46 wantErr: false,
47 expectedOut: "/usr/local/bin",
48 },
49 {
50 name: "cleans double-dot components from absolute path",
51 input: "/usr/local/../bin",
52 wantErr: false,
53 expectedOut: "/usr/bin",
54 },
55 }
56
57 for _, tt := range tests {
58 t.Run(tt.name, func(t *testing.T) {
59 result, err := fileutil.ValidateAbsolutePath(tt.input)
60 if tt.wantErr {
61 assert.Error(t, err, "expected error for input %q", tt.input)
62 return
63 }
64 require.NoError(t, err, "unexpected error for input %q", tt.input)
65 assert.Equal(t, tt.expectedOut, result, "cleaned path mismatch for input %q", tt.input)
66 })
67 }
68}
69
70// TestSpec_PublicAPI_ValidatePathWithinBase validates that candidate must be within the base directory.
71// Spec: "prevents both .. traversal and symlink escapes"

Callers

nothing calls this directly

Calls 3

ValidateAbsolutePathFunction · 0.92
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected