28 lines
850 B
Rust
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"),
|
|
}
|
|
}
|
|
|