|
|
@@ -7,6 +7,8 @@ package util |
|
|
|
import ( |
|
|
|
"testing" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/setting" |
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert" |
|
|
|
) |
|
|
|
|
|
|
@@ -42,3 +44,36 @@ func TestURLJoin(t *testing.T) { |
|
|
|
assert.Equal(t, test.Expected, URLJoin(test.Base, test.Elements...)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func TestIsExternalURL(t *testing.T) { |
|
|
|
setting.Domain = "try.gitea.io" |
|
|
|
type test struct { |
|
|
|
Expected bool |
|
|
|
RawURL string |
|
|
|
} |
|
|
|
newTest := func(expected bool, rawURL string) test { |
|
|
|
return test{Expected: expected, RawURL: rawURL} |
|
|
|
} |
|
|
|
for _, test := range []test{ |
|
|
|
newTest(false, |
|
|
|
"https://try.gitea.io"), |
|
|
|
newTest(true, |
|
|
|
"https://example.com/"), |
|
|
|
newTest(true, |
|
|
|
"//example.com"), |
|
|
|
newTest(true, |
|
|
|
"http://example.com"), |
|
|
|
newTest(false, |
|
|
|
"a/"), |
|
|
|
newTest(false, |
|
|
|
"https://try.gitea.io/test?param=false"), |
|
|
|
newTest(false, |
|
|
|
"test?param=false"), |
|
|
|
newTest(false, |
|
|
|
"//try.gitea.io/test?param=false"), |
|
|
|
newTest(false, |
|
|
|
"/hey/hey/hey#3244"), |
|
|
|
} { |
|
|
|
assert.Equal(t, test.Expected, IsExternalURL(test.RawURL)) |
|
|
|
} |
|
|
|
} |