Skip to content

Commit

Permalink
Merge pull request #1363 from hxy7yx/v2.5-2
Browse files Browse the repository at this point in the history
optimization of password error reporting
  • Loading branch information
yuxi311 authored Jul 5, 2023
2 parents 6877523 + 413cb76 commit cae5c3f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
9 changes: 7 additions & 2 deletions ft/normal_test.robot
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ Suite Setup Start Neuronx
Suite Teardown Stop Neuronx

*** Test Cases ***
login with invalid username and password, it should return failure
login with invalid username, it should return failure
POST /api/v2/login {"name":"admin1", "pass": "0000"}
Integer response status 401
Integer $.error ${NEU_ERR_INVALID_USER_OR_PASSWORD}
Integer $.error ${NEU_ERR_INVALID_USER}

login with invalid password, it should return failure
POST /api/v2/login {"name":"admin", "pass": "2333"}
Integer response status 401
Integer $.error ${NEU_ERR_INVALID_PASSWORD}

login with username and password, it should return success
POST /api/v2/login {"name":"admin", "pass": "0000"}
Expand Down
2 changes: 2 additions & 0 deletions ft/resource/error.resource
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ ${NEU_ERR_DUPLICATE_PASSWORD} 1013
${NEU_ERR_COMMAND_EXECUTION_FAILED} 1014
${NEU_ERR_IP_ADDRESS_INVALID} 1015
${NEU_ERR_IP_ADDRESS_IN_USE} 1016
${NEU_ERR_INVALID_USER} 1017
${NEU_ERR_INVALID_PASSWORD} 1018

${NEU_ERR_NODE_EXIST} 2002
${NEU_ERR_NODE_NOT_EXIST} 2003
Expand Down
2 changes: 2 additions & 0 deletions include/neuron/errcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ typedef enum {
NEU_ERR_COMMAND_EXECUTION_FAILED = 1014,
NEU_ERR_IP_ADDRESS_INVALID = 1015,
NEU_ERR_IP_ADDRESS_IN_USE = 1016,
NEU_ERR_INVALID_USER = 1017,
NEU_ERR_INVALID_PASSWORD = 1018,

NEU_ERR_NODE_EXIST = 2002,
NEU_ERR_NODE_NOT_EXIST = 2003,
Expand Down
8 changes: 4 additions & 4 deletions plugins/restful/normal_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void handle_login(nng_aio *aio)

if (NULL == user) {
nlog_error("could not find user `%s`", req->name);
NEU_JSON_RESPONSE_ERROR(NEU_ERR_INVALID_USER_OR_PASSWORD, {
NEU_JSON_RESPONSE_ERROR(NEU_ERR_INVALID_USER, {
neu_http_response(aio, error_code.error, result_error);
});
} else if (pass_len < NEU_USER_PASSWORD_MIN_LEN ||
Expand Down Expand Up @@ -90,7 +90,7 @@ void handle_login(nng_aio *aio)
free(result);
} else {
nlog_error("user `%s` password check fail", req->name);
NEU_JSON_RESPONSE_ERROR(NEU_ERR_INVALID_USER_OR_PASSWORD, {
NEU_JSON_RESPONSE_ERROR(NEU_ERR_INVALID_PASSWORD, {
neu_http_response(aio, error_code.error, result_error);
});
}
Expand All @@ -114,10 +114,10 @@ void handle_password(nng_aio *aio)
rv = NEU_ERR_INVALID_PASSWORD_LEN;
} else if (NULL == (user = neu_load_user(req->name))) {
nlog_error("could not find user `%s`", req->name);
rv = NEU_ERR_INVALID_USER_OR_PASSWORD;
rv = NEU_ERR_INVALID_USER;
} else if (!neu_user_check_password(user, req->old_pass)) {
nlog_error("user `%s` password check fail", req->name);
rv = NEU_ERR_INVALID_USER_OR_PASSWORD;
rv = NEU_ERR_INVALID_PASSWORD;
} else if (0 !=
(rv = neu_user_update_password(user, req->new_pass))) {
nlog_error("user `%s` update password fail", req->name);
Expand Down
2 changes: 2 additions & 0 deletions src/utils/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ int neu_http_response(nng_aio *aio, neu_err_code_e code, char *content)
case NEU_ERR_NEED_TOKEN:
case NEU_ERR_DECODE_TOKEN:
case NEU_ERR_INVALID_USER_OR_PASSWORD:
case NEU_ERR_INVALID_USER:
case NEU_ERR_INVALID_PASSWORD:
status = NNG_HTTP_STATUS_UNAUTHORIZED;
break;
case NEU_ERR_BODY_IS_WRONG:
Expand Down

0 comments on commit cae5c3f

Please sign in to comment.