56 lines
817 B
Go
56 lines
817 B
Go
|
package fstore
|
||
|
|
||
|
import "testing"
|
||
|
|
||
|
func TestValidatePath_valid(t *testing.T) {
|
||
|
cases := []string{
|
||
|
"/",
|
||
|
"/a/z/0.9/a-b_c.d/",
|
||
|
"/a/../b",
|
||
|
"/x/abcdefghijklmnopqrstuvwxyz/0123456789/_.-",
|
||
|
}
|
||
|
|
||
|
for _, s := range cases {
|
||
|
if err := validatePath(s); err != nil {
|
||
|
t.Fatal(s, err)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestValidatePath_invalid(t *testing.T) {
|
||
|
cases := []string{
|
||
|
"",
|
||
|
"/A",
|
||
|
"/a/b/~xyz/",
|
||
|
"/a\\b",
|
||
|
"a/b/c",
|
||
|
}
|
||
|
|
||
|
for _, s := range cases {
|
||
|
if err := validatePath(s); err == nil {
|
||
|
t.Fatal(s)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestCleanPath(t *testing.T) {
|
||
|
type Case struct {
|
||
|
In, Out string
|
||
|
}
|
||
|
|
||
|
cases := []Case{
|
||
|
{"", "/"},
|
||
|
{"../", "/"},
|
||
|
{"a/b", "/a/b"},
|
||
|
{"/a/b/../../../", "/"},
|
||
|
{"a/b/../../../", "/"},
|
||
|
}
|
||
|
|
||
|
for _, c := range cases {
|
||
|
out := cleanPath(c.In)
|
||
|
if out != c.Out {
|
||
|
t.Fatal(c.In, out, c.Out)
|
||
|
}
|
||
|
}
|
||
|
}
|