From 8ade15490af13bdb00248f7b36aa80150fea1696 Mon Sep 17 00:00:00 2001 From: Craig Disselkoen Date: Tue, 1 Oct 2024 10:05:04 -0700 Subject: [PATCH] generate hasTag expressions (#447) Signed-off-by: Craig Disselkoen --- cedar-drt/Cargo.toml | 6 +++--- cedar-policy-generators/Cargo.toml | 4 ++-- cedar-policy-generators/src/expr.rs | 24 +++++++++++++++++++++++- cedar-policy-generators/src/hierarchy.rs | 1 + 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/cedar-drt/Cargo.toml b/cedar-drt/Cargo.toml index 8ce66ba2c..511b94c94 100644 --- a/cedar-drt/Cargo.toml +++ b/cedar-drt/Cargo.toml @@ -8,9 +8,9 @@ publish = false env_logger = "0.10" log = "0.4" libfuzzer-sys = "0.4" -cedar-policy = { path = "../cedar/cedar-policy", version = "4.*" } -cedar-policy-core = { path = "../cedar/cedar-policy-core", version = "4.*", features = ["arbitrary"] } -cedar-policy-validator = { path = "../cedar/cedar-policy-validator", version = "4.*", features = ["arbitrary"] } +cedar-policy = { path = "../cedar/cedar-policy", version = "4.*", features = ["entity-tags"] } +cedar-policy-core = { path = "../cedar/cedar-policy-core", version = "4.*", features = ["arbitrary", "entity-tags"] } +cedar-policy-validator = { path = "../cedar/cedar-policy-validator", version = "4.*", features = ["arbitrary", "entity-tags"] } cedar-policy-formatter = { path = "../cedar/cedar-policy-formatter", version = "4.*" } cedar-testing = { path = "../cedar/cedar-testing", version = "4.*" } lean-sys = { version = "0.0.7", features = ["small_allocator"], default-features = false } diff --git a/cedar-policy-generators/Cargo.toml b/cedar-policy-generators/Cargo.toml index 9548fd9bc..f58d06e3a 100644 --- a/cedar-policy-generators/Cargo.toml +++ b/cedar-policy-generators/Cargo.toml @@ -6,8 +6,8 @@ publish = false [dependencies] arbitrary = "1.3" -cedar-policy-core = { path = "../cedar/cedar-policy-core", version = "4.*", features = ["arbitrary"] } -cedar-policy-validator = { path = "../cedar/cedar-policy-validator", version = "4.*", features = ["arbitrary"] } +cedar-policy-core = { path = "../cedar/cedar-policy-core", version = "4.*", features = ["arbitrary", "entity-tags"] } +cedar-policy-validator = { path = "../cedar/cedar-policy-validator", version = "4.*", features = ["arbitrary", "entity-tags"] } clap = { version = "4.3.16", features = ["derive"] } highway = "0.8.1" serde = { version = "1.0", features = ["derive"] } diff --git a/cedar-policy-generators/src/expr.rs b/cedar-policy-generators/src/expr.rs index 557601998..fbe7bddd8 100644 --- a/cedar-policy-generators/src/expr.rs +++ b/cedar-policy-generators/src/expr.rs @@ -251,7 +251,16 @@ impl<'a> ExprGenerator<'a> { self.generate_expr(max_depth - 1, u)?, attr_name, )) - }) + }, + 4 => { + let tag_name = uniform!(u, + self.generate_expr(max_depth - 1, u)?, + ast::Expr::val(self.schema.arbitrary_attr(u)?.0.clone()) + ); + let e = self.generate_expr(max_depth - 1, u)?; + Ok(ast::Expr::has_tag(e, tag_name)) + } + ) }) } } @@ -583,6 +592,19 @@ impl<'a> ExprGenerator<'a> { )?, self.constant_pool.arbitrary_string_constant(u)?, )), + // hasTag expression on an entity, for an arbitrary tag name + 1 => Ok(ast::Expr::has_tag( + self.generate_expr_for_type( + &Type::entity(), + max_depth - 1, + u, + )?, + self.generate_expr_for_type( + &Type::string(), + max_depth - 1, + u, + )?, + )), // has expression on a record 2 => Ok(ast::Expr::has_attr( self.generate_expr_for_type( diff --git a/cedar-policy-generators/src/hierarchy.rs b/cedar-policy-generators/src/hierarchy.rs index 4a60765db..182772a48 100644 --- a/cedar-policy-generators/src/hierarchy.rs +++ b/cedar-policy-generators/src/hierarchy.rs @@ -656,6 +656,7 @@ impl<'a, 'u> HierarchyGenerator<'a, 'u> { uid.clone(), attrs.into_iter(), parents.into_iter().collect(), + [], &self.extensions, ) .map_err(|e| Error::EntitiesError(e.to_string()))?;