Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scripts to generate corpus #192

Merged
merged 10 commits into from
Jan 25, 2024
Merged

Add scripts to generate corpus #192

merged 10 commits into from
Jan 25, 2024

Conversation

khieta
Copy link
Contributor

@khieta khieta commented Jan 7, 2024

Issue #, if available:

Description of changes:

Added scripts to generate corpus files, towards solving cedar#552. Also included some minor refactoring + added support for logging corpus tests from the abac-type-directed targets and resolves #191.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@khieta
Copy link
Contributor Author

khieta commented Jan 25, 2024

Apologies for the delay in updating this PR! My latest commits resolve #191 and make the suggested changes to the scripts. I decided to leave the default timeout to 15 minutes for now -- I expect we'll change it in the future after we have more evidence about what timeout leads to the "best" corpus tests.

This PR will need to be merged after cedar#589.

Comment on lines 154 to 159
let mut responses = Vec::with_capacity(requests.len());
for request in requests.iter() {
let authorizer = Authorizer::new();
let response = authorizer.is_authorized(request.clone(), &policyset, &input.entities);
responses.push(response);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, would it be possible to share some of this code, which is currently duplicated. (doesn't have to be in this PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reformatted in the latest commit. I didn't deal with the code reuse, but you're right that would be cleaner

Comment on lines +135 to +141
/// Check whether a policy set can be successfully parsed
fn well_formed(policies: &PolicySet) -> bool {
policies
.static_policies()
.map(ToString::to_string)
.all(|p| Policy::from_str(&p).is_ok())
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it sufficent to check the .static_policies()? should we also check templates? is there an easy way to iterate over both static policies and templates?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current code only writes out the static policies because the relevant abac* targets only generate static policies. The general function is .policies().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

@khieta khieta merged commit a4817d0 into main Jan 25, 2024
3 checks passed
@khieta khieta deleted the khieta/corpus-scripts branch January 25, 2024 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reuse cedar-policy definitions for integration tests
5 participants