diff options
Diffstat (limited to 'pkg/tool/path_test.go')
-rw-r--r-- | pkg/tool/path_test.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/pkg/tool/path_test.go b/pkg/tool/path_test.go index 530238ce..c9e18294 100644 --- a/pkg/tool/path_test.go +++ b/pkg/tool/path_test.go @@ -30,3 +30,19 @@ func Test_IsSameSiteURLPath(t *testing.T) { } }) } + +func Test_SanitizePath(t *testing.T) { + Convey("Sanitize malicious user-defined path", t, func() { + testCases := []struct { + path string + expect string + }{ + {"../../../../../../../../../data/gogs/data/sessions/a/9/a9f0ab6c3ef63dd8", "data/gogs/data/sessions/a/9/a9f0ab6c3ef63dd8"}, + + {"data/sessions/a/9/a9f0ab6c3ef63dd8", "data/sessions/a/9/a9f0ab6c3ef63dd8"}, + } + for _, tc := range testCases { + So(SanitizePath(tc.path), ShouldEqual, tc.expect) + } + }) +} |