Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] #3962: Revoke associated tokens on entity unregistretration #4213

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions client/tests/integration/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use iroha_client::{
crypto::KeyPair,
data_model::prelude::*,
};
use iroha_data_model::permission::PermissionToken;
use iroha_genesis::GenesisNetwork;
use serde_json::json;
use test_network::{PeerBuilder, *};
Expand Down Expand Up @@ -381,3 +382,50 @@ fn permission_tokens_are_unified() {
.submit_blocking(allow_alice_to_transfer_rose_2)
.expect_err("permission tokens are not unified");
}

#[test]
fn associated_permission_tokens_removed_on_unregister() {
let (_rt, _peer, iroha_client) = <PeerBuilder>::new().with_port(11_240).start_with_runtime();
wait_for_genesis_committed(&[iroha_client.clone()], 0);

let bob_id: AccountId = "bob@wonderland".parse().expect("Valid");
let kingdom_id: DomainId = "kingdom".parse().expect("Valid");
Comment on lines +391 to +392
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we now discourage the use of expect("Valid") and prefer just unwrap()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was unaware of this, where it's stated?

let kingdom = Domain::new(kingdom_id.clone());

// register kingdom and give bob permissions in this domain
let register_domain = Register::domain(kingdom);
let bob_to_set_kv_in_domain_token = PermissionToken::new(
"CanSetKeyValueInDomain".parse().unwrap(),
&json!({ "domain_id": kingdom_id }),
);
let allow_bob_to_set_kv_in_domain =
Grant::permission(bob_to_set_kv_in_domain_token.clone(), bob_id.clone());

iroha_client
.submit_all_blocking([
InstructionBox::from(register_domain),
allow_bob_to_set_kv_in_domain.into(),
])
.expect("failed to register domain and grant permission");

// check that bob indeed have granted permission
assert!(iroha_client
.request(client::permission::by_account_id(bob_id.clone()))
.and_then(std::iter::Iterator::collect::<QueryResult<Vec<PermissionToken>>>)
.expect("failed to get permissions for bob")
.into_iter()
.any(|token| { token == bob_to_set_kv_in_domain_token }));

// unregister kingdom
iroha_client
.submit_blocking(Unregister::domain(kingdom_id))
.expect("failed to unregister domain");

// check that permission is removed from bob
assert!(iroha_client
.request(client::permission::by_account_id(bob_id))
.and_then(std::iter::Iterator::collect::<QueryResult<Vec<PermissionToken>>>)
.expect("failed to get permissions for bob")
.into_iter()
.all(|token| { token != bob_to_set_kv_in_domain_token }));
}
Binary file modified configs/peer/executor.wasm
Binary file not shown.
Loading
Loading