Skip to content

Commit

Permalink
Don't error on deleted users
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Steffen <[email protected]>
  • Loading branch information
jastBytes committed Aug 2, 2022
1 parent 4f18ba2 commit c1eba26
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/scimserver/user_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ func (h *userHandler) Delete(r *http.Request, id string) error {

_, err = h.cmdHandlerClient.Execute(ctx, cmd.CreateCommand(uid, commandTypes.DeleteUser))
if err != nil {
err = errors.TranslateFromGrpcError(err)
if err == errors.ErrDeleted {
return nil
}

return scim_errors.ScimError{
Status: http.StatusInternalServerError,
Detail: err.Error(),
Expand Down
22 changes: 22 additions & 0 deletions internal/scimserver/user_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,28 @@ var _ = Describe("internal/scimserver/UserHandler", func() {
scimErr, ok := err.(scim_errors.ScimError)
Expect(ok).To(BeTrue())

Expect(scimErr.Status).To(Equal(http.StatusNotFound))
})
It("doesn't return deleted user", func() {
deletedUser := &projections.User{
Id: uuid.New().String(),
Name: "test.user.a",
Email: "[email protected]",
Metadata: &projections.LifecycleMetadata{
Deleted: timestamppb.Now(),
},
}
commandHandlerClient := mock_eventsourcing.NewMockCommandHandlerClient(mockCtrl)
userClient := mock_domain.NewMockUserClient(mockCtrl)
userHandler := NewUserHandler(commandHandlerClient, userClient)

userClient.EXPECT().GetById(ctx, gomock.Any()).Return(deletedUser, nil)

_, err := userHandler.Get(request, deletedUser.Id)
Expect(err).To(HaveOccurred())
scimErr, ok := err.(scim_errors.ScimError)
Expect(ok).To(BeTrue())

Expect(scimErr.Status).To(Equal(http.StatusNotFound))
})
})
Expand Down

0 comments on commit c1eba26

Please sign in to comment.