Skip to content

Commit 5df50cd

Browse files
Aaron Elinekhieta
authored andcommitted
Fixing #580 (Fully qualify common types in error messages) (#652)
1 parent 64f2258 commit 5df50cd

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

cedar-policy-validator/src/schema.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,4 +1972,72 @@ mod test {
19721972
"ExampleCo::Personnel::Action"
19731973
);
19741974
}
1975+
1976+
#[test]
1977+
fn qualified_undeclared_common_types() {
1978+
let src = json!(
1979+
{
1980+
"Demo": {
1981+
"entityTypes": {
1982+
"User": {
1983+
"memberOfTypes": [],
1984+
"shape": {
1985+
"type": "Record",
1986+
"attributes": {
1987+
"id": { "type": "id" },
1988+
}
1989+
}
1990+
}
1991+
},
1992+
"actions": {}
1993+
},
1994+
"": {
1995+
"commonTypes": {
1996+
"id": {
1997+
"type": "String"
1998+
},
1999+
},
2000+
"entityTypes": {},
2001+
"actions": {}
2002+
}
2003+
}
2004+
);
2005+
let schema = ValidatorSchema::from_json_value(src, Extensions::all_available());
2006+
assert_matches!(schema, Err(SchemaError::UndeclaredCommonTypes(types)) =>
2007+
assert_eq!(types, HashSet::from(["Demo::id".to_string()])));
2008+
}
2009+
2010+
#[test]
2011+
fn qualified_undeclared_common_types2() {
2012+
let src = json!(
2013+
{
2014+
"Demo": {
2015+
"entityTypes": {
2016+
"User": {
2017+
"memberOfTypes": [],
2018+
"shape": {
2019+
"type": "Record",
2020+
"attributes": {
2021+
"id": { "type": "Demo::id" },
2022+
}
2023+
}
2024+
}
2025+
},
2026+
"actions": {}
2027+
},
2028+
"": {
2029+
"commonTypes": {
2030+
"id": {
2031+
"type": "String"
2032+
},
2033+
},
2034+
"entityTypes": {},
2035+
"actions": {}
2036+
}
2037+
}
2038+
);
2039+
let schema = ValidatorSchema::from_json_value(src, Extensions::all_available());
2040+
assert_matches!(schema, Err(SchemaError::UndeclaredCommonTypes(types)) =>
2041+
assert_eq!(types, HashSet::from(["Demo::id".to_string()])));
2042+
}
19752043
}

cedar-policy-validator/src/schema/namespace_def.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,9 @@ impl ValidatorNamespaceDef {
722722
.map_err(SchemaError::ParseCommonType)?;
723723
Ok(WithUnresolvedTypeDefs::new(move |typ_defs| {
724724
typ_defs.get(&defined_type_name).cloned().ok_or(
725-
SchemaError::UndeclaredCommonTypes(HashSet::from([type_name.to_string()])),
725+
SchemaError::UndeclaredCommonTypes(HashSet::from([
726+
defined_type_name.to_string()
727+
])),
726728
)
727729
}))
728730
}

cedar-policy/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Cedar Language Version: 3.1.0
2222

2323
### Changed
2424

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

0 commit comments

Comments
 (0)