Path sanitation
parent
e6e2f372dd
commit
82067ca87c
@ -0,0 +1,44 @@
|
||||
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)
|
||||
}
|
Loading…
Reference in New Issue