mirror of
https://github.com/emqx/neuron.git
synced 2026-10-29 07:06:32 +08:00
merge user&password error code
This commit is contained in:
@@ -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
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -3,6 +3,7 @@ import sys
|
||||
|
||||
import neuron.api as api
|
||||
from neuron.common import *
|
||||
from neuron.error import *
|
||||
|
||||
|
||||
class TestLogin:
|
||||
@@ -16,11 +17,13 @@ class TestLogin:
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user