Fix MM-57090 (#26589)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
cd3b5b46e1
Коммит
b336fb9a45
@@ -4272,6 +4272,91 @@ func TestSwitchAccount(t *testing.T) {
|
||||
_, appErr := th.App.Srv().Store().User().UpdateAuthData(th.BasicUser.Id, model.UserAuthServiceGitlab, &fakeAuthData, th.BasicUser.Email, true)
|
||||
require.NoError(t, appErr)
|
||||
|
||||
t.Run("From GitLab to Email", func(t *testing.T) {
|
||||
sr = &model.SwitchRequest{
|
||||
CurrentService: model.UserAuthServiceGitlab,
|
||||
NewService: model.UserAuthServiceEmail,
|
||||
Email: th.BasicUser.Email,
|
||||
NewPassword: th.BasicUser.Password,
|
||||
}
|
||||
|
||||
t.Run("Switching from OAuth to email is disabled if EnableSignUpWithEmail is false", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.EmailSettings.EnableSignUpWithEmail = false })
|
||||
t.Cleanup(func() {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.EmailSettings.EnableSignUpWithEmail = true })
|
||||
})
|
||||
|
||||
_, resp, err = th.Client.SwitchAccountType(context.Background(), sr)
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, "api.user.auth_switch.not_available.email_signup_disabled.app_error", err.(*model.AppError).Id)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("Switching from OAuth to email is disabled if EnableSignInWithEmail and EnableSignInWithUsername is false", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.EmailSettings.EnableSignInWithEmail = false
|
||||
*cfg.EmailSettings.EnableSignInWithUsername = false
|
||||
})
|
||||
t.Cleanup(func() {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.EmailSettings.EnableSignInWithEmail = true
|
||||
*cfg.EmailSettings.EnableSignInWithUsername = true
|
||||
})
|
||||
})
|
||||
|
||||
_, resp, err = th.Client.SwitchAccountType(context.Background(), sr)
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, "api.user.auth_switch.not_available.login_disabled.app_error", err.(*model.AppError).Id)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("From LDAP to Email", func(t *testing.T) {
|
||||
_, err = th.App.Srv().Store().User().UpdateAuthData(th.BasicUser.Id, model.UserAuthServiceLdap, &fakeAuthData, th.BasicUser.Email, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Cleanup(func() {
|
||||
_, err = th.App.Srv().Store().User().UpdateAuthData(th.BasicUser.Id, model.UserAuthServiceGitlab, &fakeAuthData, th.BasicUser.Email, true)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
sr = &model.SwitchRequest{
|
||||
CurrentService: model.UserAuthServiceLdap,
|
||||
NewService: model.UserAuthServiceEmail,
|
||||
Email: th.BasicUser.Email,
|
||||
NewPassword: th.BasicUser.Password,
|
||||
}
|
||||
|
||||
t.Run("Switching from LDAP to email is disabled if EnableSignUpWithEmail is false", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.EmailSettings.EnableSignUpWithEmail = false })
|
||||
t.Cleanup(func() {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.EmailSettings.EnableSignUpWithEmail = true })
|
||||
})
|
||||
|
||||
_, resp, err = th.Client.SwitchAccountType(context.Background(), sr)
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, "api.user.auth_switch.not_available.email_signup_disabled.app_error", err.(*model.AppError).Id)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
t.Run("Switching from LDAP to email is disabled if EnableSignInWithEmail and EnableSignInWithUsername is false", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.EmailSettings.EnableSignInWithEmail = false
|
||||
*cfg.EmailSettings.EnableSignInWithUsername = false
|
||||
})
|
||||
t.Cleanup(func() {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.EmailSettings.EnableSignInWithEmail = true
|
||||
*cfg.EmailSettings.EnableSignInWithUsername = true
|
||||
})
|
||||
})
|
||||
|
||||
_, resp, err = th.Client.SwitchAccountType(context.Background(), sr)
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, "api.user.auth_switch.not_available.login_disabled.app_error", err.(*model.AppError).Id)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
})
|
||||
|
||||
sr = &model.SwitchRequest{
|
||||
CurrentService: model.UserAuthServiceGitlab,
|
||||
NewService: model.UserAuthServiceEmail,
|
||||
|
||||
@@ -129,6 +129,14 @@ func (a *App) SwitchLdapToEmail(c request.CTX, ldapPassword, code, email, newPas
|
||||
return "", model.NewAppError("ldapToEmail", "api.user.ldap_to_email.not_available.app_error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
|
||||
if !*a.Config().EmailSettings.EnableSignUpWithEmail {
|
||||
return "", model.NewAppError("SwitchEmailToLdap", "api.user.auth_switch.not_available.email_signup_disabled.app_error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
|
||||
if !*a.Config().EmailSettings.EnableSignInWithEmail && !*a.Config().EmailSettings.EnableSignInWithUsername {
|
||||
return "", model.NewAppError("SwitchEmailToLdap", "api.user.auth_switch.not_available.login_disabled.app_error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
|
||||
user, err := a.GetUserByEmail(email)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
@@ -986,6 +986,14 @@ func (a *App) SwitchOAuthToEmail(c request.CTX, email, password, requesterId str
|
||||
return "", model.NewAppError("oauthToEmail", "api.user.oauth_to_email.not_available.app_error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
|
||||
if !*a.Config().EmailSettings.EnableSignUpWithEmail {
|
||||
return "", model.NewAppError("SwitchOAuthToEmail", "api.user.auth_switch.not_available.email_signup_disabled.app_error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
|
||||
if !*a.Config().EmailSettings.EnableSignInWithEmail && !*a.Config().EmailSettings.EnableSignInWithUsername {
|
||||
return "", model.NewAppError("SwitchOAuthToEmail", "api.user.auth_switch.not_available.login_disabled.app_error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
|
||||
user, err := a.GetUserByEmail(email)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
@@ -4066,6 +4066,14 @@
|
||||
"id": "api.user.add_user_to_group_syncables.not_ldap_user.app_error",
|
||||
"translation": "not an ldap user"
|
||||
},
|
||||
{
|
||||
"id": "api.user.auth_switch.not_available.email_signup_disabled.app_error",
|
||||
"translation": "Authentication Transfer is not available as email signup is disabled."
|
||||
},
|
||||
{
|
||||
"id": "api.user.auth_switch.not_available.login_disabled.app_error",
|
||||
"translation": "Authentication Transfer is not available as neither email login nor username login is enabled."
|
||||
},
|
||||
{
|
||||
"id": "api.user.authorize_oauth_user.bad_response.app_error",
|
||||
"translation": "Bad response from token request."
|
||||
|
||||
Ссылка в новой задаче
Block a user