Skip to content

Commit

Permalink
Add test for archive buffer limits (#2315)
Browse files Browse the repository at this point in the history
Add test for archive limits

This PR adds a test to check that the archive buffer limit is applied
correctly.
  • Loading branch information
Frederik Rothenberger authored Feb 27, 2024
1 parent facc954 commit 1eee740
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/internet_identity/tests/integration/archive_integration.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use crate::v2_api::authn_method_test_helpers::{
create_identity_with_authn_method, sample_webauthn_authn_method, test_authn_method,
};
use canister_tests::api::archive as archive_api;
use canister_tests::api::internet_identity as ii_api;
use canister_tests::api::internet_identity::api_v2;
use canister_tests::flows;
use canister_tests::framework::*;
use ic_cdk::api::management_canister::main::CanisterId;
Expand Down Expand Up @@ -949,4 +953,53 @@ mod pull_entries_tests {
.unwrap(),
);
}

#[test]
fn should_not_accept_changes_if_archive_buffer_full() {
let env = env();
let ii_canister = install_ii_canister_with_arg(
&env,
II_WASM.clone(),
Some(InternetIdentityInit {
archive_config: Some(ArchiveConfig {
module_hash: archive_wasm_hash(&ARCHIVE_WASM),
entries_buffer_limit: 3,
polling_interval_ns: 0,
entries_fetch_limit: 0,
}),
..InternetIdentityInit::default()
}),
);
let archive_canister = deploy_archive_via_ii(&env, ii_canister);
// stop the archive so that the entries start piling up in the buffer
env.stop_canister(archive_canister, Some(ii_canister))
.expect("failed to stop archive");

let authn_method = test_authn_method();
let identity = create_identity_with_authn_method(&env, ii_canister, &authn_method);
for i in 0..2 {
api_v2::authn_method_add(
&env,
ii_canister,
authn_method.principal(),
identity,
&sample_webauthn_authn_method(i + 1),
)
.expect("API call failed")
.expect("authn_method_add failed");
}

let result = api_v2::authn_method_add(
&env,
ii_canister,
authn_method.principal(),
identity,
&sample_webauthn_authn_method(3),
);
expect_user_error_with_message(
result,
CanisterCalledTrap,
Regex::new("cannot archive operation, archive entries buffer limit reached").unwrap(),
);
}
}

0 comments on commit 1eee740

Please sign in to comment.