test: cover path traversal rejection
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package api
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestUnsafePath(t *testing.T) {
|
||||
cases := map[string]bool{
|
||||
"../secret": true,
|
||||
"a/../secret": true,
|
||||
`..\\secret`: true,
|
||||
"%2e%2e/secret": false,
|
||||
"secret": false,
|
||||
"a//b": false,
|
||||
"": false,
|
||||
}
|
||||
for p, want := range cases {
|
||||
if got := unsafePath(p); got != want {
|
||||
t.Fatalf("unsafePath(%q)=%v, want %v", p, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user