Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 58 additions & 4 deletions cedar-policy-core/src/parser/cst_to_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,10 +901,7 @@ impl ExprOrSpecial<'_> {
errs.push(self.to_ast_err(ToASTErrorKind::IsInvalidName(lit.to_string())));
None
}
Self::Var { var, .. } => {
errs.push(self.to_ast_err(ToASTErrorKind::IsInvalidName(var.to_string())));
None
}
Self::Var { var, .. } => Some(ast::Name::unqualified_name(var.into())),
Self::Name { name, .. } => Some(name),
Self::Expr { ref expr, .. } => {
errs.push(self.to_ast_err(ToASTErrorKind::IsInvalidName(expr.to_string())));
Expand Down Expand Up @@ -4098,6 +4095,48 @@ mod tests {
Expr::val(2),
),
),
(
r#"principal::"alice" is principal"#,
Expr::is_entity_type(
Expr::val(r#"principal::"alice""#.parse::<EntityUID>().unwrap()),
"principal".parse().unwrap(),
),
),
(
r#"foo::principal::"alice" is foo::principal"#,
Expr::is_entity_type(
Expr::val(r#"foo::principal::"alice""#.parse::<EntityUID>().unwrap()),
"foo::principal".parse().unwrap(),
),
),
(
r#"principal::foo::"alice" is principal::foo"#,
Expr::is_entity_type(
Expr::val(r#"principal::foo::"alice""#.parse::<EntityUID>().unwrap()),
"principal::foo".parse().unwrap(),
),
),
(
r#"resource::"thing" is resource"#,
Expr::is_entity_type(
Expr::val(r#"resource::"thing""#.parse::<EntityUID>().unwrap()),
"resource".parse().unwrap(),
),
),
(
r#"action::"do" is action"#,
Expr::is_entity_type(
Expr::val(r#"action::"do""#.parse::<EntityUID>().unwrap()),
"action".parse().unwrap(),
),
),
(
r#"context::"stuff" is context"#,
Expr::is_entity_type(
Expr::val(r#"context::"stuff""#.parse::<EntityUID>().unwrap()),
"context".parse().unwrap(),
),
),
] {
let e = parse_expr(es).unwrap();
assert!(
Expand All @@ -4118,6 +4157,12 @@ mod tests {
ActionConstraint::any(),
ResourceConstraint::any(),
),
(
r#"permit(principal is principal, action, resource);"#,
PrincipalConstraint::is_entity_type("principal".parse().unwrap()),
ActionConstraint::any(),
ResourceConstraint::any(),
),
(
r#"permit(principal is A::User, action, resource);"#,
PrincipalConstraint::is_entity_type("A::User".parse().unwrap()),
Expand All @@ -4133,6 +4178,15 @@ mod tests {
ActionConstraint::any(),
ResourceConstraint::any(),
),
(
r#"permit(principal is principal in Group::"thing", action, resource);"#,
PrincipalConstraint::is_entity_type_in(
"principal".parse().unwrap(),
r#"Group::"thing""#.parse().unwrap(),
),
ActionConstraint::any(),
ResourceConstraint::any(),
),
(
r#"permit(principal is A::User in Group::"thing", action, resource);"#,
PrincipalConstraint::is_entity_type_in(
Expand Down
3 changes: 3 additions & 0 deletions cedar-policy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ method checks the request against the schema provided and the
`principal`. Variables qualified by a namespace of any size comprised entirely
of Cedar keywords are correctly rejected. E.g., `if::then::else::principal` is an error.
(#594 and #596)
- The entity type tested for by an `is` expression may be an identifier shared
with a builtin variable. E.g., `... is principal` and `... is action` are now
accepted by the Cedar parser. (#558)

## [3.0.1] - 2023-12-21
Cedar Language Version: 3.0.0
Expand Down