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

Function TestValidateAbsolutePath

pkg/fileutil/fileutil_test.go:47–148  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

45}
46
47func TestValidateAbsolutePath(t *testing.T) {
48 tests := []struct {
49 name string
50 path string
51 shouldError bool
52 errorMsg string
53 }{
54 {
55 name: "valid absolute Unix path",
56 path: "/home/user/file.txt",
57 shouldError: false,
58 },
59 {
60 name: "valid absolute path with cleaned components",
61 path: "/home/user/../user/file.txt",
62 shouldError: false,
63 },
64 {
65 name: "empty path",
66 path: "",
67 shouldError: true,
68 errorMsg: "path cannot be empty",
69 },
70 {
71 name: "relative path",
72 path: "relative/path.txt",
73 shouldError: true,
74 errorMsg: "path must be absolute",
75 },
76 {
77 name: "relative path with dot",
78 path: "./file.txt",
79 shouldError: true,
80 errorMsg: "path must be absolute",
81 },
82 {
83 name: "relative path with double dot",
84 path: "../file.txt",
85 shouldError: true,
86 errorMsg: "path must be absolute",
87 },
88 {
89 name: "path traversal attempt",
90 path: "../../../etc/passwd",
91 shouldError: true,
92 errorMsg: "path must be absolute",
93 },
94 {
95 name: "single dot",
96 path: ".",
97 shouldError: true,
98 errorMsg: "path must be absolute",
99 },
100 {
101 name: "double dot",
102 path: "..",
103 shouldError: true,
104 errorMsg: "path must be absolute",

Callers

nothing calls this directly

Calls 3

ValidateAbsolutePathFunction · 0.85
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected