diff --git a/stix2/test/v21/test_deterministic_ids.py b/stix2/test/v21/test_deterministic_ids.py index 1140de7f..854ddd0b 100644 --- a/stix2/test/v21/test_deterministic_ids.py +++ b/stix2/test/v21/test_deterministic_ids.py @@ -7,9 +7,9 @@ import stix2.base import stix2.canonicalization.Canonicalize from stix2.properties import ( - BooleanProperty, DictionaryProperty, ExtensionsProperty, FloatProperty, - IDProperty, IntegerProperty, ListProperty, StringProperty, - TimestampProperty, TypeProperty, + BooleanProperty, DictionaryProperty, EmbeddedObjectProperty, + ExtensionsProperty, FloatProperty, IDProperty, IntegerProperty, + ListProperty, StringProperty, TimestampProperty, TypeProperty, ) import stix2.v21.base @@ -151,3 +151,40 @@ class SomeSCO(stix2.v21.base._Observable): actual_uuid5 = _uuid_from_id(sco["id"]) assert actual_uuid5 == expected_uuid5 + + +def test_embedded_object(): + class SubObj(stix2.base._STIXBase): + _type = "sub-object" + _properties = OrderedDict(( + ('value', StringProperty()), + )) + + class SomeSCO(stix2.v21.base._Observable): + _type = "some-sco" + _properties = OrderedDict(( + ('type', TypeProperty(_type, spec_version='2.1')), + ('id', IDProperty(_type, spec_version='2.1')), + ( + 'extensions', ExtensionsProperty( + spec_version='2.1', enclosing_type=_type, + ), + ), + ('sub_obj', EmbeddedObjectProperty(type=SubObj)), + )) + _id_contributing_properties = ['sub_obj'] + + sub_obj = SubObj(value="foo") + sco = SomeSCO(sub_obj=sub_obj) + + obj = { + "sub_obj": { + "value": "foo", + }, + } + + can_json = stix2.canonicalization.Canonicalize.canonicalize(obj, utf8=False) + expected_uuid5 = _make_uuid5(can_json) + actual_uuid5 = _uuid_from_id(sco["id"]) + + assert actual_uuid5 == expected_uuid5