Closed cdisselkoen closed 2 months ago
The entity record becomes the restricted expr: Record { attrs: {"extra": AttributeType { attr_type: String, required: false }, "foo": AttributeType { attr_type: Long, required: false }}, open_attrs: false }
We then check if actual_ty.is_consistent_with(expected_ty)
. This checks for required attrs
in one but not the other (assuming open
is false). Because the attrs
of actual_ty
are all optional, this actually only checks if actual_ty
has all required attrs
of expected_ty
.
I think we can fix this by just changing schematype_of_restricted_expr
to mark existing attrs
as required
. Contrary to the comments on that function, I think this makes sense. Consider the possibilities:
We check if SchemaType
of two concrete entities are consistent. This doesn't make sense and will always be true
because their attributes are optional.
We check if SchemaType
s from the schema are consistent. Here we know exactly which attributes are required/optional.
We check a concrete entity vs a SchemaType
from the schema. Here we get our desired behavior by making the attrs
required.
Because the attrs of actual_ty are all optional, this actually only checks if actual_ty has all required attrs of expected_ty.
See #382
Marking existing attrs as required seems plausible to me as long as they still .is_consistent_with()
a SchemaType
in which one or more of them are optional.
Marking attributes as required affects which sets are considered heterogeneous, which would be a breaking change. I made a new method for this instead.
Before opening, please confirm:
Bug Category
Schemas and Validation
Describe the bug
The documentation on
Entities::from_entities()
saysIn actuality, this function will not correctly error if inside a record-typed attribute, an (inner) superfluous attribute is provided.
Confirmed this behavior on
main
and 3.3.0 as of this writing. Doesn't seem to affectEntities::from_json_*()
because the JSON deserialization code does catch the superfluous inner attribute. For the same reason, this bug is not reproducible in the CLI (as far as I know). It only affects users ofEntities::from_entities()
who constructed entities programmatically.Expected behavior
Expected behavior to match the docs. Expected
Entities::from_entities()
to reject an entity with a superfluous inner attribute.Reproduction steps
The following works in an otherwise-blank Cargo project with dependency on
cedar_policy
3.3.0 (andmiette
7.2.0).Code Snippet
above
Log output
No response
Additional configuration
No response
Operating System
No response
Additional information and screenshots
No response