diff --git a/app/oauth.go b/app/oauth.go index ea747fb75d..9e3bbc9dd9 100644 --- a/app/oauth.go +++ b/app/oauth.go @@ -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) diff --git a/app/oauth_test.go b/app/oauth_test.go index 7b0ccd492a..35c2904b94 100644 --- a/app/oauth_test.go +++ b/app/oauth_test.go @@ -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