Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -912,10 +912,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 @@ -4108,6 +4105,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 @@ -4128,6 +4167,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 @@ -4143,6 +4188,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 @@ -54,6 +54,9 @@ method checks the request against the schema provided and the
the transitive closure to be pre-computed. (#581, resolving #285)
- Variables qualified by a namespace with a single element are correctly
rejected. E.g., `foo::principal` is an error and is not parsed as `principal`.
- 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