Skip to content

Commit

Permalink
test(Acl): extend coverage (Near-One#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
mooori authored Mar 10, 2023
1 parent 8619c33 commit d37bd5c
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions near-plugins-derive/tests/access_controllable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,20 +447,61 @@ async fn test_super_admin_may_revoke_any_admin() -> anyhow::Result<()> {
.assert_acl_is_admin(false, role, admin.id())
.await;
}

Ok(())
}

/// Verify that a super-admin may grant every role.
#[tokio::test]
async fn test_super_admin_may_grant_any_role() -> anyhow::Result<()> {
// TODO once acl_grant_role is implemented
let setup = Setup::new().await?;
let super_admin = setup.new_super_admin_account().await?;

for role in ALL_ROLES {
let account = setup.worker.dev_create_account().await?;
setup
.contract
.assert_acl_has_role(false, role, account.id())
.await;

let res = setup
.contract
.acl_grant_role(&super_admin, role, account.id())
.await?;
assert_eq!(res, Some(true));
setup
.contract
.assert_acl_has_role(true, role, account.id())
.await;
}

Ok(())
}

/// Verify that a super-admin may revoke every role.
#[tokio::test]
async fn test_super_admin_may_revoke_any_role() -> anyhow::Result<()> {
// TODO once acl_revoke_role is implemented
let setup = Setup::new().await?;
let super_admin = setup.new_super_admin_account().await?;

for role in ALL_ROLES {
let grantee = setup.new_account_with_roles(&[role]).await?;
setup
.contract
.assert_acl_has_role(true, role, grantee.id())
.await;

let res = setup
.contract
.acl_revoke_role(&super_admin, role, grantee.id())
.await?;
assert_eq!(res, Some(true));
setup
.contract
.assert_acl_has_role(false, role, grantee.id())
.await;
}

Ok(())
}

Expand Down

0 comments on commit d37bd5c

Please sign in to comment.