aboutsummaryrefslogtreecommitdiff
path: root/internal/tool/path_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/tool/path_test.go')
-rw-r--r--internal/tool/path_test.go74
1 files changed, 37 insertions, 37 deletions
diff --git a/internal/tool/path_test.go b/internal/tool/path_test.go
index 44ee975f..be9b5192 100644
--- a/internal/tool/path_test.go
+++ b/internal/tool/path_test.go
@@ -7,47 +7,47 @@ package tool
import (
"testing"
- . "github.com/smartystreets/goconvey/convey"
+ "github.com/stretchr/testify/assert"
)
func Test_IsSameSiteURLPath(t *testing.T) {
- Convey("Check if a path belongs to the same site", t, func() {
- testCases := []struct {
- url string
- expect bool
- }{
- {"//github.com", false},
- {"http://github.com", false},
- {"https://github.com", false},
- {"/\\github.com", false},
-
- {"/admin", true},
- {"/user/repo", true},
- }
-
- for _, tc := range testCases {
- So(IsSameSiteURLPath(tc.url), ShouldEqual, tc.expect)
- }
- })
+ tests := []struct {
+ url string
+ expVal bool
+ }{
+ {url: "//github.com", expVal: false},
+ {url: "http://github.com", expVal: false},
+ {url: "https://github.com", expVal: false},
+ {url: "/\\github.com", expVal: false},
+
+ {url: "/admin", expVal: true},
+ {url: "/user/repo", expVal: true},
+ }
+
+ for _, test := range tests {
+ t.Run(test.url, func(t *testing.T) {
+ assert.Equal(t, test.expVal, IsSameSiteURLPath(test.url))
+ })
+ }
}
func Test_IsMaliciousPath(t *testing.T) {
- Convey("Detects malicious path", t, func() {
- testCases := []struct {
- path string
- expect bool
- }{
- {"../../../../../../../../../data/gogs/data/sessions/a/9/a9f0ab6c3ef63dd8", true},
- {"..\\/..\\/../data/gogs/data/sessions/a/9/a9f0ab6c3ef63dd8", true},
- {"data/gogs/../../../../../../../../../data/sessions/a/9/a9f0ab6c3ef63dd8", true},
- {"..\\..\\..\\..\\..\\..\\..\\..\\..\\data\\gogs\\data\\sessions\\a\\9\\a9f0ab6c3ef63dd8", true},
- {"data\\gogs\\..\\..\\..\\..\\..\\..\\..\\..\\..\\data\\sessions\\a\\9\\a9f0ab6c3ef63dd8", true},
-
- {"data/sessions/a/9/a9f0ab6c3ef63dd8", false},
- {"data\\sessions\\a\\9\\a9f0ab6c3ef63dd8", false},
- }
- for _, tc := range testCases {
- So(IsMaliciousPath(tc.path), ShouldEqual, tc.expect)
- }
- })
+ tests := []struct {
+ path string
+ expVal bool
+ }{
+ {path: "../../../../../../../../../data/gogs/data/sessions/a/9/a9f0ab6c3ef63dd8", expVal: true},
+ {path: "..\\/..\\/../data/gogs/data/sessions/a/9/a9f0ab6c3ef63dd8", expVal: true},
+ {path: "data/gogs/../../../../../../../../../data/sessions/a/9/a9f0ab6c3ef63dd8", expVal: true},
+ {path: "..\\..\\..\\..\\..\\..\\..\\..\\..\\data\\gogs\\data\\sessions\\a\\9\\a9f0ab6c3ef63dd8", expVal: true},
+ {path: "data\\gogs\\..\\..\\..\\..\\..\\..\\..\\..\\..\\data\\sessions\\a\\9\\a9f0ab6c3ef63dd8", expVal: true},
+
+ {path: "data/sessions/a/9/a9f0ab6c3ef63dd8", expVal: false},
+ {path: "data\\sessions\\a\\9\\a9f0ab6c3ef63dd8", expVal: false},
+ }
+ for _, test := range tests {
+ t.Run(test.path, func(t *testing.T) {
+ assert.Equal(t, test.expVal, IsMaliciousPath(test.path))
+ })
+ }
}