Skip to content

Commit

Permalink
squash! fixup! improv: Check reference prop types for all customs
Browse files Browse the repository at this point in the history
Fix property dictionary emptiness check for custom extensions. Neither
`_properties` or `_top_level_properties` (if provided) may be empty.
  • Loading branch information
maybe-sybr committed Jul 16, 2021
1 parent 99e8bdd commit 6b89520
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions stix2/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,22 @@ def _register_extension(
ext_type,
)

# Need to check both toplevel and nested properties
combined_props = {
**new_extension._properties,
**getattr(new_extension, "_toplevel_properties", dict()),
}
if not combined_props:
tl_props = getattr(new_extension, "_toplevel_properties", None)
if any((
# There must always be at least one property in an extension. This
# holds for instances of both custom object extensions which must
# contain one or more custom properties, and `extension-definition`s
# which must contain an `extension_type` property.
not new_extension._properties,
# If a top-level properties mapping is provided, it cannot be empty
tl_props is not None and not tl_props,
)):
raise ValueError(
"Invalid extension: must define at least one property: " +
ext_type,
)
# We need to validate all properties related to this extension
combined_props = dict(new_extension._properties, **(tl_props or dict()))
_validate_props(combined_props, version)

EXT_MAP = registry.STIX2_OBJ_MAPS[version]['extensions']
Expand Down

0 comments on commit 6b89520

Please sign in to comment.