Support for Custom URI Schemes in OAuth2 Redirect URIs (#37356)
Fix #34349 By the way, remove `(ctx *APIContext) HasAPIError() ` and `(ctx *APIContext) GetErrMsg()` because they do nothing, the error handling has been done in API's middeware The existing OAuth2 tests were not quite right, refactored them together
This commit is contained in:
@@ -14,15 +14,9 @@ import (
|
||||
)
|
||||
|
||||
func TestRegisterForm_IsDomainAllowed_Empty(t *testing.T) {
|
||||
oldService := setting.Service
|
||||
defer func() {
|
||||
setting.Service = oldService
|
||||
}()
|
||||
|
||||
defer test.MockVariableValue(&setting.Service)()
|
||||
setting.Service.EmailDomainAllowList = nil
|
||||
|
||||
form := RegisterForm{}
|
||||
|
||||
assert.True(t, form.IsEmailDomainAllowed())
|
||||
}
|
||||
|
||||
@@ -87,3 +81,30 @@ func TestRegisterForm_IsDomainAllowed_BlockedEmail(t *testing.T) {
|
||||
assert.Equal(t, v.valid, form.IsEmailDomainAllowed())
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetectInvalidOAuth2ApplicationRedirectURI(t *testing.T) {
|
||||
defer test.MockVariableValue(&setting.OAuth2.CustomSchemes)()
|
||||
setting.OAuth2.CustomSchemes = []string{"my-app"}
|
||||
assertValid := func(t *testing.T, s string, valid bool) {
|
||||
ret := DetectInvalidOAuth2ApplicationRedirectURI([]string{s})
|
||||
if valid {
|
||||
assert.Empty(t, ret)
|
||||
} else {
|
||||
assert.Equal(t, s, ret)
|
||||
}
|
||||
}
|
||||
assertValid(t, "my-app:", true)
|
||||
assertValid(t, "my-app:/foo", true)
|
||||
assertValid(t, "http://foo", true)
|
||||
assertValid(t, "https://foo", true)
|
||||
|
||||
assertValid(t, "my-app", false)
|
||||
assertValid(t, "ftp:", false)
|
||||
assertValid(t, "ftp://foo", false)
|
||||
assertValid(t, "https://[invalid", false)
|
||||
|
||||
ret := DetectInvalidOAuth2ApplicationRedirectURI([]string{"my-app:", "http://foo", "https://foo"})
|
||||
assert.Empty(t, ret)
|
||||
ret = DetectInvalidOAuth2ApplicationRedirectURI([]string{"my-app:", "http://foo", "invalid", "https://foo"})
|
||||
assert.Equal(t, "invalid", ret)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user