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
600 B
Go

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",
}
err := rf.Clean(false)
is.NoErr(err)
is.Equal(rf.Path, tc.clean)
}
}
func TestSwampPathStrict(t *testing.T) {
is := is.New(t)
rf := FileReference{
"/a/../b",
"ns",
}
err := rf.Clean(true)
is.Equal(err, ErrUnacceptablePath)
}