Skip to content

Commit

Permalink
fix: Wrong Error Message Returned When No Provider For UserGrant (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinodsathyaseelan committed Apr 5, 2024
1 parent c48571a commit 2c1a47f
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 4 deletions.
117 changes: 117 additions & 0 deletions core/sdk/src/api/firebolt/fb_capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ pub const CAPABILITY_UNGRANTED: i32 = -40401;

pub const CAPABILITY_APP_NOT_IN_ACTIVE_STATE: i32 = -40402;

pub const CAPABILITY_GRANT_PROVIDER_MISSING: i32 = -40403;

impl RpcError for DenyReason {
type E = Vec<String>;
fn get_rpc_error_code(&self) -> i32 {
Expand All @@ -389,6 +391,7 @@ impl RpcError for DenyReason {
Self::Ungranted => CAPABILITY_NOT_PERMITTED,
Self::NotFound => JSON_RPC_STANDARD_ERROR_METHOD_NOT_FOUND,
Self::AppNotInActiveState => CAPABILITY_NOT_PERMITTED,
Self::GrantProviderMissing => CAPABILITY_GRANT_PROVIDER_MISSING,
_ => CAPABILITY_GET_ERROR,
}
}
Expand All @@ -405,6 +408,7 @@ impl RpcError for DenyReason {
Self::AppNotInActiveState => {
"Capability cannot be used when app is not in foreground state due to requiring a user grant".to_string()
}
Self::GrantProviderMissing => format!("Grant provider is missing for {}", caps_disp),
_ => format!("Error with {}", caps_disp),
}
}
Expand All @@ -418,6 +422,7 @@ impl RpcError for DenyReason {
Self::Ungranted => CAPABILITY_UNGRANTED,
Self::NotFound => JSON_RPC_STANDARD_ERROR_METHOD_NOT_FOUND,
Self::AppNotInActiveState => CAPABILITY_APP_NOT_IN_ACTIVE_STATE,
Self::GrantProviderMissing => CAPABILITY_GRANT_PROVIDER_MISSING,
_ => CAPABILITY_GET_ERROR,
}
}
Expand Down Expand Up @@ -510,3 +515,115 @@ impl CapEvent {
variant_name.to_owned()
}
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_deny_reason_get_rpc_error_message() {
let caps = vec!["xrn:firebolt:capability:account:session".to_string()];
assert_eq!(
DenyReason::Unavailable.get_rpc_error_message(caps.clone()),
"xrn:firebolt:capability:account:session is not available"
);
assert_eq!(
DenyReason::Unsupported.get_rpc_error_message(caps.clone()),
"xrn:firebolt:capability:account:session is not supported"
);
assert_eq!(
DenyReason::GrantDenied.get_rpc_error_message(caps.clone()),
"The user denied access to xrn:firebolt:capability:account:session"
);
assert_eq!(
DenyReason::Unpermitted.get_rpc_error_message(caps.clone()),
"xrn:firebolt:capability:account:session is not permitted"
);
assert_eq!(
DenyReason::Ungranted.get_rpc_error_message(caps.clone()),
"The user did not make a grant decision for xrn:firebolt:capability:account:session"
);
assert_eq!(
DenyReason::NotFound.get_rpc_error_message(caps.clone()),
"Method not Found"
);
assert_eq!(
DenyReason::AppNotInActiveState.get_rpc_error_message(caps.clone()),
"Capability cannot be used when app is not in foreground state due to requiring a user grant"
);
assert_eq!(
DenyReason::GrantProviderMissing.get_rpc_error_message(caps),
"Grant provider is missing for xrn:firebolt:capability:account:session"
);
}
#[test]
fn test_deny_reason_get_rpc_error_code() {
assert_eq!(
DenyReason::Unavailable.get_rpc_error_code(),
CAPABILITY_NOT_AVAILABLE
);
assert_eq!(
DenyReason::Unsupported.get_rpc_error_code(),
CAPABILITY_NOT_SUPPORTED
);
assert_eq!(
DenyReason::GrantDenied.get_rpc_error_code(),
CAPABILITY_NOT_PERMITTED
);
assert_eq!(
DenyReason::Unpermitted.get_rpc_error_code(),
CAPABILITY_NOT_PERMITTED
);
assert_eq!(
DenyReason::Ungranted.get_rpc_error_code(),
CAPABILITY_NOT_PERMITTED
);
assert_eq!(
DenyReason::NotFound.get_rpc_error_code(),
JSON_RPC_STANDARD_ERROR_METHOD_NOT_FOUND
);
assert_eq!(
DenyReason::AppNotInActiveState.get_rpc_error_code(),
CAPABILITY_NOT_PERMITTED
);
assert_eq!(
DenyReason::GrantProviderMissing.get_rpc_error_code(),
CAPABILITY_GRANT_PROVIDER_MISSING
);
}
#[test]
fn test_deny_reason_get_observability_error_code() {
assert_eq!(
DenyReason::Unavailable.get_observability_error_code(),
CAPABILITY_NOT_AVAILABLE
);
assert_eq!(
DenyReason::Unsupported.get_observability_error_code(),
CAPABILITY_NOT_SUPPORTED
);
assert_eq!(
DenyReason::GrantDenied.get_observability_error_code(),
CAPABILITY_GRANT_DENIED
);
assert_eq!(
DenyReason::Unpermitted.get_observability_error_code(),
CAPABILITY_NOT_PERMITTED
);
assert_eq!(
DenyReason::Ungranted.get_observability_error_code(),
CAPABILITY_UNGRANTED
);
assert_eq!(
DenyReason::NotFound.get_observability_error_code(),
JSON_RPC_STANDARD_ERROR_METHOD_NOT_FOUND
);
assert_eq!(
DenyReason::AppNotInActiveState.get_observability_error_code(),
CAPABILITY_APP_NOT_IN_ACTIVE_STATE
);
assert_eq!(
DenyReason::GrantProviderMissing.get_observability_error_code(),
CAPABILITY_GRANT_PROVIDER_MISSING
);
}
}
11 changes: 7 additions & 4 deletions core/sdk/src/extn/client/extn_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,13 @@ impl ExtnClient {
error!("IEC Latency {:?}", c_message);
}
let message_result: Result<ExtnMessage, RippleError> = c_message.clone().try_into();
if message_result.is_err() {
error!("invalid message {:?}", c_message);
}
let message = message_result.unwrap();
let message = match message_result {
Ok(extn_msg) => extn_msg,
Err(_) => {
error!("invalid message {:?}", c_message);
continue;
}
};
debug!("** receiving message latency={} msg={:?}", latency, message);
if message.payload.is_response() {
Self::handle_single(message, self.response_processors.clone());
Expand Down

0 comments on commit 2c1a47f

Please sign in to comment.