Skip to content

Commit

Permalink
[fix] #3857: Add test to check token unification
Browse files Browse the repository at this point in the history
Signed-off-by: Shanin Roman <[email protected]>
  • Loading branch information
Erigara committed Jan 9, 2024
1 parent f147295 commit b14ad7b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client/tests/integration/connected_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn register_new_peer() -> Result<()> {
PeerBuilder::new()
.with_configuration(configuration)
.with_into_genesis(WithGenesis::None)
.with_port(11_200)
.with_port(11_225)
.start(),
);

Expand Down
36 changes: 36 additions & 0 deletions client/tests/integration/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,39 @@ fn stored_vs_granted_token_payload() -> Result<()> {

Ok(())
}

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

// Given
let alice_id = AccountId::from_str("alice@wonderland").expect("Valid");

let allow_alice_to_transfer_rose_1 = Grant::permission_token(
PermissionToken::from_str_unchecked(
"CanTransferUserAsset".parse().unwrap(),
// NOTE: Introduced additional whitespaces in the serialized form
"{ \"asset_id\" : \"rose#wonderland#alice@wonderland\" }",
),
alice_id.clone(),
);

let allow_alice_to_transfer_rose_2 = Grant::permission_token(
PermissionToken::from_str_unchecked(
"CanTransferUserAsset".parse().unwrap(),
// NOTE: Introduced additional whitespaces in the serialized form
"{ \"asset_id\" : \"rose##alice@wonderland\" }",
),
alice_id,
);

iroha_client
.submit_blocking(allow_alice_to_transfer_rose_1)
.expect("failed to grant permission token");

let _ = iroha_client
.submit_blocking(allow_alice_to_transfer_rose_2)
.expect_err("permission tokens are not unified");
}
39 changes: 39 additions & 0 deletions client/tests/integration/roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,42 @@ fn role_with_invalid_permissions_is_not_accepted() -> Result<()> {

Ok(())
}

#[test]
#[allow(deprecated)]
fn role_permissions_unified() {
let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(11_235).start_with_runtime();
wait_for_genesis_committed(&vec![test_client.clone()], 0);

let allow_alice_to_transfer_rose_1 = PermissionToken::from_str_unchecked(
"CanTransferUserAsset".parse().unwrap(),
// NOTE: Introduced additional whitespaces in the serialized form
"{ \"asset_id\" : \"rose#wonderland#alice@wonderland\" }",
);

let allow_alice_to_transfer_rose_2 = PermissionToken::from_str_unchecked(
"CanTransferUserAsset".parse().unwrap(),
// NOTE: Introduced additional whitespaces in the serialized form
"{ \"asset_id\" : \"rose##alice@wonderland\" }",
);

let role_id: RoleId = "role_id".parse().expect("Valid");
let role = Role::new(role_id.clone())
.add_permission(allow_alice_to_transfer_rose_1)
.add_permission(allow_alice_to_transfer_rose_2);

test_client
.submit_blocking(Register::role(role))
.expect("failed to register role");

let role = test_client
.request(FindRoleByRoleId::new(role_id))
.expect("failed to find role");

// Permission tokens are unified so only one token left
assert_eq!(
role.permissions().len(),
1,
"permission tokens for role aren't deduplicated"
);
}

0 comments on commit b14ad7b

Please sign in to comment.