You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bog/dataswamp/swampfile/valueobjects_test.go

45 lines
607 B
Go

3 years ago
package swampfile
import (
"github.com/matryer/is"
"testing"
)
func TestSwampPathNotStrict(t *testing.T) {
cases := []struct {
dirty string
clean string
}{
{"/", "/"},
{"..", "/"},
{"/../a", "/a"},
{"/../a/../a", "/a"},
{"../b", "/b"},
}
is := is.New(t)
for _, tc := range cases {
rf := FileReference{
tc.dirty,
"ns",
}
rc, err := rf.Clean(false)
3 years ago
is.NoErr(err)
is.Equal(rc.Path, tc.clean)
3 years ago
}
}
func TestSwampPathStrict(t *testing.T) {
is := is.New(t)
rf := FileReference{
"/a/../b",
"ns",
}
_, err := rf.Clean(true)
3 years ago
is.Equal(err, ErrUnacceptablePath)
}