Skip to content

Commit

Permalink
update tests and fix 1 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kayra1 committed Jul 26, 2024
1 parent 270a162 commit 942696e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions internal/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,13 @@ func DeleteUserAccount(env *Environment) http.HandlerFunc {
id := r.PathValue("id")
user, err := env.DB.RetrieveUser(id)
if err != nil {
logErrorAndWriteResponse("error occured while processing request", http.StatusInternalServerError, w)
return
if !errors.Is(err, certdb.ErrIdNotFound) {
logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w)
return
}
}
if user.Permissions == 1 {
logErrorAndWriteResponse("Deleting an Admin account is not allowed.", http.StatusBadRequest, w)
logErrorAndWriteResponse("deleting an Admin account is not allowed.", http.StatusBadRequest, w)
return
}
insertId, err := env.DB.DeleteUser(id)
Expand Down
4 changes: 2 additions & 2 deletions internal/api/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,8 @@ func TestAuthorization(t *testing.T) {
path: "/api/v1/accounts/1",
data: "",
auth: adminToken,
response: "error: can't delete admin account",
status: http.StatusConflict,
response: "error: deleting an Admin account is not allowed.",
status: http.StatusBadRequest,
},
{
desc: "admin can delete nonuser",
Expand Down

0 comments on commit 942696e

Please sign in to comment.