-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dependabot/cargo/once_cell-1.20.0
- Loading branch information
Showing
13 changed files
with
863 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
//! The `authenticate_v2` method error. | ||
|
||
use super::shared; | ||
use crate::error_data; | ||
|
||
/// The `authenticate_v2` method error kinds. | ||
#[derive(Debug)] | ||
pub struct Error(pub shared::FlowBaseError<robonode_client::AuthenticateError>); | ||
|
||
impl From<Error> for jsonrpsee::core::Error { | ||
fn from(err: Error) -> Self { | ||
err.0 | ||
.to_jsonrpsee_error::<_, error_data::BlobOrRetry>(|call_error| match call_error { | ||
robonode_client::AuthenticateError::PersonNotFound(ref scan_result_blob) | ||
| robonode_client::AuthenticateError::FaceScanRejected(ref scan_result_blob) | ||
| robonode_client::AuthenticateError::SignatureInvalid(ref scan_result_blob) | ||
| robonode_client::AuthenticateError::LogicInternal(ref scan_result_blob) => { | ||
Some(error_data::ScanResultBlob(scan_result_blob.clone()).into()) | ||
} | ||
|
||
robonode_client::AuthenticateError::FaceScanRejectedNoBlob => { | ||
Some(error_data::ShouldRetry.into()) | ||
} | ||
|
||
robonode_client::AuthenticateError::InvalidLivenessData | ||
| robonode_client::AuthenticateError::PersonNotFoundNoBlob | ||
| robonode_client::AuthenticateError::SignatureInvalidNoBlob | ||
| robonode_client::AuthenticateError::LogicInternalNoBlob | ||
| robonode_client::AuthenticateError::UnknownCode(_) | ||
| robonode_client::AuthenticateError::Unknown(_) => None, | ||
}) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
use jsonrpsee::types::ErrorObject; | ||
use rpc_validator_key_logic::Error as ValidatorKeyError; | ||
|
||
use super::*; | ||
use crate::errors::sign::Error as SignError; | ||
|
||
#[test] | ||
fn error_key_extraction_validator_key_extraction() { | ||
let error: jsonrpsee::core::Error = Error(shared::FlowBaseError::KeyExtraction( | ||
ValidatorKeyError::ValidatorKeyExtraction, | ||
)) | ||
.into(); | ||
let error: ErrorObject = error.into(); | ||
|
||
let expected_error_message = "{\"code\":600,\"message\":\"unable to extract own key\"}"; | ||
assert_eq!( | ||
expected_error_message, | ||
serde_json::to_string(&error).unwrap() | ||
); | ||
} | ||
|
||
#[test] | ||
fn error_key_extraction_missing_validator_key() { | ||
let error: jsonrpsee::core::Error = Error(shared::FlowBaseError::KeyExtraction( | ||
ValidatorKeyError::MissingValidatorKey, | ||
)) | ||
.into(); | ||
let error: ErrorObject = error.into(); | ||
|
||
let expected_error_message = "{\"code\":500,\"message\":\"validator key not available\",\"data\":{\"validatorKeyNotAvailable\":true}}"; | ||
assert_eq!( | ||
expected_error_message, | ||
serde_json::to_string(&error).unwrap() | ||
); | ||
} | ||
|
||
#[test] | ||
fn error_sign() { | ||
let error: jsonrpsee::core::Error = | ||
Error(shared::FlowBaseError::Sign(SignError::SigningFailed)).into(); | ||
let error: ErrorObject = error.into(); | ||
|
||
let expected_error_message = "{\"code\":100,\"message\":\"signing failed\"}"; | ||
assert_eq!( | ||
expected_error_message, | ||
serde_json::to_string(&error).unwrap() | ||
); | ||
} | ||
|
||
#[test] | ||
fn error_robonode_face_scan_rejected() { | ||
let error: jsonrpsee::core::Error = Error(shared::FlowBaseError::RobonodeClient( | ||
robonode_client::Error::Call(robonode_client::AuthenticateError::FaceScanRejected( | ||
"scan result blob".to_owned(), | ||
)), | ||
)) | ||
.into(); | ||
let error: ErrorObject = error.into(); | ||
|
||
let expected_error_message = | ||
"{\"code\":200,\"message\":\"server error: face scan rejected\",\"data\":{\"scanResultBlob\":\"scan result blob\"}}"; | ||
assert_eq!( | ||
expected_error_message, | ||
serde_json::to_string(&error).unwrap() | ||
); | ||
} | ||
|
||
#[test] | ||
fn error_robonode_logic_internal() { | ||
let error: jsonrpsee::core::Error = Error(shared::FlowBaseError::RobonodeClient( | ||
robonode_client::Error::Call(robonode_client::AuthenticateError::LogicInternal( | ||
"scan result blob".to_owned(), | ||
)), | ||
)) | ||
.into(); | ||
let error: ErrorObject = error.into(); | ||
|
||
let expected_error_message = | ||
"{\"code\":200,\"message\":\"server error: logic internal error\",\"data\":{\"scanResultBlob\":\"scan result blob\"}}"; | ||
assert_eq!( | ||
expected_error_message, | ||
serde_json::to_string(&error).unwrap() | ||
); | ||
} | ||
|
||
#[test] | ||
fn error_robonode_other() { | ||
let error: jsonrpsee::core::Error = Error(shared::FlowBaseError::RobonodeClient( | ||
robonode_client::Error::Call(robonode_client::AuthenticateError::Unknown( | ||
"test".to_owned(), | ||
)), | ||
)) | ||
.into(); | ||
let error: ErrorObject = error.into(); | ||
|
||
let expected_error_message = | ||
"{\"code\":200,\"message\":\"server error: unknown error: test\"}"; | ||
assert_eq!( | ||
expected_error_message, | ||
serde_json::to_string(&error).unwrap() | ||
); | ||
} | ||
} |
Oops, something went wrong.