Use the correct error variable from provider.GetSSOSettings (#18920)
```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
13c0ba6e8a
Коммит
7a0131ee14
@@ -774,7 +774,7 @@ func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service
|
||||
|
||||
sso, e2 := provider.GetSSOSettings(a.Config(), service)
|
||||
if e2 != nil {
|
||||
return nil, "", nil, nil, model.NewAppError("AuthorizeOAuthUser.GetSSOSettings", "api.user.get_authorization_code.endpoint.app_error", nil, e.Error(), http.StatusNotImplemented)
|
||||
return nil, "", nil, nil, model.NewAppError("AuthorizeOAuthUser.GetSSOSettings", "api.user.get_authorization_code.endpoint.app_error", nil, e2.Error(), http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
b, strErr := b64.StdEncoding.DecodeString(state)
|
||||
|
||||
@@ -6,6 +6,7 @@ package app
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -14,7 +15,10 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/v6/einterfaces/mocks"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin/plugintest/mock"
|
||||
)
|
||||
|
||||
func TestGetOAuthAccessTokenForImplicitFlow(t *testing.T) {
|
||||
@@ -447,6 +451,24 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
assert.Equal(t, "oauth.gitlab.tos.error", err.Id)
|
||||
})
|
||||
|
||||
t.Run("with error in GetSSOSettings", func(t *testing.T) {
|
||||
th := setup(t, true, true, true, "")
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.OpenIdSettings.Enable = true
|
||||
})
|
||||
|
||||
providerMock := &mocks.OAuthProvider{}
|
||||
providerMock.On("GetSSOSettings", mock.Anything, model.ServiceOpenid).Return(nil, errors.New("error"))
|
||||
einterfaces.RegisterOAuthProvider(model.ServiceOpenid, providerMock)
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(nil, nil, model.ServiceOpenid, "", "", "")
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, "api.user.get_authorization_code.endpoint.app_error", err.Id)
|
||||
|
||||
})
|
||||
|
||||
t.Run("enabled and properly configured", func(t *testing.T) {
|
||||
testCases := []struct {
|
||||
Description string
|
||||
|
||||
Ссылка в новой задаче
Block a user