Files
iam-service/tests/authorization_expr.rs
2026-02-11 10:55:26 +08:00

28 lines
850 B
Rust

use iam_service::models::{AuthorizationExprCheckRequest, PermissionExpr};
#[test]
fn deserialize_any_expr() {
let json = r#"{ "expr": { "any": ["cms:article:edit", "cms:article:create"] } }"#;
let parsed: AuthorizationExprCheckRequest = serde_json::from_str(json).unwrap();
match parsed.expr {
PermissionExpr::Any(x) => {
assert_eq!(x.any.len(), 2);
}
_ => panic!("expected any"),
}
}
#[test]
fn deserialize_nested_expr() {
let json =
r#"{ "expr": { "all": ["cms:article:edit", { "any": ["cms:article:create", "cms:article:publish"] }] } }"#;
let parsed: AuthorizationExprCheckRequest = serde_json::from_str(json).unwrap();
match parsed.expr {
PermissionExpr::All(x) => {
assert_eq!(x.all.len(), 2);
}
_ => panic!("expected all"),
}
}