Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions cedar-policy-validator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ wasm = ["serde-wasm-bindgen", "tsify", "wasm-bindgen"]
similar-asserts = "1.5.0"
cool_asserts = "2.0"
cedar-policy-core = { version = "=4.0.0", path = "../cedar-policy-core", features = ["test-util"] }
miette = { version = "7.1.0", features = ["fancy"] }

[build-dependencies]
lalrpop = "0.20.0"
2 changes: 1 addition & 1 deletion cedar-policy-validator/src/json_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl Display for CommonTypeId {
pub(crate) fn is_reserved_schema_keyword(id: &UnreservedId) -> bool {
matches!(
id.as_ref(),
"Set" | "Record" | "Entity" | "Extension" | "Long" | "String" | "Boolean"
"Bool" | "Boolean" | "Entity" | "Extension" | "Long" | "Record" | "Set" | "String"
)
}

Expand Down
50 changes: 42 additions & 8 deletions cedar-policy-validator/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2913,13 +2913,15 @@ pub(crate) mod test {
});
}

#[track_caller]
fn assert_invalid_json_schema(src: serde_json::Value) {
let schema = ValidatorSchema::from_json_value(src, Extensions::all_available());
assert_matches!(schema, Err(SchemaError::JsonDeserialization(e)) if e.to_smolstr().contains("Used reserved schema keyword"));
}

// Names like `Set`, `Record`, `Entity`, and Extension` are not allowed as common type names, as specified in #1070 and #1139.
#[test]
fn test_common_type_name_conflicts() {
let assert_invalid_json_schema = |src: serde_json::Value| {
let schema = ValidatorSchema::from_json_value(src, Extensions::all_available());
assert_matches!(schema, Err(SchemaError::JsonDeserialization(e)) if e.to_smolstr().contains("Used reserved schema keyword"));
};
// `Record` cannot be a common type name
let src: serde_json::Value = json!({
"": {
Expand Down Expand Up @@ -3332,6 +3334,38 @@ pub(crate) mod test {
}
});
assert_invalid_json_schema(src);

// Cedar examines common type name declarations eagerly.
// So it throws an error for the following example even though `Record`
// is not referenced.
let src: serde_json::Value = json!({
"": {
"commonTypes": {
"Record": {
"type": "Record",
"attributes": {
"a": {
"type": "Long",
}
}
}
},
"entityTypes": {
"b": {
"shape" : {
"type" : "Record",
"attributes" : {
"c" : {
"type" : "Long"
}
}
}
}
},
"actions": { },
}
});
assert_invalid_json_schema(src);
}

#[test]
Expand Down Expand Up @@ -4001,9 +4035,9 @@ mod test_rfc70 {
d: __cedar::Long,
};
namespace NS {
type Bool = Long;
type _Bool = Long;
entity F {
a: Bool,
a: _Bool,
b: __cedar::Bool,
c: Long,
d: __cedar::Long,
Expand Down Expand Up @@ -4101,14 +4135,14 @@ mod test_rfc70 {
},
"NS": {
"commonTypes": {
"Bool": { "type": "Long" },
"_Bool": { "type": "Long" },
},
"entityTypes": {
"F": {
"shape": {
"type": "Record",
"attributes": {
"a": { "type": "Bool" },
"a": { "type": "_Bool" },
"b": { "type": "__cedar::Bool" },
"c": { "type": "Long" },
"d": { "type": "__cedar::Long" },
Expand Down