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.
45 lines
600 B
Go
45 lines
600 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",
|
||
|
}
|
||
|
|
||
|
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)
|
||
|
}
|