Skip to content

Commit

Permalink
test: add tests for remove_filtered_policy
Browse files Browse the repository at this point in the history
  • Loading branch information
zbrox committed Feb 21, 2024
1 parent 06fd241 commit adff2f3
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,56 @@ mod tests {
.unwrap());
assert_eq!(vec![String::new(); 0], e.get_roles_for_user("carol", None));

// GitHub issue: https://github.com/casbin-rs/sqlx-adapter/pull/90
// add policies:
// p, alice_rfp, book_rfp, read_rfp
// p, bob_rfp, book_rfp, read_rfp
// p, bob_rfp, book_rfp, write_rfp
// p, alice_rfp, pen_rfp, get_rfp
// p, bob_rfp, pen_rfp, get_rfp
// p, alice_rfp, pencil_rfp, get_rfp
assert!(adapter
.add_policy("", "p", to_owned(vec!["alice_rfp", "book_rfp", "read_rfp"]),)
.await
.is_ok());
assert!(adapter
.add_policy("", "p", to_owned(vec!["bob_rfp", "book_rfp", "read_rfp"]),)
.await
.is_ok());
assert!(adapter
.add_policy("", "p", to_owned(vec!["bob_rfp", "book_rfp", "write_rfp"]),)
.await
.is_ok());
assert!(adapter
.add_policy("", "p", to_owned(vec!["alice_rfp", "pen_rfp", "get_rfp"]),)
.await
.is_ok());
assert!(adapter
.add_policy("", "p", to_owned(vec!["bob_rfp", "pen_rfp", "get_rfp"]),)
.await
.is_ok());
assert!(adapter
.add_policy(
"",
"p",
to_owned(vec!["alice_rfp", "pencil_rfp", "get_rfp"]),
)
.await
.is_ok());

// should remove (return true) all policies where "book_rfp" is in the second position
assert!(adapter
.remove_filtered_policy("", "p", 1, to_owned(vec!["book_rfp"]),)
.await
.unwrap());

// should remove (return true) all policies which match "alice_rfp" on first position
// and "get_rfp" on third position
assert!(adapter
.remove_filtered_policy("", "p", 0, to_owned(vec!["alice_rfp", "", "get_rfp"]),)
.await
.unwrap());

// shadow the previous enforcer
let mut e = Enforcer::new(
"examples/rbac_with_domains_model.conf",
Expand Down

0 comments on commit adff2f3

Please sign in to comment.