diff --git a/ft/normal_test.robot b/ft/normal_test.robot deleted file mode 100644 index 961145bb1..000000000 --- a/ft/normal_test.robot +++ /dev/null @@ -1,22 +0,0 @@ -*** Settings *** -Resource resource/api.resource -Resource resource/common.resource -Resource resource/error.resource -Suite Setup Start Neuronx -Suite Teardown Stop Neuronx - -*** Test Cases *** -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} - -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"} - Integer response status 200 - output $.token \ No newline at end of file diff --git a/include/neuron/errcodes.h b/include/neuron/errcodes.h index 65337abbf..e2153f6a4 100644 --- a/include/neuron/errcodes.h +++ b/include/neuron/errcodes.h @@ -47,8 +47,6 @@ 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, diff --git a/plugins/restful/normal_handle.c b/plugins/restful/normal_handle.c index 1d013c1ce..52fb800a6 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, { + NEU_JSON_RESPONSE_ERROR(NEU_ERR_INVALID_USER_OR_PASSWORD, { 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_PASSWORD, { + NEU_JSON_RESPONSE_ERROR(NEU_ERR_INVALID_USER_OR_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; + rv = NEU_ERR_INVALID_USER_OR_PASSWORD; } else if (!neu_user_check_password(user, req->old_pass)) { nlog_error("user `%s` password check fail", req->name); - rv = NEU_ERR_INVALID_PASSWORD; + rv = NEU_ERR_INVALID_USER_OR_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 98291c260..42653659e 100644 --- a/src/utils/http.c +++ b/src/utils/http.c @@ -317,8 +317,6 @@ 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: diff --git a/tests/ft/login/test_login.py b/tests/ft/login/test_login.py index 26fa77dc3..d74bb22cf 100644 --- a/tests/ft/login/test_login.py +++ b/tests/ft/login/test_login.py @@ -3,6 +3,7 @@ import neuron.api as api from neuron.common import * +from neuron.error import * class TestLogin: @@ -16,11 +17,13 @@ def test_login_success(self): def test_login_invalid_user(self): response = api.login('invalid_user') assert 401 == response.status_code + assert NEU_ERR_INVALID_USER_OR_PASSWORD == response.json()['error'] @description(given="invalid password", when="login", then="login failed") def test_login_invalid_password(self): response = api.login(password='invalid_password') assert 401 == response.status_code + assert NEU_ERR_INVALID_USER_OR_PASSWORD == response.json()['error'] @description(given="user, old and new password", when="change password", then="change success") def test_change_password(self):