From 93a537a636299e1e049505bdaf072f8d3ae974a4 Mon Sep 17 00:00:00 2001 From: Rodrigo Villablanca Date: Fri, 17 Jul 2020 06:56:08 -0400 Subject: [PATCH] OAuthStore migration (#15013) Automatic Merge --- app/oauth.go | 124 ++++++++++++++---- app/oauth_test.go | 8 +- app/session.go | 6 +- app/user.go | 2 +- i18n/en.json | 144 +++++++-------------- store/opentracing_layer.go | 38 +++--- store/sqlstore/oauth_store.go | 116 ++++++++--------- store/store.go | 38 +++--- store/storetest/mocks/OAuthStore.go | 190 +++++++++++----------------- store/storetest/oauth_store.go | 3 +- store/timer_layer.go | 38 +++--- web/oauth_test.go | 4 +- 12 files changed, 348 insertions(+), 363 deletions(-) diff --git a/app/oauth.go b/app/oauth.go index 635a872ec1..d8ae42242b 100644 --- a/app/oauth.go +++ b/app/oauth.go @@ -35,14 +35,40 @@ func (a *App) CreateOAuthApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppEr app.ClientSecret = model.NewId() - return a.Srv().Store.OAuth().SaveApp(app) + oauthApp, err := a.Srv().Store.OAuth().SaveApp(app) + if err != nil { + var appErr *model.AppError + var invErr *store.ErrInvalidInput + switch { + case errors.As(err, &appErr): + return nil, appErr + case errors.As(err, &invErr): + return nil, model.NewAppError("CreateOAuthApp", "app.oauth.save_app.existing.app_error", nil, invErr.Error(), http.StatusBadRequest) + default: + return nil, model.NewAppError("CreateOAuthApp", "app.oauth.save_app.save.app_error", nil, err.Error(), http.StatusInternalServerError) + } + } + + return oauthApp, nil } func (a *App) GetOAuthApp(appId string) (*model.OAuthApp, *model.AppError) { if !*a.Config().ServiceSettings.EnableOAuthServiceProvider { return nil, model.NewAppError("GetOAuthApp", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented) } - return a.Srv().Store.OAuth().GetApp(appId) + + oauthApp, err := a.Srv().Store.OAuth().GetApp(appId) + if err != nil { + var nfErr *store.ErrNotFound + switch { + case errors.As(err, &nfErr): + return nil, model.NewAppError("GetOAuthApp", "app.oauth.get_app.find.app_error", nil, nfErr.Error(), http.StatusNotFound) + default: + return nil, model.NewAppError("GetOAuthApp", "app.oauth.get_app.finding.app_error", nil, err.Error(), http.StatusInternalServerError) + } + } + + return oauthApp, nil } func (a *App) UpdateOauthApp(oldApp, updatedApp *model.OAuthApp) (*model.OAuthApp, *model.AppError) { @@ -55,7 +81,21 @@ func (a *App) UpdateOauthApp(oldApp, updatedApp *model.OAuthApp) (*model.OAuthAp updatedApp.CreateAt = oldApp.CreateAt updatedApp.ClientSecret = oldApp.ClientSecret - return a.Srv().Store.OAuth().UpdateApp(updatedApp) + oauthApp, err := a.Srv().Store.OAuth().UpdateApp(updatedApp) + if err != nil { + var appErr *model.AppError + var invErr *store.ErrInvalidInput + switch { + case errors.As(err, &appErr): + return nil, appErr + case errors.As(err, &invErr): + return nil, model.NewAppError("UpdateOauthApp", "app.oauth.update_app.find.app_error", nil, invErr.Error(), http.StatusBadRequest) + default: + return nil, model.NewAppError("UpdateOauthApp", "app.oauth.update_app.updating.app_error", nil, err.Error(), http.StatusInternalServerError) + } + } + + return oauthApp, nil } func (a *App) DeleteOAuthApp(appId string) *model.AppError { @@ -64,7 +104,7 @@ func (a *App) DeleteOAuthApp(appId string) *model.AppError { } if err := a.Srv().Store.OAuth().DeleteApp(appId); err != nil { - return err + return model.NewAppError("DeleteOAuthApp", "app.oauth.delete_app.app_error", nil, err.Error(), http.StatusInternalServerError) } if err := a.Srv().InvalidateAllCaches(); err != nil { @@ -79,7 +119,12 @@ func (a *App) GetOAuthApps(page, perPage int) ([]*model.OAuthApp, *model.AppErro return nil, model.NewAppError("GetOAuthApps", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented) } - return a.Srv().Store.OAuth().GetApps(page*perPage, perPage) + oauthApps, err := a.Srv().Store.OAuth().GetApps(page*perPage, perPage) + if err != nil { + return nil, model.NewAppError("GetOAuthApps", "app.oauth.get_apps.find.app_error", nil, err.Error(), http.StatusInternalServerError) + } + + return oauthApps, nil } func (a *App) GetOAuthAppsByCreator(userId string, page, perPage int) ([]*model.OAuthApp, *model.AppError) { @@ -87,7 +132,12 @@ func (a *App) GetOAuthAppsByCreator(userId string, page, perPage int) ([]*model. return nil, model.NewAppError("GetOAuthAppsByUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented) } - return a.Srv().Store.OAuth().GetAppByUser(userId, page*perPage, perPage) + oauthApps, err := a.Srv().Store.OAuth().GetAppByUser(userId, page*perPage, perPage) + if err != nil { + return nil, model.NewAppError("GetOAuthAppsByCreator", "app.oauth.get_app_by_user.find.app_error", nil, err.Error(), http.StatusInternalServerError) + } + + return oauthApps, nil } func (a *App) GetOAuthImplicitRedirect(userId string, authRequest *model.AuthorizeRequest) (string, *model.AppError) { @@ -126,9 +176,15 @@ func (a *App) AllowOAuthAppAccessToUser(userId string, authRequest *model.Author authRequest.Scope = model.DEFAULT_SCOPE } - oauthApp, err := a.Srv().Store.OAuth().GetApp(authRequest.ClientId) - if err != nil { - return "", err + oauthApp, nErr := a.Srv().Store.OAuth().GetApp(authRequest.ClientId) + if nErr != nil { + var nfErr *store.ErrNotFound + switch { + case errors.As(nErr, &nfErr): + return "", model.NewAppError("AllowOAuthAppAccessToUser", "app.oauth.get_app.find.app_error", nil, nfErr.Error(), http.StatusNotFound) + default: + return "", model.NewAppError("AllowOAuthAppAccessToUser", "app.oauth.get_app.finding.app_error", nil, nErr.Error(), http.StatusInternalServerError) + } } if !oauthApp.IsValidRedirectURL(authRequest.RedirectUri) { @@ -136,7 +192,7 @@ func (a *App) AllowOAuthAppAccessToUser(userId string, authRequest *model.Author } var redirectURI string - + var err *model.AppError switch authRequest.ResponseType { case model.AUTHCODE_RESPONSE_TYPE: redirectURI, err = a.GetOAuthCodeRedirect(userId, authRequest) @@ -202,8 +258,8 @@ func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectUri, c return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.disabled.app_error", nil, "", http.StatusNotImplemented) } - oauthApp, err := a.Srv().Store.OAuth().GetApp(clientId) - if err != nil { + oauthApp, nErr := a.Srv().Store.OAuth().GetApp(clientId) + if nErr != nil { return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.credentials.app_error", nil, "", http.StatusNotFound) } @@ -211,18 +267,19 @@ func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectUri, c return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.credentials.app_error", nil, "", http.StatusForbidden) } - var user *model.User var accessData *model.AccessData var accessRsp *model.AccessResponse if grantType == model.ACCESS_TOKEN_GRANT_TYPE { var authData *model.AuthData - authData, err = a.Srv().Store.OAuth().GetAuthData(code) - if err != nil { + authData, nErr = a.Srv().Store.OAuth().GetAuthData(code) + if nErr != nil { return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.expired_code.app_error", nil, "", http.StatusBadRequest) } if authData.IsExpired() { - a.Srv().Store.OAuth().RemoveAuthData(authData.Code) + if nErr = a.Srv().Store.OAuth().RemoveAuthData(authData.Code); nErr != nil { + mlog.Warn("unable to remove auth data", mlog.Err(nErr)) + } return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.expired_code.app_error", nil, "", http.StatusForbidden) } @@ -230,13 +287,13 @@ func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectUri, c return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.redirect_uri.app_error", nil, "", http.StatusBadRequest) } - user, err = a.Srv().Store.User().Get(authData.UserId) + user, err := a.Srv().Store.User().Get(authData.UserId) if err != nil { return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.internal_user.app_error", nil, "", http.StatusNotFound) } - accessData, err = a.Srv().Store.OAuth().GetPreviousAccessData(user.Id, clientId) - if err != nil { + accessData, nErr = a.Srv().Store.OAuth().GetPreviousAccessData(user.Id, clientId) + if nErr != nil { return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.internal.app_error", nil, "", http.StatusBadRequest) } @@ -267,8 +324,8 @@ func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectUri, c accessData = &model.AccessData{ClientId: clientId, UserId: user.Id, Token: session.Token, RefreshToken: model.NewId(), RedirectUri: redirectUri, ExpiresAt: session.ExpiresAt, Scope: authData.Scope} - if _, err = a.Srv().Store.OAuth().SaveAccessData(accessData); err != nil { - mlog.Error("error saving oauth access data in token for code flow", mlog.Err(err)) + if _, nErr = a.Srv().Store.OAuth().SaveAccessData(accessData); nErr != nil { + mlog.Error("error saving oauth access data in token for code flow", mlog.Err(nErr)) return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.internal_saving.app_error", nil, "", http.StatusInternalServerError) } @@ -280,11 +337,13 @@ func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectUri, c } } - a.Srv().Store.OAuth().RemoveAuthData(authData.Code) + if nErr = a.Srv().Store.OAuth().RemoveAuthData(authData.Code); nErr != nil { + mlog.Warn("unable to remove auth data", mlog.Err(nErr)) + } } else { // When grantType is refresh_token - accessData, err = a.Srv().Store.OAuth().GetAccessDataByRefreshToken(refreshToken) - if err != nil { + accessData, nErr = a.Srv().Store.OAuth().GetAccessDataByRefreshToken(refreshToken) + if nErr != nil { return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.refresh_token.app_error", nil, "", http.StatusNotFound) } @@ -394,7 +453,7 @@ func (a *App) GetAuthorizedAppsForUser(userId string, page, perPage int) ([]*mod apps, err := a.Srv().Store.OAuth().GetAuthorizedApps(userId, page*perPage, perPage) if err != nil { - return nil, err + return nil, model.NewAppError("GetAuthorizedAppsForUser", "app.oauth.get_apps.find.app_error", nil, err.Error(), http.StatusInternalServerError) } for k, a := range apps { @@ -413,7 +472,7 @@ func (a *App) DeauthorizeOAuthAppForUser(userId, appId string) *model.AppError { // Revoke app sessions accessData, err := a.Srv().Store.OAuth().GetAccessDataByUserForApp(userId, appId) if err != nil { - return err + return model.NewAppError("DeauthorizeOAuthAppForUser", "app.oauth.get_access_data_by_user_for_app.app_error", nil, err.Error(), http.StatusInternalServerError) } for _, ad := range accessData { @@ -422,7 +481,7 @@ func (a *App) DeauthorizeOAuthAppForUser(userId, appId string) *model.AppError { } if err := a.Srv().Store.OAuth().RemoveAccessData(ad.Token); err != nil { - return err + return model.NewAppError("DeauthorizeOAuthAppForUser", "app.oauth.remove_access_data.app_error", nil, err.Error(), http.StatusInternalServerError) } } @@ -441,7 +500,16 @@ func (a *App) RegenerateOAuthAppSecret(app *model.OAuthApp) (*model.OAuthApp, *m app.ClientSecret = model.NewId() if _, err := a.Srv().Store.OAuth().UpdateApp(app); err != nil { - return nil, err + var appErr *model.AppError + var invErr *store.ErrInvalidInput + switch { + case errors.As(err, &appErr): + return nil, appErr + case errors.As(err, &invErr): + return nil, model.NewAppError("RegenerateOAuthAppSecret", "app.oauth.update_app.find.app_error", nil, invErr.Error(), http.StatusBadRequest) + default: + return nil, model.NewAppError("RegenerateOAuthAppSecret", "app.oauth.update_app.updating.app_error", nil, err.Error(), http.StatusInternalServerError) + } } return app, nil diff --git a/app/oauth_test.go b/app/oauth_test.go index 5e4fc5e6dd..f69a01aad9 100644 --- a/app/oauth_test.go +++ b/app/oauth_test.go @@ -90,8 +90,8 @@ func TestOAuthRevokeAccessToken(t *testing.T) { accessData.ClientId = model.NewId() accessData.ExpiresAt = session.ExpiresAt - _, err = th.App.Srv().Store.OAuth().SaveAccessData(accessData) - require.Nil(t, err) + _, nErr := th.App.Srv().Store.OAuth().SaveAccessData(accessData) + require.Nil(t, nErr) err = th.App.RevokeAccessToken(accessData.Token) require.Nil(t, err) @@ -130,8 +130,8 @@ func TestOAuthDeleteApp(t *testing.T) { accessData.ClientId = a1.Id accessData.ExpiresAt = session.ExpiresAt - _, err = th.App.Srv().Store.OAuth().SaveAccessData(accessData) - require.Nil(t, err) + _, nErr := th.App.Srv().Store.OAuth().SaveAccessData(accessData) + require.Nil(t, nErr) err = th.App.DeleteOAuthApp(a1.Id) require.Nil(t, err) diff --git a/app/session.go b/app/session.go index cf68577044..d621e44cfd 100644 --- a/app/session.go +++ b/app/session.go @@ -153,9 +153,9 @@ func (a *App) RevokeAllSessions(userId string) *model.AppError { // in the server and revoke them func (a *App) RevokeSessionsFromAllUsers() *model.AppError { // revoke tokens before sessions so they can't be used to relogin - tErr := a.Srv().Store.OAuth().RemoveAllAccessData() - if tErr != nil { - return tErr + nErr := a.Srv().Store.OAuth().RemoveAllAccessData() + if nErr != nil { + return model.NewAppError("RevokeSessionsFromAllUsers", "app.oauth.remove_access_data.app_error", nil, nErr.Error(), http.StatusInternalServerError) } err := a.Srv().Store.Session().RemoveAllSessions() if err != nil { diff --git a/app/user.go b/app/user.go index 5435d042a6..9da2e1ce09 100644 --- a/app/user.go +++ b/app/user.go @@ -1461,7 +1461,7 @@ func (a *App) PermanentDeleteUser(user *model.User) *model.AppError { } if err := a.Srv().Store.OAuth().PermanentDeleteAuthDataByUser(user.Id); err != nil { - return err + return model.NewAppError("PermanentDeleteUser", "app.oauth.permanent_delete_auth_data_by_user.app_error", nil, err.Error(), http.StatusInternalServerError) } if err := a.Srv().Store.Webhook().PermanentDeleteIncomingByUser(user.Id); err != nil { diff --git a/i18n/en.json b/i18n/en.json index a5400dd97c..a503d946d1 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -3850,6 +3850,54 @@ "id": "app.notification.subject.notification.full", "translation": "[{{ .SiteName }}] Notification in {{ .TeamName}} on {{.Month}} {{.Day}}, {{.Year}}" }, + { + "id": "app.oauth.delete_app.app_error", + "translation": "An error occurred while deleting the OAuth2 App." + }, + { + "id": "app.oauth.get_access_data_by_user_for_app.app_error", + "translation": "We encountered an error finding all the access tokens." + }, + { + "id": "app.oauth.get_app.find.app_error", + "translation": "Unable to find the requested app." + }, + { + "id": "app.oauth.get_app.finding.app_error", + "translation": "We encountered an error finding the app." + }, + { + "id": "app.oauth.get_app_by_user.find.app_error", + "translation": "Unable to find any existing apps." + }, + { + "id": "app.oauth.get_apps.find.app_error", + "translation": "An error occurred while finding the OAuth2 Apps." + }, + { + "id": "app.oauth.permanent_delete_auth_data_by_user.app_error", + "translation": "Unable to remove the authorization code." + }, + { + "id": "app.oauth.remove_access_data.app_error", + "translation": "Unable to remove the access token." + }, + { + "id": "app.oauth.save_app.existing.app_error", + "translation": "Must call update for existing app." + }, + { + "id": "app.oauth.save_app.save.app_error", + "translation": "Unable to save the app." + }, + { + "id": "app.oauth.update_app.find.app_error", + "translation": "Unable to find the existing app to update." + }, + { + "id": "app.oauth.update_app.updating.app_error", + "translation": "We encountered an error updating the app." + }, { "id": "app.plugin.cluster.save_config.app_error", "translation": "The plugin configuration in your config.json file must be updated manually when using ReadOnlyConfig with clustering enabled." @@ -6722,102 +6770,6 @@ "id": "store.sql_job.update.app_error", "translation": "Unable to update the job." }, - { - "id": "store.sql_oauth.delete.commit_transaction.app_error", - "translation": "Unable to commit transaction." - }, - { - "id": "store.sql_oauth.delete.open_transaction.app_error", - "translation": "Unable to open transaction to delete the OAuth2 app." - }, - { - "id": "store.sql_oauth.delete_app.app_error", - "translation": "An error occurred while deleting the OAuth2 App." - }, - { - "id": "store.sql_oauth.get_access_data.app_error", - "translation": "We encountered an error finding the access token." - }, - { - "id": "store.sql_oauth.get_access_data_by_user_for_app.app_error", - "translation": "We encountered an error finding all the access tokens." - }, - { - "id": "store.sql_oauth.get_app.find.app_error", - "translation": "Unable to find the requested app." - }, - { - "id": "store.sql_oauth.get_app.finding.app_error", - "translation": "We encountered an error finding the app." - }, - { - "id": "store.sql_oauth.get_app_by_user.find.app_error", - "translation": "Unable to find any existing apps." - }, - { - "id": "store.sql_oauth.get_apps.find.app_error", - "translation": "An error occurred while finding the OAuth2 Apps." - }, - { - "id": "store.sql_oauth.get_auth_data.find.app_error", - "translation": "Unable to find the existing authorization code." - }, - { - "id": "store.sql_oauth.get_auth_data.finding.app_error", - "translation": "We encountered an error finding the authorization code." - }, - { - "id": "store.sql_oauth.get_previous_access_data.app_error", - "translation": "We encountered an error finding the access token." - }, - { - "id": "store.sql_oauth.permanent_delete_auth_data_by_user.app_error", - "translation": "Unable to remove the authorization code." - }, - { - "id": "store.sql_oauth.remove_access_data.app_error", - "translation": "Unable to remove the access token." - }, - { - "id": "store.sql_oauth.remove_auth_data.app_error", - "translation": "Unable to remove the authorization code." - }, - { - "id": "store.sql_oauth.save_access_data.app_error", - "translation": "Unable to save the access token." - }, - { - "id": "store.sql_oauth.save_app.existing.app_error", - "translation": "Must call update for existing app." - }, - { - "id": "store.sql_oauth.save_app.save.app_error", - "translation": "Unable to save the app." - }, - { - "id": "store.sql_oauth.save_auth_data.app_error", - "translation": "Unable to save the authorization code." - }, - { - "id": "store.sql_oauth.update_access_data.app_error", - "translation": "We encountered an error updating the access token." - }, - { - "id": "store.sql_oauth.update_app.find.app_error", - "translation": "Unable to find the existing app to update." - }, - { - "id": "store.sql_oauth.update_app.finding.app_error", - "translation": "We encountered an error finding the app." - }, - { - "id": "store.sql_oauth.update_app.update.app_error", - "translation": "Unable to update the app." - }, - { - "id": "store.sql_oauth.update_app.updating.app_error", - "translation": "We encountered an error updating the app." - }, { "id": "store.sql_plugin_store.compare_and_set.mysql_select.app_error", "translation": "Failed to query for existing row on MySQL after KVCompareAndSet with unchanged value." diff --git a/store/opentracing_layer.go b/store/opentracing_layer.go index 9be368b74a..11c4307774 100644 --- a/store/opentracing_layer.go +++ b/store/opentracing_layer.go @@ -4188,7 +4188,7 @@ func (s *OpenTracingLayerLinkMetadataStore) Save(linkMetadata *model.LinkMetadat return resultVar0, resultVar1 } -func (s *OpenTracingLayerOAuthStore) DeleteApp(id string) *model.AppError { +func (s *OpenTracingLayerOAuthStore) DeleteApp(id string) error { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "OAuthStore.DeleteApp") s.Root.Store.SetContext(newCtx) @@ -4206,7 +4206,7 @@ func (s *OpenTracingLayerOAuthStore) DeleteApp(id string) *model.AppError { return resultVar0 } -func (s *OpenTracingLayerOAuthStore) GetAccessData(token string) (*model.AccessData, *model.AppError) { +func (s *OpenTracingLayerOAuthStore) GetAccessData(token string) (*model.AccessData, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "OAuthStore.GetAccessData") s.Root.Store.SetContext(newCtx) @@ -4224,7 +4224,7 @@ func (s *OpenTracingLayerOAuthStore) GetAccessData(token string) (*model.AccessD return resultVar0, resultVar1 } -func (s *OpenTracingLayerOAuthStore) GetAccessDataByRefreshToken(token string) (*model.AccessData, *model.AppError) { +func (s *OpenTracingLayerOAuthStore) GetAccessDataByRefreshToken(token string) (*model.AccessData, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "OAuthStore.GetAccessDataByRefreshToken") s.Root.Store.SetContext(newCtx) @@ -4242,7 +4242,7 @@ func (s *OpenTracingLayerOAuthStore) GetAccessDataByRefreshToken(token string) ( return resultVar0, resultVar1 } -func (s *OpenTracingLayerOAuthStore) GetAccessDataByUserForApp(userId string, clientId string) ([]*model.AccessData, *model.AppError) { +func (s *OpenTracingLayerOAuthStore) GetAccessDataByUserForApp(userId string, clientId string) ([]*model.AccessData, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "OAuthStore.GetAccessDataByUserForApp") s.Root.Store.SetContext(newCtx) @@ -4260,7 +4260,7 @@ func (s *OpenTracingLayerOAuthStore) GetAccessDataByUserForApp(userId string, cl return resultVar0, resultVar1 } -func (s *OpenTracingLayerOAuthStore) GetApp(id string) (*model.OAuthApp, *model.AppError) { +func (s *OpenTracingLayerOAuthStore) GetApp(id string) (*model.OAuthApp, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "OAuthStore.GetApp") s.Root.Store.SetContext(newCtx) @@ -4278,7 +4278,7 @@ func (s *OpenTracingLayerOAuthStore) GetApp(id string) (*model.OAuthApp, *model. return resultVar0, resultVar1 } -func (s *OpenTracingLayerOAuthStore) GetAppByUser(userId string, offset int, limit int) ([]*model.OAuthApp, *model.AppError) { +func (s *OpenTracingLayerOAuthStore) GetAppByUser(userId string, offset int, limit int) ([]*model.OAuthApp, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "OAuthStore.GetAppByUser") s.Root.Store.SetContext(newCtx) @@ -4296,7 +4296,7 @@ func (s *OpenTracingLayerOAuthStore) GetAppByUser(userId string, offset int, lim return resultVar0, resultVar1 } -func (s *OpenTracingLayerOAuthStore) GetApps(offset int, limit int) ([]*model.OAuthApp, *model.AppError) { +func (s *OpenTracingLayerOAuthStore) GetApps(offset int, limit int) ([]*model.OAuthApp, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "OAuthStore.GetApps") s.Root.Store.SetContext(newCtx) @@ -4314,7 +4314,7 @@ func (s *OpenTracingLayerOAuthStore) GetApps(offset int, limit int) ([]*model.OA return resultVar0, resultVar1 } -func (s *OpenTracingLayerOAuthStore) GetAuthData(code string) (*model.AuthData, *model.AppError) { +func (s *OpenTracingLayerOAuthStore) GetAuthData(code string) (*model.AuthData, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "OAuthStore.GetAuthData") s.Root.Store.SetContext(newCtx) @@ -4332,7 +4332,7 @@ func (s *OpenTracingLayerOAuthStore) GetAuthData(code string) (*model.AuthData, return resultVar0, resultVar1 } -func (s *OpenTracingLayerOAuthStore) GetAuthorizedApps(userId string, offset int, limit int) ([]*model.OAuthApp, *model.AppError) { +func (s *OpenTracingLayerOAuthStore) GetAuthorizedApps(userId string, offset int, limit int) ([]*model.OAuthApp, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "OAuthStore.GetAuthorizedApps") s.Root.Store.SetContext(newCtx) @@ -4350,7 +4350,7 @@ func (s *OpenTracingLayerOAuthStore) GetAuthorizedApps(userId string, offset int return resultVar0, resultVar1 } -func (s *OpenTracingLayerOAuthStore) GetPreviousAccessData(userId string, clientId string) (*model.AccessData, *model.AppError) { +func (s *OpenTracingLayerOAuthStore) GetPreviousAccessData(userId string, clientId string) (*model.AccessData, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "OAuthStore.GetPreviousAccessData") s.Root.Store.SetContext(newCtx) @@ -4368,7 +4368,7 @@ func (s *OpenTracingLayerOAuthStore) GetPreviousAccessData(userId string, client return resultVar0, resultVar1 } -func (s *OpenTracingLayerOAuthStore) PermanentDeleteAuthDataByUser(userId string) *model.AppError { +func (s *OpenTracingLayerOAuthStore) PermanentDeleteAuthDataByUser(userId string) error { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "OAuthStore.PermanentDeleteAuthDataByUser") s.Root.Store.SetContext(newCtx) @@ -4386,7 +4386,7 @@ func (s *OpenTracingLayerOAuthStore) PermanentDeleteAuthDataByUser(userId string return resultVar0 } -func (s *OpenTracingLayerOAuthStore) RemoveAccessData(token string) *model.AppError { +func (s *OpenTracingLayerOAuthStore) RemoveAccessData(token string) error { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "OAuthStore.RemoveAccessData") s.Root.Store.SetContext(newCtx) @@ -4404,7 +4404,7 @@ func (s *OpenTracingLayerOAuthStore) RemoveAccessData(token string) *model.AppEr return resultVar0 } -func (s *OpenTracingLayerOAuthStore) RemoveAllAccessData() *model.AppError { +func (s *OpenTracingLayerOAuthStore) RemoveAllAccessData() error { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "OAuthStore.RemoveAllAccessData") s.Root.Store.SetContext(newCtx) @@ -4422,7 +4422,7 @@ func (s *OpenTracingLayerOAuthStore) RemoveAllAccessData() *model.AppError { return resultVar0 } -func (s *OpenTracingLayerOAuthStore) RemoveAuthData(code string) *model.AppError { +func (s *OpenTracingLayerOAuthStore) RemoveAuthData(code string) error { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "OAuthStore.RemoveAuthData") s.Root.Store.SetContext(newCtx) @@ -4440,7 +4440,7 @@ func (s *OpenTracingLayerOAuthStore) RemoveAuthData(code string) *model.AppError return resultVar0 } -func (s *OpenTracingLayerOAuthStore) SaveAccessData(accessData *model.AccessData) (*model.AccessData, *model.AppError) { +func (s *OpenTracingLayerOAuthStore) SaveAccessData(accessData *model.AccessData) (*model.AccessData, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "OAuthStore.SaveAccessData") s.Root.Store.SetContext(newCtx) @@ -4458,7 +4458,7 @@ func (s *OpenTracingLayerOAuthStore) SaveAccessData(accessData *model.AccessData return resultVar0, resultVar1 } -func (s *OpenTracingLayerOAuthStore) SaveApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppError) { +func (s *OpenTracingLayerOAuthStore) SaveApp(app *model.OAuthApp) (*model.OAuthApp, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "OAuthStore.SaveApp") s.Root.Store.SetContext(newCtx) @@ -4476,7 +4476,7 @@ func (s *OpenTracingLayerOAuthStore) SaveApp(app *model.OAuthApp) (*model.OAuthA return resultVar0, resultVar1 } -func (s *OpenTracingLayerOAuthStore) SaveAuthData(authData *model.AuthData) (*model.AuthData, *model.AppError) { +func (s *OpenTracingLayerOAuthStore) SaveAuthData(authData *model.AuthData) (*model.AuthData, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "OAuthStore.SaveAuthData") s.Root.Store.SetContext(newCtx) @@ -4494,7 +4494,7 @@ func (s *OpenTracingLayerOAuthStore) SaveAuthData(authData *model.AuthData) (*mo return resultVar0, resultVar1 } -func (s *OpenTracingLayerOAuthStore) UpdateAccessData(accessData *model.AccessData) (*model.AccessData, *model.AppError) { +func (s *OpenTracingLayerOAuthStore) UpdateAccessData(accessData *model.AccessData) (*model.AccessData, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "OAuthStore.UpdateAccessData") s.Root.Store.SetContext(newCtx) @@ -4512,7 +4512,7 @@ func (s *OpenTracingLayerOAuthStore) UpdateAccessData(accessData *model.AccessDa return resultVar0, resultVar1 } -func (s *OpenTracingLayerOAuthStore) UpdateApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppError) { +func (s *OpenTracingLayerOAuthStore) UpdateApp(app *model.OAuthApp) (*model.OAuthApp, error) { origCtx := s.Root.Store.Context() span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "OAuthStore.UpdateApp") s.Root.Store.SetContext(newCtx) diff --git a/store/sqlstore/oauth_store.go b/store/sqlstore/oauth_store.go index 1fba08f1f2..f1a4a353b4 100644 --- a/store/sqlstore/oauth_store.go +++ b/store/sqlstore/oauth_store.go @@ -4,12 +4,14 @@ package sqlstore import ( - "net/http" - "strings" + "database/sql" + "fmt" "github.com/mattermost/gorp" "github.com/mattermost/mattermost-server/v5/model" "github.com/mattermost/mattermost-server/v5/store" + + "github.com/pkg/errors" ) type SqlOAuthStore struct { @@ -59,9 +61,9 @@ func (as SqlOAuthStore) createIndexesIfNotExists() { as.CreateIndexIfNotExists("idx_oauthauthdata_client_id", "OAuthAuthData", "Code") } -func (as SqlOAuthStore) SaveApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppError) { +func (as SqlOAuthStore) SaveApp(app *model.OAuthApp) (*model.OAuthApp, error) { if len(app.Id) > 0 { - return nil, model.NewAppError("SqlOAuthStore.SaveApp", "store.sql_oauth.save_app.existing.app_error", nil, "app_id="+app.Id, http.StatusBadRequest) + return nil, store.NewErrInvalidInput("OAuthApp", "Id", app.Id) } app.PreSave() @@ -70,12 +72,12 @@ func (as SqlOAuthStore) SaveApp(app *model.OAuthApp) (*model.OAuthApp, *model.Ap } if err := as.GetMaster().Insert(app); err != nil { - return nil, model.NewAppError("SqlOAuthStore.SaveApp", "store.sql_oauth.save_app.save.app_error", nil, "app_id="+app.Id+", "+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "failed to save OAuthApp") } return app, nil } -func (as SqlOAuthStore) UpdateApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppError) { +func (as SqlOAuthStore) UpdateApp(app *model.OAuthApp) (*model.OAuthApp, error) { app.PreUpdate() if err := app.IsValid(); err != nil { @@ -84,10 +86,10 @@ func (as SqlOAuthStore) UpdateApp(app *model.OAuthApp) (*model.OAuthApp, *model. oldAppResult, err := as.GetMaster().Get(model.OAuthApp{}, app.Id) if err != nil { - return nil, model.NewAppError("SqlOAuthStore.UpdateApp", "store.sql_oauth.update_app.finding.app_error", nil, "app_id="+app.Id+", "+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to get OAuthApp with id=%s", app.Id) } if oldAppResult == nil { - return nil, model.NewAppError("SqlOAuthStore.UpdateApp", "store.sql_oauth.update_app.find.app_error", nil, "app_id="+app.Id, http.StatusBadRequest) + return nil, store.NewErrInvalidInput("OAuthApp", "Id", app.Id) } oldApp := oldAppResult.(*model.OAuthApp) @@ -96,62 +98,62 @@ func (as SqlOAuthStore) UpdateApp(app *model.OAuthApp) (*model.OAuthApp, *model. count, err := as.GetMaster().Update(app) if err != nil { - return nil, model.NewAppError("SqlOAuthStore.UpdateApp", "store.sql_oauth.update_app.updating.app_error", nil, "app_id="+app.Id+", "+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to update OAuthApp with id=%s", app.Id) } if count != 1 { - return nil, model.NewAppError("SqlOAuthStore.UpdateApp", "store.sql_oauth.update_app.update.app_error", nil, "app_id="+app.Id, http.StatusBadRequest) + return nil, store.NewErrInvalidInput("OAuthApp", "Id", app.Id) } return app, nil } -func (as SqlOAuthStore) GetApp(id string) (*model.OAuthApp, *model.AppError) { +func (as SqlOAuthStore) GetApp(id string) (*model.OAuthApp, error) { obj, err := as.GetReplica().Get(model.OAuthApp{}, id) if err != nil { - return nil, model.NewAppError("SqlOAuthStore.GetApp", "store.sql_oauth.get_app.finding.app_error", nil, "app_id="+id+", "+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to get OAuthApp with id=%s", id) } if obj == nil { - return nil, model.NewAppError("SqlOAuthStore.GetApp", "store.sql_oauth.get_app.find.app_error", nil, "app_id="+id, http.StatusNotFound) + return nil, store.NewErrNotFound("OAuthApp", id) } return obj.(*model.OAuthApp), nil } -func (as SqlOAuthStore) GetAppByUser(userId string, offset, limit int) ([]*model.OAuthApp, *model.AppError) { +func (as SqlOAuthStore) GetAppByUser(userId string, offset, limit int) ([]*model.OAuthApp, error) { var apps []*model.OAuthApp if _, err := as.GetReplica().Select(&apps, "SELECT * FROM OAuthApps WHERE CreatorId = :UserId LIMIT :Limit OFFSET :Offset", map[string]interface{}{"UserId": userId, "Offset": offset, "Limit": limit}); err != nil { - return nil, model.NewAppError("SqlOAuthStore.GetAppByUser", "store.sql_oauth.get_app_by_user.find.app_error", nil, "user_id="+userId+", "+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to find OAuthApps with userId=%s", userId) } return apps, nil } -func (as SqlOAuthStore) GetApps(offset, limit int) ([]*model.OAuthApp, *model.AppError) { +func (as SqlOAuthStore) GetApps(offset, limit int) ([]*model.OAuthApp, error) { var apps []*model.OAuthApp if _, err := as.GetReplica().Select(&apps, "SELECT * FROM OAuthApps LIMIT :Limit OFFSET :Offset", map[string]interface{}{"Offset": offset, "Limit": limit}); err != nil { - return nil, model.NewAppError("SqlOAuthStore.GetAppByUser", "store.sql_oauth.get_apps.find.app_error", nil, "err="+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "failed to find OAuthApps") } return apps, nil } -func (as SqlOAuthStore) GetAuthorizedApps(userId string, offset, limit int) ([]*model.OAuthApp, *model.AppError) { +func (as SqlOAuthStore) GetAuthorizedApps(userId string, offset, limit int) ([]*model.OAuthApp, error) { var apps []*model.OAuthApp if _, err := as.GetReplica().Select(&apps, `SELECT o.* FROM OAuthApps AS o INNER JOIN Preferences AS p ON p.Name=o.Id AND p.UserId=:UserId LIMIT :Limit OFFSET :Offset`, map[string]interface{}{"UserId": userId, "Offset": offset, "Limit": limit}); err != nil { - return nil, model.NewAppError("SqlOAuthStore.GetAuthorizedApps", "store.sql_oauth.get_apps.find.app_error", nil, "err="+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to find OAuthApps with userId=%s", userId) } return apps, nil } -func (as SqlOAuthStore) DeleteApp(id string) *model.AppError { +func (as SqlOAuthStore) DeleteApp(id string) error { // wrap in a transaction so that if one fails, everything fails transaction, err := as.GetMaster().Begin() if err != nil { - return model.NewAppError("SqlOAuthStore.DeleteApp", "store.sql_oauth.delete.open_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) + return errors.Wrap(err, "begin_transaction") } defer finalizeTransaction(transaction) @@ -161,139 +163,139 @@ func (as SqlOAuthStore) DeleteApp(id string) *model.AppError { if err := transaction.Commit(); err != nil { // don't need to rollback here since the transaction is already closed - return model.NewAppError("SqlOAuthStore.DeleteApp", "store.sql_oauth.delete.commit_transaction.app_error", nil, err.Error(), http.StatusInternalServerError) + return errors.Wrap(err, "commit_transaction") } return nil } -func (as SqlOAuthStore) SaveAccessData(accessData *model.AccessData) (*model.AccessData, *model.AppError) { +func (as SqlOAuthStore) SaveAccessData(accessData *model.AccessData) (*model.AccessData, error) { if err := accessData.IsValid(); err != nil { return nil, err } if err := as.GetMaster().Insert(accessData); err != nil { - return nil, model.NewAppError("SqlOAuthStore.SaveAccessData", "store.sql_oauth.save_access_data.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "failed to save AccessData") } return accessData, nil } -func (as SqlOAuthStore) GetAccessData(token string) (*model.AccessData, *model.AppError) { +func (as SqlOAuthStore) GetAccessData(token string) (*model.AccessData, error) { accessData := model.AccessData{} if err := as.GetReplica().SelectOne(&accessData, "SELECT * FROM OAuthAccessData WHERE Token = :Token", map[string]interface{}{"Token": token}); err != nil { - return nil, model.NewAppError("SqlOAuthStore.GetAccessData", "store.sql_oauth.get_access_data.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to get OAuthAccessData with token=%s", token) } return &accessData, nil } -func (as SqlOAuthStore) GetAccessDataByUserForApp(userId, clientId string) ([]*model.AccessData, *model.AppError) { +func (as SqlOAuthStore) GetAccessDataByUserForApp(userId, clientId string) ([]*model.AccessData, error) { var accessData []*model.AccessData if _, err := as.GetReplica().Select(&accessData, "SELECT * FROM OAuthAccessData WHERE UserId = :UserId AND ClientId = :ClientId", map[string]interface{}{"UserId": userId, "ClientId": clientId}); err != nil { - return nil, model.NewAppError("SqlOAuthStore.GetAccessDataByUserForApp", "store.sql_oauth.get_access_data_by_user_for_app.app_error", nil, "user_id="+userId+" client_id="+clientId, http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to delete OAuthAccessData with userId=%s and clientId=%s", userId, clientId) } return accessData, nil } -func (as SqlOAuthStore) GetAccessDataByRefreshToken(token string) (*model.AccessData, *model.AppError) { +func (as SqlOAuthStore) GetAccessDataByRefreshToken(token string) (*model.AccessData, error) { accessData := model.AccessData{} if err := as.GetReplica().SelectOne(&accessData, "SELECT * FROM OAuthAccessData WHERE RefreshToken = :Token", map[string]interface{}{"Token": token}); err != nil { - return nil, model.NewAppError("SqlOAuthStore.GetAccessData", "store.sql_oauth.get_access_data.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to find OAuthAccessData with refreshToken=%s", token) } return &accessData, nil } -func (as SqlOAuthStore) GetPreviousAccessData(userId, clientId string) (*model.AccessData, *model.AppError) { +func (as SqlOAuthStore) GetPreviousAccessData(userId, clientId string) (*model.AccessData, error) { accessData := model.AccessData{} if err := as.GetReplica().SelectOne(&accessData, "SELECT * FROM OAuthAccessData WHERE ClientId = :ClientId AND UserId = :UserId", map[string]interface{}{"ClientId": clientId, "UserId": userId}); err != nil { - if strings.Contains(err.Error(), "no rows") { + if err == sql.ErrNoRows { return nil, nil } - return nil, model.NewAppError("SqlOAuthStore.GetPreviousAccessData", "store.sql_oauth.get_previous_access_data.app_error", nil, err.Error(), http.StatusNotFound) + + return nil, errors.Wrapf(err, "failed to get AccessData with clientId=%s and userId=%s", clientId, userId) } return &accessData, nil } -func (as SqlOAuthStore) UpdateAccessData(accessData *model.AccessData) (*model.AccessData, *model.AppError) { +func (as SqlOAuthStore) UpdateAccessData(accessData *model.AccessData) (*model.AccessData, error) { if err := accessData.IsValid(); err != nil { return nil, err } if _, err := as.GetMaster().Exec("UPDATE OAuthAccessData SET Token = :Token, ExpiresAt = :ExpiresAt, RefreshToken = :RefreshToken WHERE ClientId = :ClientId AND UserID = :UserId", map[string]interface{}{"Token": accessData.Token, "ExpiresAt": accessData.ExpiresAt, "RefreshToken": accessData.RefreshToken, "ClientId": accessData.ClientId, "UserId": accessData.UserId}); err != nil { - return nil, model.NewAppError("SqlOAuthStore.Update", "store.sql_oauth.update_access_data.app_error", nil, - "clientId="+accessData.ClientId+",userId="+accessData.UserId+", "+err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to update OAuthAccessData with userId=%s and clientId=%s", accessData.UserId, accessData.ClientId) } return accessData, nil } -func (as SqlOAuthStore) RemoveAccessData(token string) *model.AppError { +func (as SqlOAuthStore) RemoveAccessData(token string) error { if _, err := as.GetMaster().Exec("DELETE FROM OAuthAccessData WHERE Token = :Token", map[string]interface{}{"Token": token}); err != nil { - return model.NewAppError("SqlOAuthStore.RemoveAccessData", "store.sql_oauth.remove_access_data.app_error", nil, "err="+err.Error(), http.StatusInternalServerError) + return errors.Wrapf(err, "failed to delete OAuthAccessData with token=%s", token) } return nil } -func (as SqlOAuthStore) RemoveAllAccessData() *model.AppError { +func (as SqlOAuthStore) RemoveAllAccessData() error { if _, err := as.GetMaster().Exec("DELETE FROM OAuthAccessData", map[string]interface{}{}); err != nil { - return model.NewAppError("SqlOAuthStore.RemoveAccessData", "store.sql_oauth.remove_access_data.app_error", nil, "err="+err.Error(), http.StatusInternalServerError) + return errors.Wrap(err, "failed to delete OAuthAccessData") } return nil } -func (as SqlOAuthStore) SaveAuthData(authData *model.AuthData) (*model.AuthData, *model.AppError) { +func (as SqlOAuthStore) SaveAuthData(authData *model.AuthData) (*model.AuthData, error) { authData.PreSave() if err := authData.IsValid(); err != nil { return nil, err } if err := as.GetMaster().Insert(authData); err != nil { - return nil, model.NewAppError("SqlOAuthStore.SaveAuthData", "store.sql_oauth.save_auth_data.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrap(err, "failed to save AuthData") } return authData, nil } -func (as SqlOAuthStore) GetAuthData(code string) (*model.AuthData, *model.AppError) { +func (as SqlOAuthStore) GetAuthData(code string) (*model.AuthData, error) { obj, err := as.GetReplica().Get(model.AuthData{}, code) if err != nil { - return nil, model.NewAppError("SqlOAuthStore.GetAuthData", "store.sql_oauth.get_auth_data.finding.app_error", nil, err.Error(), http.StatusInternalServerError) + return nil, errors.Wrapf(err, "failed to get AuthData with code=%s", code) } if obj == nil { - return nil, model.NewAppError("SqlOAuthStore.GetAuthData", "store.sql_oauth.get_auth_data.find.app_error", nil, "", http.StatusNotFound) + return nil, store.NewErrNotFound("AuthData", fmt.Sprintf("code=%s", code)) } return obj.(*model.AuthData), nil } -func (as SqlOAuthStore) RemoveAuthData(code string) *model.AppError { +func (as SqlOAuthStore) RemoveAuthData(code string) error { _, err := as.GetMaster().Exec("DELETE FROM OAuthAuthData WHERE Code = :Code", map[string]interface{}{"Code": code}) if err != nil { - return model.NewAppError("SqlOAuthStore.RemoveAuthData", "store.sql_oauth.remove_auth_data.app_error", nil, "err="+err.Error(), http.StatusInternalServerError) + return errors.Wrapf(err, "failed to delete AuthData with code=%s", code) } return nil } -func (as SqlOAuthStore) PermanentDeleteAuthDataByUser(userId string) *model.AppError { +func (as SqlOAuthStore) PermanentDeleteAuthDataByUser(userId string) error { _, err := as.GetMaster().Exec("DELETE FROM OAuthAccessData WHERE UserId = :UserId", map[string]interface{}{"UserId": userId}) if err != nil { - return model.NewAppError("SqlOAuthStore.RemoveAuthDataByUserId", "store.sql_oauth.permanent_delete_auth_data_by_user.app_error", nil, "err="+err.Error(), http.StatusInternalServerError) + return errors.Wrapf(err, "failed to delete OAuthAccessData with userId=%s", userId) } return nil } -func (as SqlOAuthStore) deleteApp(transaction *gorp.Transaction, clientId string) *model.AppError { +func (as SqlOAuthStore) deleteApp(transaction *gorp.Transaction, clientId string) error { if _, err := transaction.Exec("DELETE FROM OAuthApps WHERE Id = :Id", map[string]interface{}{"Id": clientId}); err != nil { - return model.NewAppError("SqlOAuthStore.DeleteApp", "store.sql_oauth.delete_app.app_error", nil, "id="+clientId+", err="+err.Error(), http.StatusInternalServerError) + return errors.Wrapf(err, "failed to delete OAuthApp with id=%s", clientId) } return as.deleteOAuthAppSessions(transaction, clientId) } -func (as SqlOAuthStore) deleteOAuthAppSessions(transaction *gorp.Transaction, clientId string) *model.AppError { +func (as SqlOAuthStore) deleteOAuthAppSessions(transaction *gorp.Transaction, clientId string) error { query := "" if as.DriverName() == model.DATABASE_DRIVER_POSTGRES { @@ -303,28 +305,28 @@ func (as SqlOAuthStore) deleteOAuthAppSessions(transaction *gorp.Transaction, cl } if _, err := transaction.Exec(query, map[string]interface{}{"Id": clientId}); err != nil { - return model.NewAppError("SqlOAuthStore.DeleteApp", "store.sql_oauth.delete_app.app_error", nil, "id="+clientId+", err="+err.Error(), http.StatusInternalServerError) + return errors.Wrapf(err, "failed to delete Session with OAuthAccessData.Id=%s", clientId) } return as.deleteOAuthTokens(transaction, clientId) } -func (as SqlOAuthStore) deleteOAuthTokens(transaction *gorp.Transaction, clientId string) *model.AppError { +func (as SqlOAuthStore) deleteOAuthTokens(transaction *gorp.Transaction, clientId string) error { if _, err := transaction.Exec("DELETE FROM OAuthAccessData WHERE ClientId = :Id", map[string]interface{}{"Id": clientId}); err != nil { - return model.NewAppError("SqlOAuthStore.DeleteApp", "store.sql_oauth.delete_app.app_error", nil, "id="+clientId+", err="+err.Error(), http.StatusInternalServerError) + return errors.Wrapf(err, "failed to delete OAuthAccessData with id=%s", clientId) } return as.deleteAppExtras(transaction, clientId) } -func (as SqlOAuthStore) deleteAppExtras(transaction *gorp.Transaction, clientId string) *model.AppError { +func (as SqlOAuthStore) deleteAppExtras(transaction *gorp.Transaction, clientId string) error { if _, err := transaction.Exec( `DELETE FROM Preferences WHERE Category = :Category AND Name = :Name`, map[string]interface{}{"Category": model.PREFERENCE_CATEGORY_AUTHORIZED_OAUTH_APP, "Name": clientId}); err != nil { - return model.NewAppError("SqlOAuthStore.DeleteApp", "store.sql_preference.delete.app_error", nil, err.Error(), http.StatusInternalServerError) + return errors.Wrapf(err, "failed to delete Preferences with name=%s", clientId) } return nil diff --git a/store/store.go b/store/store.go index 1e7c4a29cc..06e6bc0d80 100644 --- a/store/store.go +++ b/store/store.go @@ -412,25 +412,25 @@ type ComplianceStore interface { } type OAuthStore interface { - SaveApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppError) - UpdateApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppError) - GetApp(id string) (*model.OAuthApp, *model.AppError) - GetAppByUser(userId string, offset, limit int) ([]*model.OAuthApp, *model.AppError) - GetApps(offset, limit int) ([]*model.OAuthApp, *model.AppError) - GetAuthorizedApps(userId string, offset, limit int) ([]*model.OAuthApp, *model.AppError) - DeleteApp(id string) *model.AppError - SaveAuthData(authData *model.AuthData) (*model.AuthData, *model.AppError) - GetAuthData(code string) (*model.AuthData, *model.AppError) - RemoveAuthData(code string) *model.AppError - PermanentDeleteAuthDataByUser(userId string) *model.AppError - SaveAccessData(accessData *model.AccessData) (*model.AccessData, *model.AppError) - UpdateAccessData(accessData *model.AccessData) (*model.AccessData, *model.AppError) - GetAccessData(token string) (*model.AccessData, *model.AppError) - GetAccessDataByUserForApp(userId, clientId string) ([]*model.AccessData, *model.AppError) - GetAccessDataByRefreshToken(token string) (*model.AccessData, *model.AppError) - GetPreviousAccessData(userId, clientId string) (*model.AccessData, *model.AppError) - RemoveAccessData(token string) *model.AppError - RemoveAllAccessData() *model.AppError + SaveApp(app *model.OAuthApp) (*model.OAuthApp, error) + UpdateApp(app *model.OAuthApp) (*model.OAuthApp, error) + GetApp(id string) (*model.OAuthApp, error) + GetAppByUser(userId string, offset, limit int) ([]*model.OAuthApp, error) + GetApps(offset, limit int) ([]*model.OAuthApp, error) + GetAuthorizedApps(userId string, offset, limit int) ([]*model.OAuthApp, error) + DeleteApp(id string) error + SaveAuthData(authData *model.AuthData) (*model.AuthData, error) + GetAuthData(code string) (*model.AuthData, error) + RemoveAuthData(code string) error + PermanentDeleteAuthDataByUser(userId string) error + SaveAccessData(accessData *model.AccessData) (*model.AccessData, error) + UpdateAccessData(accessData *model.AccessData) (*model.AccessData, error) + GetAccessData(token string) (*model.AccessData, error) + GetAccessDataByUserForApp(userId, clientId string) ([]*model.AccessData, error) + GetAccessDataByRefreshToken(token string) (*model.AccessData, error) + GetPreviousAccessData(userId, clientId string) (*model.AccessData, error) + RemoveAccessData(token string) error + RemoveAllAccessData() error } type SystemStore interface { diff --git a/store/storetest/mocks/OAuthStore.go b/store/storetest/mocks/OAuthStore.go index a568a2a88a..92fe7ddcb9 100644 --- a/store/storetest/mocks/OAuthStore.go +++ b/store/storetest/mocks/OAuthStore.go @@ -15,23 +15,21 @@ type OAuthStore struct { } // DeleteApp provides a mock function with given fields: id -func (_m *OAuthStore) DeleteApp(id string) *model.AppError { +func (_m *OAuthStore) DeleteApp(id string) error { ret := _m.Called(id) - var r0 *model.AppError - if rf, ok := ret.Get(0).(func(string) *model.AppError); ok { + var r0 error + if rf, ok := ret.Get(0).(func(string) error); ok { r0 = rf(id) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.AppError) - } + r0 = ret.Error(0) } return r0 } // GetAccessData provides a mock function with given fields: token -func (_m *OAuthStore) GetAccessData(token string) (*model.AccessData, *model.AppError) { +func (_m *OAuthStore) GetAccessData(token string) (*model.AccessData, error) { ret := _m.Called(token) var r0 *model.AccessData @@ -43,20 +41,18 @@ func (_m *OAuthStore) GetAccessData(token string) (*model.AccessData, *model.App } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(token) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetAccessDataByRefreshToken provides a mock function with given fields: token -func (_m *OAuthStore) GetAccessDataByRefreshToken(token string) (*model.AccessData, *model.AppError) { +func (_m *OAuthStore) GetAccessDataByRefreshToken(token string) (*model.AccessData, error) { ret := _m.Called(token) var r0 *model.AccessData @@ -68,20 +64,18 @@ func (_m *OAuthStore) GetAccessDataByRefreshToken(token string) (*model.AccessDa } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(token) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetAccessDataByUserForApp provides a mock function with given fields: userId, clientId -func (_m *OAuthStore) GetAccessDataByUserForApp(userId string, clientId string) ([]*model.AccessData, *model.AppError) { +func (_m *OAuthStore) GetAccessDataByUserForApp(userId string, clientId string) ([]*model.AccessData, error) { ret := _m.Called(userId, clientId) var r0 []*model.AccessData @@ -93,20 +87,18 @@ func (_m *OAuthStore) GetAccessDataByUserForApp(userId string, clientId string) } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, string) error); ok { r1 = rf(userId, clientId) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetApp provides a mock function with given fields: id -func (_m *OAuthStore) GetApp(id string) (*model.OAuthApp, *model.AppError) { +func (_m *OAuthStore) GetApp(id string) (*model.OAuthApp, error) { ret := _m.Called(id) var r0 *model.OAuthApp @@ -118,20 +110,18 @@ func (_m *OAuthStore) GetApp(id string) (*model.OAuthApp, *model.AppError) { } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(id) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetAppByUser provides a mock function with given fields: userId, offset, limit -func (_m *OAuthStore) GetAppByUser(userId string, offset int, limit int) ([]*model.OAuthApp, *model.AppError) { +func (_m *OAuthStore) GetAppByUser(userId string, offset int, limit int) ([]*model.OAuthApp, error) { ret := _m.Called(userId, offset, limit) var r0 []*model.OAuthApp @@ -143,20 +133,18 @@ func (_m *OAuthStore) GetAppByUser(userId string, offset int, limit int) ([]*mod } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, int, int) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, int, int) error); ok { r1 = rf(userId, offset, limit) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetApps provides a mock function with given fields: offset, limit -func (_m *OAuthStore) GetApps(offset int, limit int) ([]*model.OAuthApp, *model.AppError) { +func (_m *OAuthStore) GetApps(offset int, limit int) ([]*model.OAuthApp, error) { ret := _m.Called(offset, limit) var r0 []*model.OAuthApp @@ -168,20 +156,18 @@ func (_m *OAuthStore) GetApps(offset int, limit int) ([]*model.OAuthApp, *model. } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(int, int) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(int, int) error); ok { r1 = rf(offset, limit) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetAuthData provides a mock function with given fields: code -func (_m *OAuthStore) GetAuthData(code string) (*model.AuthData, *model.AppError) { +func (_m *OAuthStore) GetAuthData(code string) (*model.AuthData, error) { ret := _m.Called(code) var r0 *model.AuthData @@ -193,20 +179,18 @@ func (_m *OAuthStore) GetAuthData(code string) (*model.AuthData, *model.AppError } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string) error); ok { r1 = rf(code) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetAuthorizedApps provides a mock function with given fields: userId, offset, limit -func (_m *OAuthStore) GetAuthorizedApps(userId string, offset int, limit int) ([]*model.OAuthApp, *model.AppError) { +func (_m *OAuthStore) GetAuthorizedApps(userId string, offset int, limit int) ([]*model.OAuthApp, error) { ret := _m.Called(userId, offset, limit) var r0 []*model.OAuthApp @@ -218,20 +202,18 @@ func (_m *OAuthStore) GetAuthorizedApps(userId string, offset int, limit int) ([ } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, int, int) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, int, int) error); ok { r1 = rf(userId, offset, limit) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // GetPreviousAccessData provides a mock function with given fields: userId, clientId -func (_m *OAuthStore) GetPreviousAccessData(userId string, clientId string) (*model.AccessData, *model.AppError) { +func (_m *OAuthStore) GetPreviousAccessData(userId string, clientId string) (*model.AccessData, error) { ret := _m.Called(userId, clientId) var r0 *model.AccessData @@ -243,84 +225,74 @@ func (_m *OAuthStore) GetPreviousAccessData(userId string, clientId string) (*mo } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(string, string) error); ok { r1 = rf(userId, clientId) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // PermanentDeleteAuthDataByUser provides a mock function with given fields: userId -func (_m *OAuthStore) PermanentDeleteAuthDataByUser(userId string) *model.AppError { +func (_m *OAuthStore) PermanentDeleteAuthDataByUser(userId string) error { ret := _m.Called(userId) - var r0 *model.AppError - if rf, ok := ret.Get(0).(func(string) *model.AppError); ok { + var r0 error + if rf, ok := ret.Get(0).(func(string) error); ok { r0 = rf(userId) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.AppError) - } + r0 = ret.Error(0) } return r0 } // RemoveAccessData provides a mock function with given fields: token -func (_m *OAuthStore) RemoveAccessData(token string) *model.AppError { +func (_m *OAuthStore) RemoveAccessData(token string) error { ret := _m.Called(token) - var r0 *model.AppError - if rf, ok := ret.Get(0).(func(string) *model.AppError); ok { + var r0 error + if rf, ok := ret.Get(0).(func(string) error); ok { r0 = rf(token) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.AppError) - } + r0 = ret.Error(0) } return r0 } // RemoveAllAccessData provides a mock function with given fields: -func (_m *OAuthStore) RemoveAllAccessData() *model.AppError { +func (_m *OAuthStore) RemoveAllAccessData() error { ret := _m.Called() - var r0 *model.AppError - if rf, ok := ret.Get(0).(func() *model.AppError); ok { + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { r0 = rf() } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.AppError) - } + r0 = ret.Error(0) } return r0 } // RemoveAuthData provides a mock function with given fields: code -func (_m *OAuthStore) RemoveAuthData(code string) *model.AppError { +func (_m *OAuthStore) RemoveAuthData(code string) error { ret := _m.Called(code) - var r0 *model.AppError - if rf, ok := ret.Get(0).(func(string) *model.AppError); ok { + var r0 error + if rf, ok := ret.Get(0).(func(string) error); ok { r0 = rf(code) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*model.AppError) - } + r0 = ret.Error(0) } return r0 } // SaveAccessData provides a mock function with given fields: accessData -func (_m *OAuthStore) SaveAccessData(accessData *model.AccessData) (*model.AccessData, *model.AppError) { +func (_m *OAuthStore) SaveAccessData(accessData *model.AccessData) (*model.AccessData, error) { ret := _m.Called(accessData) var r0 *model.AccessData @@ -332,20 +304,18 @@ func (_m *OAuthStore) SaveAccessData(accessData *model.AccessData) (*model.Acces } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(*model.AccessData) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(*model.AccessData) error); ok { r1 = rf(accessData) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // SaveApp provides a mock function with given fields: app -func (_m *OAuthStore) SaveApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppError) { +func (_m *OAuthStore) SaveApp(app *model.OAuthApp) (*model.OAuthApp, error) { ret := _m.Called(app) var r0 *model.OAuthApp @@ -357,20 +327,18 @@ func (_m *OAuthStore) SaveApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppE } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(*model.OAuthApp) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(*model.OAuthApp) error); ok { r1 = rf(app) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // SaveAuthData provides a mock function with given fields: authData -func (_m *OAuthStore) SaveAuthData(authData *model.AuthData) (*model.AuthData, *model.AppError) { +func (_m *OAuthStore) SaveAuthData(authData *model.AuthData) (*model.AuthData, error) { ret := _m.Called(authData) var r0 *model.AuthData @@ -382,20 +350,18 @@ func (_m *OAuthStore) SaveAuthData(authData *model.AuthData) (*model.AuthData, * } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(*model.AuthData) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(*model.AuthData) error); ok { r1 = rf(authData) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // UpdateAccessData provides a mock function with given fields: accessData -func (_m *OAuthStore) UpdateAccessData(accessData *model.AccessData) (*model.AccessData, *model.AppError) { +func (_m *OAuthStore) UpdateAccessData(accessData *model.AccessData) (*model.AccessData, error) { ret := _m.Called(accessData) var r0 *model.AccessData @@ -407,20 +373,18 @@ func (_m *OAuthStore) UpdateAccessData(accessData *model.AccessData) (*model.Acc } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(*model.AccessData) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(*model.AccessData) error); ok { r1 = rf(accessData) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 } // UpdateApp provides a mock function with given fields: app -func (_m *OAuthStore) UpdateApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppError) { +func (_m *OAuthStore) UpdateApp(app *model.OAuthApp) (*model.OAuthApp, error) { ret := _m.Called(app) var r0 *model.OAuthApp @@ -432,13 +396,11 @@ func (_m *OAuthStore) UpdateApp(app *model.OAuthApp) (*model.OAuthApp, *model.Ap } } - var r1 *model.AppError - if rf, ok := ret.Get(1).(func(*model.OAuthApp) *model.AppError); ok { + var r1 error + if rf, ok := ret.Get(1).(func(*model.OAuthApp) error); ok { r1 = rf(app) } else { - if ret.Get(1) != nil { - r1 = ret.Get(1).(*model.AppError) - } + r1 = ret.Error(1) } return r0, r1 diff --git a/store/storetest/oauth_store.go b/store/storetest/oauth_store.go index 19d4c23fb1..0dc9c239f4 100644 --- a/store/storetest/oauth_store.go +++ b/store/storetest/oauth_store.go @@ -20,6 +20,7 @@ func TestOAuthStore(t *testing.T, ss store.Store) { t.Run("OAuthUpdateAccessData", func(t *testing.T) { testOAuthUpdateAccessData(t, ss) }) t.Run("GetAccessData", func(t *testing.T) { testOAuthStoreGetAccessData(t, ss) }) t.Run("RemoveAccessData", func(t *testing.T) { testOAuthStoreRemoveAccessData(t, ss) }) + t.Run("RemoveAllAccessData", func(t *testing.T) { testOAuthStoreRemoveAllAccessData(t, ss) }) t.Run("SaveAuthData", func(t *testing.T) { testOAuthStoreSaveAuthData(t, ss) }) t.Run("GetAuthData", func(t *testing.T) { testOAuthStoreGetAuthData(t, ss) }) t.Run("RemoveAuthData", func(t *testing.T) { testOAuthStoreRemoveAuthData(t, ss) }) @@ -213,7 +214,7 @@ func testOAuthStoreRemoveAccessData(t *testing.T, ss store.Store) { require.Nil(t, result, "did not delete access token") } -func TestOAuthStoreRemoveAllAccessData(t *testing.T, ss store.Store) { +func testOAuthStoreRemoveAllAccessData(t *testing.T, ss store.Store) { a1 := model.AccessData{} a1.ClientId = model.NewId() a1.UserId = model.NewId() diff --git a/store/timer_layer.go b/store/timer_layer.go index d58ae07c43..710ff221ec 100644 --- a/store/timer_layer.go +++ b/store/timer_layer.go @@ -3806,7 +3806,7 @@ func (s *TimerLayerLinkMetadataStore) Save(linkMetadata *model.LinkMetadata) (*m return resultVar0, resultVar1 } -func (s *TimerLayerOAuthStore) DeleteApp(id string) *model.AppError { +func (s *TimerLayerOAuthStore) DeleteApp(id string) error { start := timemodule.Now() resultVar0 := s.OAuthStore.DeleteApp(id) @@ -3822,7 +3822,7 @@ func (s *TimerLayerOAuthStore) DeleteApp(id string) *model.AppError { return resultVar0 } -func (s *TimerLayerOAuthStore) GetAccessData(token string) (*model.AccessData, *model.AppError) { +func (s *TimerLayerOAuthStore) GetAccessData(token string) (*model.AccessData, error) { start := timemodule.Now() resultVar0, resultVar1 := s.OAuthStore.GetAccessData(token) @@ -3838,7 +3838,7 @@ func (s *TimerLayerOAuthStore) GetAccessData(token string) (*model.AccessData, * return resultVar0, resultVar1 } -func (s *TimerLayerOAuthStore) GetAccessDataByRefreshToken(token string) (*model.AccessData, *model.AppError) { +func (s *TimerLayerOAuthStore) GetAccessDataByRefreshToken(token string) (*model.AccessData, error) { start := timemodule.Now() resultVar0, resultVar1 := s.OAuthStore.GetAccessDataByRefreshToken(token) @@ -3854,7 +3854,7 @@ func (s *TimerLayerOAuthStore) GetAccessDataByRefreshToken(token string) (*model return resultVar0, resultVar1 } -func (s *TimerLayerOAuthStore) GetAccessDataByUserForApp(userId string, clientId string) ([]*model.AccessData, *model.AppError) { +func (s *TimerLayerOAuthStore) GetAccessDataByUserForApp(userId string, clientId string) ([]*model.AccessData, error) { start := timemodule.Now() resultVar0, resultVar1 := s.OAuthStore.GetAccessDataByUserForApp(userId, clientId) @@ -3870,7 +3870,7 @@ func (s *TimerLayerOAuthStore) GetAccessDataByUserForApp(userId string, clientId return resultVar0, resultVar1 } -func (s *TimerLayerOAuthStore) GetApp(id string) (*model.OAuthApp, *model.AppError) { +func (s *TimerLayerOAuthStore) GetApp(id string) (*model.OAuthApp, error) { start := timemodule.Now() resultVar0, resultVar1 := s.OAuthStore.GetApp(id) @@ -3886,7 +3886,7 @@ func (s *TimerLayerOAuthStore) GetApp(id string) (*model.OAuthApp, *model.AppErr return resultVar0, resultVar1 } -func (s *TimerLayerOAuthStore) GetAppByUser(userId string, offset int, limit int) ([]*model.OAuthApp, *model.AppError) { +func (s *TimerLayerOAuthStore) GetAppByUser(userId string, offset int, limit int) ([]*model.OAuthApp, error) { start := timemodule.Now() resultVar0, resultVar1 := s.OAuthStore.GetAppByUser(userId, offset, limit) @@ -3902,7 +3902,7 @@ func (s *TimerLayerOAuthStore) GetAppByUser(userId string, offset int, limit int return resultVar0, resultVar1 } -func (s *TimerLayerOAuthStore) GetApps(offset int, limit int) ([]*model.OAuthApp, *model.AppError) { +func (s *TimerLayerOAuthStore) GetApps(offset int, limit int) ([]*model.OAuthApp, error) { start := timemodule.Now() resultVar0, resultVar1 := s.OAuthStore.GetApps(offset, limit) @@ -3918,7 +3918,7 @@ func (s *TimerLayerOAuthStore) GetApps(offset int, limit int) ([]*model.OAuthApp return resultVar0, resultVar1 } -func (s *TimerLayerOAuthStore) GetAuthData(code string) (*model.AuthData, *model.AppError) { +func (s *TimerLayerOAuthStore) GetAuthData(code string) (*model.AuthData, error) { start := timemodule.Now() resultVar0, resultVar1 := s.OAuthStore.GetAuthData(code) @@ -3934,7 +3934,7 @@ func (s *TimerLayerOAuthStore) GetAuthData(code string) (*model.AuthData, *model return resultVar0, resultVar1 } -func (s *TimerLayerOAuthStore) GetAuthorizedApps(userId string, offset int, limit int) ([]*model.OAuthApp, *model.AppError) { +func (s *TimerLayerOAuthStore) GetAuthorizedApps(userId string, offset int, limit int) ([]*model.OAuthApp, error) { start := timemodule.Now() resultVar0, resultVar1 := s.OAuthStore.GetAuthorizedApps(userId, offset, limit) @@ -3950,7 +3950,7 @@ func (s *TimerLayerOAuthStore) GetAuthorizedApps(userId string, offset int, limi return resultVar0, resultVar1 } -func (s *TimerLayerOAuthStore) GetPreviousAccessData(userId string, clientId string) (*model.AccessData, *model.AppError) { +func (s *TimerLayerOAuthStore) GetPreviousAccessData(userId string, clientId string) (*model.AccessData, error) { start := timemodule.Now() resultVar0, resultVar1 := s.OAuthStore.GetPreviousAccessData(userId, clientId) @@ -3966,7 +3966,7 @@ func (s *TimerLayerOAuthStore) GetPreviousAccessData(userId string, clientId str return resultVar0, resultVar1 } -func (s *TimerLayerOAuthStore) PermanentDeleteAuthDataByUser(userId string) *model.AppError { +func (s *TimerLayerOAuthStore) PermanentDeleteAuthDataByUser(userId string) error { start := timemodule.Now() resultVar0 := s.OAuthStore.PermanentDeleteAuthDataByUser(userId) @@ -3982,7 +3982,7 @@ func (s *TimerLayerOAuthStore) PermanentDeleteAuthDataByUser(userId string) *mod return resultVar0 } -func (s *TimerLayerOAuthStore) RemoveAccessData(token string) *model.AppError { +func (s *TimerLayerOAuthStore) RemoveAccessData(token string) error { start := timemodule.Now() resultVar0 := s.OAuthStore.RemoveAccessData(token) @@ -3998,7 +3998,7 @@ func (s *TimerLayerOAuthStore) RemoveAccessData(token string) *model.AppError { return resultVar0 } -func (s *TimerLayerOAuthStore) RemoveAllAccessData() *model.AppError { +func (s *TimerLayerOAuthStore) RemoveAllAccessData() error { start := timemodule.Now() resultVar0 := s.OAuthStore.RemoveAllAccessData() @@ -4014,7 +4014,7 @@ func (s *TimerLayerOAuthStore) RemoveAllAccessData() *model.AppError { return resultVar0 } -func (s *TimerLayerOAuthStore) RemoveAuthData(code string) *model.AppError { +func (s *TimerLayerOAuthStore) RemoveAuthData(code string) error { start := timemodule.Now() resultVar0 := s.OAuthStore.RemoveAuthData(code) @@ -4030,7 +4030,7 @@ func (s *TimerLayerOAuthStore) RemoveAuthData(code string) *model.AppError { return resultVar0 } -func (s *TimerLayerOAuthStore) SaveAccessData(accessData *model.AccessData) (*model.AccessData, *model.AppError) { +func (s *TimerLayerOAuthStore) SaveAccessData(accessData *model.AccessData) (*model.AccessData, error) { start := timemodule.Now() resultVar0, resultVar1 := s.OAuthStore.SaveAccessData(accessData) @@ -4046,7 +4046,7 @@ func (s *TimerLayerOAuthStore) SaveAccessData(accessData *model.AccessData) (*mo return resultVar0, resultVar1 } -func (s *TimerLayerOAuthStore) SaveApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppError) { +func (s *TimerLayerOAuthStore) SaveApp(app *model.OAuthApp) (*model.OAuthApp, error) { start := timemodule.Now() resultVar0, resultVar1 := s.OAuthStore.SaveApp(app) @@ -4062,7 +4062,7 @@ func (s *TimerLayerOAuthStore) SaveApp(app *model.OAuthApp) (*model.OAuthApp, *m return resultVar0, resultVar1 } -func (s *TimerLayerOAuthStore) SaveAuthData(authData *model.AuthData) (*model.AuthData, *model.AppError) { +func (s *TimerLayerOAuthStore) SaveAuthData(authData *model.AuthData) (*model.AuthData, error) { start := timemodule.Now() resultVar0, resultVar1 := s.OAuthStore.SaveAuthData(authData) @@ -4078,7 +4078,7 @@ func (s *TimerLayerOAuthStore) SaveAuthData(authData *model.AuthData) (*model.Au return resultVar0, resultVar1 } -func (s *TimerLayerOAuthStore) UpdateAccessData(accessData *model.AccessData) (*model.AccessData, *model.AppError) { +func (s *TimerLayerOAuthStore) UpdateAccessData(accessData *model.AccessData) (*model.AccessData, error) { start := timemodule.Now() resultVar0, resultVar1 := s.OAuthStore.UpdateAccessData(accessData) @@ -4094,7 +4094,7 @@ func (s *TimerLayerOAuthStore) UpdateAccessData(accessData *model.AccessData) (* return resultVar0, resultVar1 } -func (s *TimerLayerOAuthStore) UpdateApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppError) { +func (s *TimerLayerOAuthStore) UpdateApp(app *model.OAuthApp) (*model.OAuthApp, error) { start := timemodule.Now() resultVar0, resultVar1 := s.OAuthStore.UpdateApp(app) diff --git a/web/oauth_test.go b/web/oauth_test.go index 7080bdfe71..fef5cea1d3 100644 --- a/web/oauth_test.go +++ b/web/oauth_test.go @@ -336,8 +336,8 @@ func TestOAuthAccessToken(t *testing.T) { require.Nil(t, err) authData := &model.AuthData{ClientId: oauthApp.Id, RedirectUri: oauthApp.CallbackUrls[0], UserId: th.BasicUser.Id, Code: model.NewId(), ExpiresIn: -1} - _, err = th.App.Srv().Store.OAuth().SaveAuthData(authData) - require.Nil(t, err) + _, nErr := th.App.Srv().Store.OAuth().SaveAuthData(authData) + require.Nil(t, nErr) data.Set("grant_type", model.ACCESS_TOKEN_GRANT_TYPE) data.Set("client_id", oauthApp.Id)