Skip to content

Commit

Permalink
Merge pull request #1676 from hxy7yx/main-1
Browse files Browse the repository at this point in the history
merge user&password error code
  • Loading branch information
fengzeroz authored Nov 20, 2023
2 parents 174631e + 05fe61e commit 6e0455e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 30 deletions.
22 changes: 0 additions & 22 deletions ft/normal_test.robot

This file was deleted.

2 changes: 0 additions & 2 deletions include/neuron/errcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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, {
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 ||
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_PASSWORD, {
NEU_JSON_RESPONSE_ERROR(NEU_ERR_INVALID_USER_OR_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;
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);
Expand Down
2 changes: 0 additions & 2 deletions src/utils/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions tests/ft/login/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import neuron.api as api
from neuron.common import *
from neuron.error import *


class TestLogin:
Expand All @@ -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):
Expand Down

0 comments on commit 6e0455e

Please sign in to comment.