Refactor external URL detection (#29973)
Follow #29960, `IsExternalURL` is not needed anymore. Add some tests for `RedirectToCurrentSite`
This commit is contained in:
parent
bfa160fc98
commit
ca4107dc96
7 changed files with 40 additions and 62 deletions
|
@ -5,47 +5,8 @@ package utils
|
|||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestIsExternalURL(t *testing.T) {
|
||||
setting.AppURL = "https://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"),
|
||||
newTest(true,
|
||||
"://missing protocol scheme"),
|
||||
} {
|
||||
assert.Equal(t, test.Expected, IsExternalURL(test.RawURL))
|
||||
}
|
||||
}
|
||||
|
||||
func TestSanitizeFlashErrorString(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue