This commit is contained in:
@@ -6,9 +6,6 @@ package validation
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -47,51 +44,7 @@ func Test_IsValidURL(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func Test_IsValidExternalURL(t *testing.T) {
|
||||
defer test.MockVariableValue(&setting.AppURL, "https://try.gitea.io/")()
|
||||
|
||||
cases := []struct {
|
||||
description string
|
||||
url string
|
||||
valid bool
|
||||
}{
|
||||
{
|
||||
description: "Current instance URL",
|
||||
url: "https://try.gitea.io/test",
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
description: "Loopback IPv4 URL",
|
||||
url: "http://127.0.1.1:5678/",
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
description: "Current instance API URL",
|
||||
url: "https://try.gitea.io/api/v1/user/follow",
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
description: "Local network URL",
|
||||
url: "http://192.168.1.2/api/v1/user/follow",
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
description: "Local URL",
|
||||
url: "http://LOCALHOST:1234/whatever",
|
||||
valid: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range cases {
|
||||
t.Run(testCase.description, func(t *testing.T) {
|
||||
assert.Equal(t, testCase.valid, IsValidExternalURL(testCase.url))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_IsValidExternalTrackerURLFormat(t *testing.T) {
|
||||
defer test.MockVariableValue(&setting.AppURL, "https://try.gitea.io/")()
|
||||
|
||||
cases := []struct {
|
||||
description string
|
||||
url string
|
||||
@@ -105,7 +58,7 @@ func Test_IsValidExternalTrackerURLFormat(t *testing.T) {
|
||||
{
|
||||
description: "Local external tracker URL with all placeholders",
|
||||
url: "https://127.0.0.1/{user}/{repo}/issues/{index}",
|
||||
valid: false,
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
description: "External tracker URL with typo placeholder",
|
||||
|
||||
Reference in New Issue
Block a user