aboutsummaryrefslogtreecommitdiff
path: root/internal/tool
diff options
context:
space:
mode:
authorᴜɴᴋɴᴡᴏɴ <u@gogs.io>2020-04-19 04:24:08 +0800
committerGitHub <noreply@github.com>2020-04-19 04:24:08 +0800
commitc0fd6042fd56646f24275785faf5cd40ed8ab2c2 (patch)
tree6e448c85aefed0edeacf396608b7667c43e14d63 /internal/tool
parentfc57c921b1716f0f84b5b2d4d5693091c48a4b2d (diff)
test: remove the use of goconvey (#6123)
Diffstat (limited to 'internal/tool')
-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))
+ })
+ }
}