Skip to content

Commit

Permalink
Update to generate is operator
Browse files Browse the repository at this point in the history
Generators may generate `is` based on an `enable_is` flag. This is
disabled for differential testing because `is` is not modeled in dafny,
but it is enabled for property tests.
  • Loading branch information
john-h-kastner-aws committed Nov 8, 2023
1 parent b7c637a commit 25b4f31
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions cedar-drt/fuzz/fuzz_targets/abac-type-directed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const SETTINGS: ABACSettings = ABACSettings {
max_width: 3,
enable_additional_attributes: false,
enable_like: true,
enable_is: false,
enable_action_groups_and_attrs: true,
enable_arbitrary_func_call: true,
enable_unknowns: false,
Expand Down
1 change: 1 addition & 0 deletions cedar-drt/fuzz/fuzz_targets/abac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const SETTINGS: ABACSettings = ABACSettings {
max_width: 7,
enable_additional_attributes: false,
enable_like: true,
enable_is: false,
// ABAC fuzzing restricts the use of action because it is used to generate
// the corpus tests which will be run on Cedar and CedarCLI.
// These packages only expose the restricted action behavior.
Expand Down
1 change: 1 addition & 0 deletions cedar-drt/fuzz/fuzz_targets/eval-type-directed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const SETTINGS: ABACSettings = ABACSettings {
max_width: 3,
enable_additional_attributes: false,
enable_like: true,
enable_is: false,
enable_action_groups_and_attrs: true,
enable_arbitrary_func_call: true,
enable_unknowns: false,
Expand Down
1 change: 1 addition & 0 deletions cedar-drt/fuzz/fuzz_targets/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const SETTINGS: ABACSettings = ABACSettings {
max_width: 7,
enable_additional_attributes: true,
enable_like: true,
enable_is: true,
enable_action_groups_and_attrs: true,
enable_arbitrary_func_call: false,
enable_unknowns: false,
Expand Down
1 change: 1 addition & 0 deletions cedar-drt/fuzz/fuzz_targets/partial-eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const SETTINGS: ABACSettings = ABACSettings {
max_width: 3,
enable_additional_attributes: false,
enable_like: true,
enable_is: true,
enable_action_groups_and_attrs: true,
enable_arbitrary_func_call: true,
enable_unknowns: true,
Expand Down
1 change: 1 addition & 0 deletions cedar-drt/fuzz/fuzz_targets/pp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const SETTINGS: ABACSettings = ABACSettings {
max_width: 7,
enable_additional_attributes: true,
enable_like: true,
enable_is: true,
enable_action_groups_and_attrs: true,
enable_arbitrary_func_call: false,
enable_unknowns: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const SETTINGS: ABACSettings = ABACSettings {
max_width: 7,
enable_additional_attributes: true,
enable_like: true,
enable_is: false,
enable_action_groups_and_attrs: true,
enable_arbitrary_func_call: true,
enable_unknowns: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const SETTINGS: ABACSettings = ABACSettings {
max_width: 7,
enable_additional_attributes: true,
enable_like: true,
enable_is: false,
enable_action_groups_and_attrs: true,
enable_arbitrary_func_call: true,
enable_unknowns: false,
Expand Down
1 change: 1 addition & 0 deletions cedar-drt/fuzz/fuzz_targets/validation-drt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const SETTINGS: ABACSettings = ABACSettings {
max_width: 7,
enable_additional_attributes: true,
enable_like: true,
enable_is: false,
enable_action_groups_and_attrs: true,
enable_arbitrary_func_call: true,
enable_unknowns: false,
Expand Down
4 changes: 4 additions & 0 deletions cedar-drt/fuzz/fuzz_targets/validation-pbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const SETTINGS: ABACSettings = ABACSettings {
max_width: 7,
enable_additional_attributes: true,
enable_like: true,
enable_is: true,
enable_action_groups_and_attrs: true,
enable_arbitrary_func_call: true,
enable_unknowns: false,
Expand Down Expand Up @@ -143,6 +144,9 @@ fn log_err<T>(res: Result<T>, doing_what: &str) -> Result<T> {
Err(Error::LikeDisabled) => {
checkpoint(LOG_FILENAME_ERR_LIKE_DISABLED.to_string() + "_" + doing_what)
}
Err(Error::IsDisabled) => {
checkpoint(LOG_FILENAME_ERR_LIKE_DISABLED.to_string() + "_" + doing_what)
}
Err(Error::IncorrectFormat {
doing_what: doing_2,
}) => checkpoint(
Expand Down
4 changes: 4 additions & 0 deletions cedar-policy-generators/src/err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ pub enum Error {
/// Tried to generate something using the `like` operator, but the `like`
/// operator was disabled in settings
LikeDisabled,
/// Tried to generate something using the `is` operator, but the `is`
/// operator was disabled in settings
IsDisabled,
/// `IncorrectFormat` error that was generated by the `arbitrary` crate directly.
/// We try to maintain the invariant that we don't generate these ourselves,
/// preferring the more specific errors above
Expand Down Expand Up @@ -67,6 +70,7 @@ impl From<Error> for arbitrary::Error {
Error::NoValidPrincipalOrResourceTypes => arbitrary::Error::IncorrectFormat,
Error::ExtensionsDisabled => arbitrary::Error::IncorrectFormat,
Error::LikeDisabled => arbitrary::Error::IncorrectFormat,
Error::IsDisabled => arbitrary::Error::IncorrectFormat,
Error::EntitiesError(_) => arbitrary::Error::IncorrectFormat,
Error::IncorrectFormat { .. } => arbitrary::Error::IncorrectFormat,
Error::OtherArbitrary(e) => e,
Expand Down
25 changes: 25 additions & 0 deletions cedar-policy-generators/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ impl<'a> ExprGenerator<'a> {
Err(Error::LikeDisabled)
}
},
1 => {
if self.settings.enable_is {
Ok(ast::Expr::is_entity_type(
self.generate_expr(max_depth - 1, u)?,
u.choose(&self.schema.entity_types)?.clone(),
))
} else {
Err(Error::IsDisabled)
}
},
1 => {
let mut l = Vec::new();
u.arbitrary_loop(Some(0), Some(self.settings.max_width as u32), |u| {
Expand Down Expand Up @@ -472,6 +482,21 @@ impl<'a> ExprGenerator<'a> {
Err(Error::LikeDisabled)
}
},
// is
2 => {
if self.settings.enable_is {
Ok(ast::Expr::is_entity_type(
self.generate_expr_for_type(
&Type::entity(),
max_depth - 1,
u,
)?,
u.choose(&self.schema.entity_types)?.clone(),
))
} else {
Err(Error::LikeDisabled)
}
},
// extension function that returns bool
2 => self.generate_ext_func_call_for_type(
&Type::bool(),
Expand Down
1 change: 1 addition & 0 deletions cedar-policy-generators/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl From<&HierarchyArgs> for ABACSettings {
max_width: value.max_width,
enable_additional_attributes: false,
enable_like: true,
enable_is: true,
enable_action_groups_and_attrs: true,
enable_arbitrary_func_call: false,
enable_unknowns: false,
Expand Down
1 change: 1 addition & 0 deletions cedar-policy-generators/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,7 @@ mod tests {
max_width: 4,
enable_additional_attributes: false,
enable_like: false,
enable_is: false,
enable_action_groups_and_attrs: true,
enable_arbitrary_func_call: false,
enable_unknowns: false,
Expand Down
3 changes: 3 additions & 0 deletions cedar-policy-generators/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ pub struct ABACSettings {
/// Flag to globally enable/disable generation of expressions containing the
/// `like` operator.
pub enable_like: bool,
/// Flag to globally enable/disable generation of expressions containing the
/// `is` operator.
pub enable_is: bool,
/// Flag to enable/disable generating actions in groups and declaring
/// attributes on entity types.
pub enable_action_groups_and_attrs: bool,
Expand Down

0 comments on commit 25b4f31

Please sign in to comment.