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

cherry pick from 2.4.x to main #342

Merged
merged 4 commits into from
Oct 5, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ fn scenario_4a() {
// note: 4b currently omitted because it requires date/timestamp functionality

/// currently failing, as the validator does not support action attributes
#[should_panic]
#[should_panic(
expected = "error occurred while evaluating policy `policy0`: `Action::\\\"view\\\"` does not have the attribute `readOnly`"
)]
#[test]
fn scenario_4c() {
perform_integration_test_from_json(folder().join("4c.json"));
Expand Down
2 changes: 1 addition & 1 deletion cedar-policy-core/src/ast/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ impl Eq for ExtensionValueWithArgs {}

impl PartialOrd for ExtensionValueWithArgs {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.value.partial_cmp(&other.value)
Some(self.cmp(other))
}
}

Expand Down
4 changes: 1 addition & 3 deletions cedar-policy-core/src/ast/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,7 @@ impl Eq for Set {}
// HashSet doesn't implement PartialOrd
impl PartialOrd<Set> for Set {
fn partial_cmp(&self, other: &Set) -> Option<std::cmp::Ordering> {
self.authoritative
.as_ref()
.partial_cmp(other.authoritative.as_ref())
Some(self.cmp(other))
}
}

Expand Down
13 changes: 10 additions & 3 deletions cedar-policy-core/src/parser/text_to_cst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,7 @@ mod tests {
assert!(policy.is_ok());
}

#[test]
#[should_panic] // we no longer support structs
#[test] // we no longer support named structs
fn member7() {
let policy = parse_policy(
r#"
Expand All @@ -346,7 +345,15 @@ mod tests {
};
"#,
);
assert!(policy.is_ok());
let errs = match policy.err() {
Some(pes) => pes,
_ => panic!("Expected parsing policy to error"),
};
assert!(errs.len() == 2);
assert!(format!("{:?}", errs[0])
.contains("ToCST(ToCSTError { err: UnrecognizedToken { token: (98, \"{\", 99)"));
assert!(format!("{:?}", errs[1])
.contains("ToCST(ToCSTError { err: UnrecognizedToken { token: (141, \"}\", 142)"));
}

#[test]
Expand Down
12 changes: 6 additions & 6 deletions cedar-policy-validator/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2629,7 +2629,6 @@ mod test {
}

#[test]
#[should_panic]
fn cross_fragment_duplicate_type() {
let fragment1: ValidatorSchemaFragment = serde_json::from_value::<SchemaFragment>(json!({
"A": {
Expand All @@ -2655,12 +2654,13 @@ mod test {
.unwrap()
.try_into()
.unwrap();
let schema = ValidatorSchema::from_schema_fragments([fragment1, fragment2]).unwrap();

assert_eq!(
schema.entity_types.iter().next().unwrap().1.attributes,
Attributes::with_required_attributes([("a".into(), Type::primitive_long())])
);
let schema = ValidatorSchema::from_schema_fragments([fragment1, fragment2]);

match schema {
Err(SchemaError::DuplicateCommonType(s)) if s.contains("A::MyLong") => (),
_ => panic!("should have errored because schema fragments have duplicate types"),
};
}

#[test]
Expand Down
4 changes: 4 additions & 0 deletions cedar-policy/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,10 @@ impl Default for Authorizer {

impl Authorizer {
/// Create a new `Authorizer`
///
/// The authorizer uses the `stacker` crate to manage stack size and tries to use a sane default.
/// If the default is not right for you, you can try wrapping the authorizer or individual calls
/// to `is_authorized` in `stacker::grow`.
/// ```
/// # use cedar_policy::{Authorizer, Context, Entities, EntityId, EntityTypeName,
/// # EntityUid, Request,PolicySet};
Expand Down
4 changes: 3 additions & 1 deletion cedar-policy/tests/example_use_cases_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ fn scenario_4a() {
// note: 4b currently omitted because it requires date/timestamp functionality

/// currently failing, as the validator does not support action attributes
#[should_panic]
#[should_panic(
expected = "error occurred while evaluating policy `policy0`: entity `Action::\\\"view\\\"` does not exist"
)]
#[test]
fn scenario_4c() {
perform_integration_test_from_json(folder().join("4c.json"));
Expand Down