Skip to content

Commit

Permalink
chore: [IC-272] always return error for fetching canister logs as ing…
Browse files Browse the repository at this point in the history
…ress despite the feature flag
  • Loading branch information
maksymar committed Mar 8, 2024
1 parent c9be4e4 commit 334bc60
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 74 deletions.
26 changes: 7 additions & 19 deletions rs/execution_environment/src/canister_manager.rs
Expand Up @@ -429,7 +429,6 @@ impl CanisterManager {
provisional_whitelist: &ProvisionalWhitelist,
ingress: &SignedIngressContent,
effective_canister_id: Option<CanisterId>,
canister_logging: FlagStatus,
) -> Result<(), UserError> {
let method_name = ingress.method_name();
let sender = ingress.sender();
Expand Down Expand Up @@ -524,24 +523,13 @@ impl CanisterManager {
}
},

Ok(Ic00Method::FetchCanisterLogs) => {
match canister_logging {
FlagStatus::Enabled => Err(UserError::new(
ErrorCode::CanisterRejectedMessage,
format!(
"{} API is only accessible in non-replicated mode",
Ic00Method::FetchCanisterLogs
),
)),
FlagStatus::Disabled => Err(UserError::new(
ErrorCode::CanisterContractViolation,
format!(
"{} API is not enabled on this subnet",
Ic00Method::FetchCanisterLogs
),
))
}
},
Ok(Ic00Method::FetchCanisterLogs) => Err(UserError::new(
ErrorCode::CanisterRejectedMessage,
format!(
"{} API is only accessible in non-replicated mode",
Ic00Method::FetchCanisterLogs
),
)),

Ok(Ic00Method::ProvisionalCreateCanisterWithCycles)
| Ok(Ic00Method::BitcoinGetSuccessors)
Expand Down
34 changes: 9 additions & 25 deletions rs/execution_environment/src/execution_environment.rs
Expand Up @@ -1230,30 +1230,15 @@ impl ExecutionEnvironment {
}
}

Ok(Ic00Method::FetchCanisterLogs) => match self.config.canister_logging {
FlagStatus::Enabled => ExecuteSubnetMessageResult::Finished {
response: Err(UserError::new(
ErrorCode::CanisterRejectedMessage,
format!(
"{} API is only accessible in non-replicated mode",
Ic00Method::FetchCanisterLogs
),
)),
refund: msg.take_cycles(),
},
FlagStatus::Disabled => {
let err = Err(UserError::new(
ErrorCode::CanisterContractViolation,
format!(
"{} API is not enabled on this subnet",
Ic00Method::FetchCanisterLogs
),
));
ExecuteSubnetMessageResult::Finished {
response: err,
refund: msg.take_cycles(),
}
}
Ok(Ic00Method::FetchCanisterLogs) => ExecuteSubnetMessageResult::Finished {
response: Err(UserError::new(
ErrorCode::CanisterRejectedMessage,
format!(
"{} API is only accessible in non-replicated mode",
Ic00Method::FetchCanisterLogs
),
)),
refund: msg.take_cycles(),
},

Ok(Ic00Method::TakeCanisterSnapshot) => match self.config.canister_snapshots {
Expand Down Expand Up @@ -2043,7 +2028,6 @@ impl ExecutionEnvironment {
provisional_whitelist,
ingress,
effective_canister_id,
self.config.canister_logging,
);
}

Expand Down
4 changes: 2 additions & 2 deletions rs/execution_environment/src/execution_environment/tests.rs
Expand Up @@ -3227,8 +3227,8 @@ fn test_fetch_canister_logs_should_accept_ingress_message_disabled() {
assert_eq!(
result,
Err(UserError::new(
ErrorCode::CanisterContractViolation,
"fetch_canister_logs API is not enabled on this subnet"
ErrorCode::CanisterRejectedMessage,
"fetch_canister_logs API is only accessible in non-replicated mode"
))
);
}
Expand Down
40 changes: 12 additions & 28 deletions rs/execution_environment/tests/canister_logging.rs
Expand Up @@ -75,22 +75,14 @@ fn restart_node(env: StateMachine, canister_logging: FlagStatus) -> StateMachine
#[test]
fn test_fetch_canister_logs_via_submit_ingress() {
// Test fetch_canister_logs API call results depending on the feature flag.
let error = Err(SubmitIngressError::UserError(UserError::new(
ErrorCode::CanisterRejectedMessage,
"fetch_canister_logs API is only accessible in non-replicated mode",
)));
let test_cases = vec![
// (feature flag, expected result)
(
FlagStatus::Disabled,
Err(SubmitIngressError::UserError(UserError::new(
ErrorCode::CanisterContractViolation,
"fetch_canister_logs API is not enabled on this subnet",
))),
),
(
FlagStatus::Enabled,
Err(SubmitIngressError::UserError(UserError::new(
ErrorCode::CanisterRejectedMessage,
"fetch_canister_logs API is only accessible in non-replicated mode",
))),
),
(FlagStatus::Disabled, error.clone()),
(FlagStatus::Enabled, error),
];
for (feature_flag, expected_result) in test_cases {
let (env, canister_id) = setup(
Expand All @@ -112,22 +104,14 @@ fn test_fetch_canister_logs_via_submit_ingress() {
#[test]
fn test_fetch_canister_logs_via_execute_ingress() {
// Test fetch_canister_logs API call results depending on the feature flag.
let error = Err(UserError::new(
ErrorCode::CanisterRejectedMessage,
"fetch_canister_logs API is only accessible in non-replicated mode",
));
let test_cases = vec![
// (feature flag, expected result)
(
FlagStatus::Disabled,
Err(UserError::new(
ErrorCode::CanisterContractViolation,
"fetch_canister_logs API is not enabled on this subnet",
)),
),
(
FlagStatus::Enabled,
Err(UserError::new(
ErrorCode::CanisterRejectedMessage,
"fetch_canister_logs API is only accessible in non-replicated mode",
)),
),
(FlagStatus::Disabled, error.clone()),
(FlagStatus::Enabled, error),
];
for (feature_flag, expected_result) in test_cases {
let (env, canister_id) = setup(
Expand Down

0 comments on commit 334bc60

Please sign in to comment.