fix outofbound, add more complex error msg

This commit is contained in:
DieMyst 2021-01-07 20:19:48 +03:00
parent 93081b4523
commit c3a45d6c9f
2 changed files with 6 additions and 4 deletions

View File

@ -33,7 +33,7 @@ pub struct AddServiceResult {
#[fce] #[fce]
fn add(msg: String, auth: bool) -> AddServiceResult { fn add(msg: String, auth: bool) -> AddServiceResult {
fn add_impl(msg: String, auth: bool) -> Result<u64> { fn add_impl(msg: String, auth: bool) -> Result<u64> {
is_authenticated(auth, 2)?; is_authenticated(auth, 1)?;
add_message(msg) add_message(msg)
} }
@ -102,7 +102,8 @@ pub fn is_authenticated(auth: bool, index: u64) -> Result<()> {
(st.peer_pk == t.peer_pk && st.function_name == t.fn_name (st.peer_pk == t.peer_pk && st.function_name == t.fn_name
&& st.service_id == t.service_id && && st.service_id == t.service_id &&
st.json_path == t.json_path && auth).ok_or_else(|| Unauthorized("Tetraplet did not pass the check.".to_string())) st.json_path == t.json_path && auth)
.ok_or_else(|| Unauthorized(format!("Tetraplet did not pass the check. Expected: {:?}, actual: {:?}", t, st)))
} }
} }
} }

View File

@ -41,10 +41,11 @@ pub struct GetMessagesServiceResult {
fn get_all() { fn get_all() {
let mut app_service = create_app_service(TEST_CONFIG_PATH); let mut app_service = create_app_service(TEST_CONFIG_PATH);
let result = call_app_service!(app_service, "add", json!(["body_1"])); call_app_service!(app_service, "set_tetraplet", json!(["", "", "", ""]));
let result = call_app_service!(app_service, "add", json!(["body_1", 1]));
assert_eq!(result, json!({ "ret_code": 0, "err_msg": "", "msg_id": 0 })); assert_eq!(result, json!({ "ret_code": 0, "err_msg": "", "msg_id": 0 }));
let result = call_app_service!(app_service, "add", json!(["body_2"])); let result = call_app_service!(app_service, "add", json!(["body_2", 1]));
assert_eq!(result, json!({ "ret_code": 0, "err_msg": "", "msg_id": 1 })); assert_eq!(result, json!({ "ret_code": 0, "err_msg": "", "msg_id": 1 }));
let result = call_app_service!(app_service, "get_all", json!([])); let result = call_app_service!(app_service, "get_all", json!([]));