klab-ilc-cnr / maia-be

0 stars 0 forks source link

Error creating a new user #1

Open MPapini91 opened 11 months ago

MPapini91 commented 11 months ago

Invoking the services of the development back-end in the version without Keycloak.

POST /maia/api/users HTTP/1.1 PAYLOAD {"username":"aaa","name":"aaa","surname":"aaa","email":"aaa@a.a","role":"AMMINISTRATORE","active":null,"languages":[{"code":"it","name":"Italiano"}]} RESPONSE { "timestamp": "2023-11-15T09:52:50.402+00:00", "status": 500, "error": "Internal Server Error", "message": "Could not commit JPA transaction", "path": "/maia/api/users" }

MPapini91 commented 11 months ago

@davide-albanesi-ilc I tested the creation of a new user for this PR (https://github.com/MPapini91/maia-fe/pull/77). POST /maia/api/users is correctly executed, but in the response the new user is returned with only the fields submitted at creation. Thus, the ID, which is needed to invoke password saving, is missing. The password saving is still invoked, but it fails:

POST /maia/api/users/password PAYLOAD {"id":null,"newPassword":"test6"} RESPONSE

{
    "timestamp": "2023-11-17T08:12:53.600+00:00",
    "status": 500,
    "error": "Internal Server Error",
    "message": "Cannot invoke \"String.equals(Object)\" because the return value of \"it.cnr.ilc.projectx.dto.UpdatePasswordDto.getCurrentPassword()\" is null",
    "path": "/maia/api/users/password"
}
davide-albanesi-ilc commented 11 months ago

{"username":"aaa","name":"aaa","surname":"aaa","email":"aaa@a.a","role":"AMMINISTRATORE","active":null,"languages":[{"code":"it","name":"Italiano"}]}

The username is too short, minimum length should be 4 characters. Here is the regular expression used to validate the username: ^[a-zA-Z0-9@._-]{4,20}$

davide-albanesi-ilc commented 11 months ago

@davide-albanesi-ilc I tested the creation of a new user for this PR (MPapini91/maia-fe#77). POST /maia/api/users is correctly executed, but in the response the new user is returned with only the fields submitted at creation. Thus, the ID, which is needed to invoke password saving, is missing. The password saving is still invoked, but it fails:

POST /maia/api/users/password PAYLOAD {"id":null,"newPassword":"test6"} RESPONSE

{
    "timestamp": "2023-11-17T08:12:53.600+00:00",
    "status": 500,
    "error": "Internal Server Error",
    "message": "Cannot invoke \"String.equals(Object)\" because the return value of \"it.cnr.ilc.projectx.dto.UpdatePasswordDto.getCurrentPassword()\" is null",
    "path": "/maia/api/users/password"
}

These are two different issues:

  1. ID missing in response: It's going to resolve it.
  2. error in update password: It is necessary to know who is the user who made the request.
MPapini91 commented 11 months ago

@davide-albanesi-ilc I tested the creation of a new user for this PR (MPapini91/maia-fe#77). POST /maia/api/users is correctly executed, but in the response the new user is returned with only the fields submitted at creation. Thus, the ID, which is needed to invoke password saving, is missing. The password saving is still invoked, but it fails: POST /maia/api/users/password PAYLOAD {"id":null,"newPassword":"test6"} RESPONSE

{
    "timestamp": "2023-11-17T08:12:53.600+00:00",
    "status": 500,
    "error": "Internal Server Error",
    "message": "Cannot invoke \"String.equals(Object)\" because the return value of \"it.cnr.ilc.projectx.dto.UpdatePasswordDto.getCurrentPassword()\" is null",
    "path": "/maia/api/users/password"
}

These are two different issues:

  1. ID missing in response: It's going to resolve it.
  2. error in update password: It is necessary to know who is the user who made the request.

I think it is a cascading error related to the checks on the modified user id. I make a note of the check, as soon as there is a change in the response I fix the problem of the user id of the user making the call.