(t *testing.T)
| 45 | } |
| 46 | |
| 47 | func 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", |
nothing calls this directly
no test coverage detected