mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
Add missing case for email change errors (#4390)
* Add missing case for email change errors * Update tests
This commit is contained in:
parent
1fdcb1bfc2
commit
c522c2eaa2
3 changed files with 28 additions and 0 deletions
|
|
@ -2366,6 +2366,19 @@ func (s *integrationTestSuite) TestUsers() {
|
|||
}
|
||||
s.DoJSON("PATCH", fmt.Sprintf("/api/v1/fleet/users/%d", u.ID), params, http.StatusConflict, &modResp)
|
||||
|
||||
// modify that user - set an email that has an invite for it
|
||||
createInviteReq := createInviteRequest{InvitePayload: fleet.InvitePayload{
|
||||
Email: ptr.String("colliding@email.com"),
|
||||
Name: ptr.String("some name"),
|
||||
GlobalRole: null.StringFrom(fleet.RoleAdmin),
|
||||
}}
|
||||
createInviteResp := createInviteResponse{}
|
||||
s.DoJSON("POST", "/api/v1/fleet/invites", createInviteReq, http.StatusOK, &createInviteResp)
|
||||
params = fleet.UserPayload{
|
||||
Email: ptr.String("colliding@email.com"),
|
||||
}
|
||||
s.DoJSON("PATCH", fmt.Sprintf("/api/v1/fleet/users/%d", u.ID), params, http.StatusConflict, &modResp)
|
||||
|
||||
// modify that user - set a non existent email
|
||||
params = fleet.UserPayload{
|
||||
Email: ptr.String("someemail@qowieuowh.com"),
|
||||
|
|
|
|||
|
|
@ -585,6 +585,15 @@ func (svc *Service) modifyEmailAddress(ctx context.Context, user *fleet.User, em
|
|||
return ctxerr.Wrap(ctx, err)
|
||||
}
|
||||
|
||||
switch _, err = svc.ds.InviteByEmail(ctx, email); {
|
||||
case err == nil:
|
||||
return ctxerr.Wrap(ctx, alreadyExistsError{})
|
||||
case errors.Is(err, sql.ErrNoRows):
|
||||
// OK
|
||||
default:
|
||||
return ctxerr.Wrap(ctx, err)
|
||||
}
|
||||
|
||||
err = svc.ds.PendingEmailChange(ctx, user.ID, email, token)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -213,6 +213,9 @@ func TestModifyUserEmail(t *testing.T) {
|
|||
ms.UserByEmailFunc = func(ctx context.Context, email string) (*fleet.User, error) {
|
||||
return nil, notFoundErr{}
|
||||
}
|
||||
ms.InviteByEmailFunc = func(ctx context.Context, email string) (*fleet.Invite, error) {
|
||||
return nil, notFoundErr{}
|
||||
}
|
||||
ms.AppConfigFunc = func(ctx context.Context) (*fleet.AppConfig, error) {
|
||||
config := &fleet.AppConfig{
|
||||
SMTPSettings: fleet.SMTPSettings{
|
||||
|
|
@ -351,6 +354,9 @@ func TestModifyAdminUserEmailPassword(t *testing.T) {
|
|||
ms.UserByEmailFunc = func(ctx context.Context, email string) (*fleet.User, error) {
|
||||
return nil, notFoundErr{}
|
||||
}
|
||||
ms.InviteByEmailFunc = func(ctx context.Context, email string) (*fleet.Invite, error) {
|
||||
return nil, notFoundErr{}
|
||||
}
|
||||
ms.UserByIDFunc = func(ctx context.Context, id uint) (*fleet.User, error) {
|
||||
return user, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue