diff --git a/stix2/markings/object_markings.py b/stix2/markings/object_markings.py index c0375c3..563d92b 100644 --- a/stix2/markings/object_markings.py +++ b/stix2/markings/object_markings.py @@ -37,7 +37,7 @@ def add_markings(obj, marking): object_markings = set(obj.get("object_marking_refs", []) + marking) - return new_version(obj, object_marking_refs=list(object_markings)) + return new_version(obj, object_marking_refs=list(object_markings), allow_custom=True) def remove_markings(obj, marking): diff --git a/stix2/test/test_custom.py b/stix2/test/test_custom.py index 7c1832b..df0db79 100644 --- a/stix2/test/test_custom.py +++ b/stix2/test/test_custom.py @@ -2,7 +2,7 @@ import pytest import stix2 -from .constants import FAKE_TIME +from .constants import FAKE_TIME, MARKING_DEFINITION_ID def test_identity_custom_property(): @@ -94,6 +94,25 @@ def test_custom_property_in_bundled_object(): assert '"x_foo": "bar"' in str(bundle) +def test_identity_custom_property_add_marking(): + identity = stix2.Identity( + id="identity--311b2d2d-f010-5473-83ec-1edf84858f4c", + created="2015-12-21T19:59:11Z", + modified="2015-12-21T19:59:11Z", + name="John Smith", + identity_class="individual", + x_foo="bar", + allow_custom=True, + ) + marking_definition = stix2.MarkingDefinition( + id=MARKING_DEFINITION_ID, + definition_type="statement", + definition=stix2.StatementMarking(statement="Copyright 2016, Example Corp") + ) + identity2 = identity.add_markings(marking_definition) + assert identity2.x_foo == "bar" + + def test_custom_marking_no_init_1(): @stix2.CustomMarking('x-new-obj', [ ('property1', stix2.properties.StringProperty(required=True)),