diff --git a/src/adapter.rs b/src/adapter.rs index 0b27d95..9287f93 100644 --- a/src/adapter.rs +++ b/src/adapter.rs @@ -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",