aboutsummaryrefslogtreecommitdiffstats
path: root/modules/validation/helpers_test.go
diff options
context:
space:
mode:
authormrsdizzie <info@mrsdizzie.com>2019-05-31 05:21:15 -0400
committerzeripath <art27@cantab.net>2019-05-31 10:21:15 +0100
commitde6ef14d04c36272143ad822bf5903f84c7f238b (patch)
treeb22bbf05e883fc935e7c265a827edd591dabcbdd /modules/validation/helpers_test.go
parent592924a34b8e671c93416c01a468b9aab0ab39aa (diff)
downloadgitea-de6ef14d04c36272143ad822bf5903f84c7f238b.tar.gz
gitea-de6ef14d04c36272143ad822bf5903f84c7f238b.zip
Validate External Tracker URL Format (#7089)
* Validate External Tracker URL Format Add some validation checks for external tracker URL format. Fixes #7068 * Don't make {index} a hard requirement * Fix Description * make fmt * move regex to package level * fix copyright date
Diffstat (limited to 'modules/validation/helpers_test.go')
-rw-r--r--modules/validation/helpers_test.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/modules/validation/helpers_test.go b/modules/validation/helpers_test.go
index 875625a02c..9051ee1a0d 100644
--- a/modules/validation/helpers_test.go
+++ b/modules/validation/helpers_test.go
@@ -88,3 +88,70 @@ func Test_IsValidExternalURL(t *testing.T) {
})
}
}
+
+func Test_IsValidExternalTrackerURLFormat(t *testing.T) {
+ setting.AppURL = "https://try.gitea.io/"
+
+ cases := []struct {
+ description string
+ url string
+ valid bool
+ }{
+ {
+ description: "Correct external tracker URL with all placeholders",
+ url: "https://github.com/{user}/{repo}/issues/{index}",
+ valid: true,
+ },
+ {
+ description: "Local external tracker URL with all placeholders",
+ url: "https://127.0.0.1/{user}/{repo}/issues/{index}",
+ valid: false,
+ },
+ {
+ description: "External tracker URL with typo placeholder",
+ url: "https://github.com/{user}/{repo/issues/{index}",
+ valid: false,
+ },
+ {
+ description: "External tracker URL with typo placeholder",
+ url: "https://github.com/[user}/{repo/issues/{index}",
+ valid: false,
+ },
+ {
+ description: "External tracker URL with typo placeholder",
+ url: "https://github.com/{user}/repo}/issues/{index}",
+ valid: false,
+ },
+ {
+ description: "External tracker URL missing optional placeholder",
+ url: "https://github.com/{user}/issues/{index}",
+ valid: true,
+ },
+ {
+ description: "External tracker URL missing optional placeholder",
+ url: "https://github.com/{repo}/issues/{index}",
+ valid: true,
+ },
+ {
+ description: "External tracker URL missing optional placeholder",
+ url: "https://github.com/issues/{index}",
+ valid: true,
+ },
+ {
+ description: "External tracker URL missing optional placeholder",
+ url: "https://github.com/issues/{user}",
+ valid: true,
+ },
+ {
+ description: "External tracker URL with similar placeholder names test",
+ url: "https://github.com/user/repo/issues/{index}",
+ valid: true,
+ },
+ }
+
+ for _, testCase := range cases {
+ t.Run(testCase.description, func(t *testing.T) {
+ assert.Equal(t, testCase.valid, IsValidExternalTrackerURLFormat(testCase.url))
+ })
+ }
+}