diff --git a/services/graph/pkg/service/v0/password.go b/services/graph/pkg/service/v0/password.go index b5318953dc2..4804eb07ccb 100644 --- a/services/graph/pkg/service/v0/password.go +++ b/services/graph/pkg/service/v0/password.go @@ -69,7 +69,13 @@ func (g Graph) ChangeOwnPassword(w http.ResponseWriter, r *http.Request) { return } - if authRes.Status.Code != cs3rpc.Code_CODE_OK { + switch authRes.Status.Code { + case cs3rpc.Code_CODE_OK: + break + case cs3rpc.Code_CODE_UNAUTHENTICATED, cs3rpc.Code_CODE_PERMISSION_DENIED: + errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "wrong current password") + return + default: errorcode.InvalidRequest.Render(w, r, http.StatusInternalServerError, "password change failed") return } diff --git a/services/graph/pkg/service/v0/password_test.go b/services/graph/pkg/service/v0/password_test.go index a31f7775ec1..84a33fd07fa 100644 --- a/services/graph/pkg/service/v0/password_test.go +++ b/services/graph/pkg/service/v0/password_test.go @@ -122,7 +122,7 @@ var _ = Describe("Users changing their own password", func() { Entry("fails when new password is empty", "currentpassword", "", "", http.StatusBadRequest), Entry("fails when current and new password are equal", "password", "password", "", http.StatusBadRequest), Entry("fails authentication with current password errors", "currentpassword", "newpassword", "error", http.StatusInternalServerError), - Entry("fails when current password is wrong", "currentpassword", "newpassword", "deny", http.StatusInternalServerError), + Entry("fails when current password is wrong", "currentpassword", "newpassword", "deny", http.StatusBadRequest), Entry("succeeds when current password is correct", "currentpassword", "newpassword", "", http.StatusNoContent), ) }) diff --git a/tests/acceptance/features/apiGraph/changeOwnPassword.feature b/tests/acceptance/features/apiGraph/changeOwnPassword.feature index a0351cc8d15..e487455a817 100644 --- a/tests/acceptance/features/apiGraph/changeOwnPassword.feature +++ b/tests/acceptance/features/apiGraph/changeOwnPassword.feature @@ -13,5 +13,5 @@ Feature: an user changes its own password | 123456 | ?&^%0 | 204 | | 123456 | | 400 | | 123456 | 123456 | 400 | - | wrongPass | 123456 | 500 | + | wrongPass | 123456 | 400 | | | validPass | 400 |