diff --git a/ft/normal_test.robot b/ft/normal_test.robot index df1239ae..56e555ae 100644 --- a/ft/normal_test.robot +++ b/ft/normal_test.robot @@ -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"} diff --git a/ft/resource/error.resource b/ft/resource/error.resource index 2d75e1ab..578f0feb 100644 --- a/ft/resource/error.resource +++ b/ft/resource/error.resource @@ -16,6 +16,10 @@ ${NEU_ERR_FILE_NOT_EXIST} 1011 ${NEU_ERR_INVALID_PASSWORD_LEN} 1012 ${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 diff --git a/include/neuron/errcodes.h b/include/neuron/errcodes.h index ed4ecc3a..b89c9f18 100644 --- a/include/neuron/errcodes.h +++ b/include/neuron/errcodes.h @@ -45,6 +45,10 @@ typedef enum { NEU_ERR_INVALID_PASSWORD_LEN = 1012, 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, diff --git a/plugins/restful/normal_handle.c b/plugins/restful/normal_handle.c index 52fb800a..1d013c1c 100644 --- a/plugins/restful/normal_handle.c +++ b/plugins/restful/normal_handle.c @@ -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 || @@ -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); }); } @@ -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); diff --git a/src/utils/http.c b/src/utils/http.c index de2f9f99..5b9daef4 100644 --- a/src/utils/http.c +++ b/src/utils/http.c @@ -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: