Skip to content
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
68 changes: 68 additions & 0 deletions cedar-policy-validator/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1972,4 +1972,72 @@ mod test {
"ExampleCo::Personnel::Action"
);
}

#[test]
fn qualified_undeclared_common_types() {
let src = json!(
{
"Demo": {
"entityTypes": {
"User": {
"memberOfTypes": [],
"shape": {
"type": "Record",
"attributes": {
"id": { "type": "id" },
}
}
}
},
"actions": {}
},
"": {
"commonTypes": {
"id": {
"type": "String"
},
},
"entityTypes": {},
"actions": {}
}
}
);
let schema = ValidatorSchema::from_json_value(src, Extensions::all_available());
assert_matches!(schema, Err(SchemaError::UndeclaredCommonTypes(types)) =>
assert_eq!(types, HashSet::from(["Demo::id".to_string()])));
}

#[test]
fn qualified_undeclared_common_types2() {
let src = json!(
{
"Demo": {
"entityTypes": {
"User": {
"memberOfTypes": [],
"shape": {
"type": "Record",
"attributes": {
"id": { "type": "Demo::id" },
}
}
}
},
"actions": {}
},
"": {
"commonTypes": {
"id": {
"type": "String"
},
},
"entityTypes": {},
"actions": {}
}
}
);
let schema = ValidatorSchema::from_json_value(src, Extensions::all_available());
assert_matches!(schema, Err(SchemaError::UndeclaredCommonTypes(types)) =>
assert_eq!(types, HashSet::from(["Demo::id".to_string()])));
}
}
4 changes: 3 additions & 1 deletion cedar-policy-validator/src/schema/namespace_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,9 @@ impl ValidatorNamespaceDef {
.map_err(SchemaError::ParseCommonType)?;
Ok(WithUnresolvedTypeDefs::new(move |typ_defs| {
typ_defs.get(&defined_type_name).cloned().ok_or(
SchemaError::UndeclaredCommonTypes(HashSet::from([type_name.to_string()])),
SchemaError::UndeclaredCommonTypes(HashSet::from([
defined_type_name.to_string()
])),
)
}))
}
Expand Down
2 changes: 2 additions & 0 deletions cedar-policy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Changed error message on `SchemaError::UndeclaredCommonTypes` to report
fully qualified type names. (#652, resolving #580)
- Better integration with `miette` for various error types. If you have
previously been just using the `Display` trait to get the error message from a
Cedar error type, you may want to consider also examining other data provided
Expand Down