From 7a0131ee14c19bf29a7f0416dc95aae6ce0cecad Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Wed, 3 Nov 2021 19:12:30 +0530 Subject: [PATCH] Use the correct error variable from provider.GetSSOSettings (#18920) ```release-note NONE ``` --- app/oauth.go | 2 +- app/oauth_test.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) 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