Fixes MM-50733 (#22784)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
0af69b3411
Коммит
7325c38c39
@@ -309,6 +309,10 @@ func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectURI, c
|
||||
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.internal_user.app_error", nil, "", http.StatusNotFound)
|
||||
}
|
||||
|
||||
if user.DeleteAt != 0 {
|
||||
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.expired_code.app_error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
@@ -633,3 +633,47 @@ func TestDeauthorizeOAuthApp(t *testing.T) {
|
||||
require.Equal(t, store.NewErrNotFound("AuthData", fmt.Sprintf("code=%s", code)), nErr)
|
||||
assert.Nil(t, data)
|
||||
}
|
||||
|
||||
func TestDeactivatedUserOAuthApp(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = true })
|
||||
|
||||
oapp := &model.OAuthApp{
|
||||
Name: "fakeoauthapp" + model.NewRandomString(10),
|
||||
CreatorId: th.BasicUser2.Id,
|
||||
Homepage: "https://nowhere.com",
|
||||
Description: "test",
|
||||
CallbackUrls: []string{"https://nowhere.com"},
|
||||
}
|
||||
|
||||
oapp, err := th.App.CreateOAuthApp(oapp)
|
||||
require.Nil(t, err)
|
||||
|
||||
authRequest := &model.AuthorizeRequest{
|
||||
ResponseType: model.ImplicitResponseType,
|
||||
ClientId: oapp.Id,
|
||||
RedirectURI: oapp.CallbackUrls[0],
|
||||
Scope: "",
|
||||
State: "123",
|
||||
}
|
||||
|
||||
redirectUrl, err := th.App.GetOAuthCodeRedirect(th.BasicUser.Id, authRequest)
|
||||
assert.Nil(t, err)
|
||||
|
||||
uri, uErr := url.Parse(redirectUrl)
|
||||
require.NoError(t, uErr)
|
||||
|
||||
queryParams := uri.Query()
|
||||
code := queryParams.Get("code")
|
||||
|
||||
_, appErr := th.App.UpdateActive(th.Context, th.BasicUser, false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
resp, accErr := th.App.GetOAuthAccessTokenForCodeFlow(oapp.Id, model.AccessTokenGrantType, oapp.CallbackUrls[0], code, oapp.ClientSecret, "")
|
||||
assert.Nil(t, resp)
|
||||
require.NotNil(t, accErr, "Should not get access token")
|
||||
require.Equal(t, http.StatusBadRequest, accErr.StatusCode)
|
||||
assert.Equal(t, "api.oauth.get_access_token.expired_code.app_error", accErr.Id)
|
||||
}
|
||||
|
||||
@@ -933,6 +933,10 @@ func (a *App) userDeactivated(c request.CTX, userID string) *model.AppError {
|
||||
a.disableUserBots(c, userID)
|
||||
}
|
||||
|
||||
if nErr := a.Srv().Store().OAuth().RemoveAuthDataByUserId(userID); nErr != nil {
|
||||
mlog.Warn("unable to remove auth data by user id", mlog.Err(nErr))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user