Don't try to re-parse STIX Objects when adding to Bundle.
parent
09ef9353fc
commit
374539a6cc
|
@ -7,9 +7,9 @@ from .base import _STIXBase
|
|||
from .common import MarkingDefinition
|
||||
from .properties import IDProperty, ListProperty, Property, TypeProperty
|
||||
from .sdo import (AttackPattern, Campaign, CourseOfAction, Identity, Indicator,
|
||||
IntrusionSet, Malware, ObservedData, Report, ThreatActor,
|
||||
Tool, Vulnerability)
|
||||
from .sro import Relationship, Sighting
|
||||
IntrusionSet, Malware, ObservedData, Report,
|
||||
STIXDomainObject, ThreatActor, Tool, Vulnerability)
|
||||
from .sro import Relationship, Sighting, STIXRelationshipObject
|
||||
from .utils import get_dict
|
||||
|
||||
|
||||
|
@ -20,6 +20,11 @@ class STIXObjectProperty(Property):
|
|||
super(STIXObjectProperty, self).__init__()
|
||||
|
||||
def clean(self, value):
|
||||
# Any STIX Object (SDO, SRO, or Marking Definition) can be added to
|
||||
# a bundle with no further checks.
|
||||
if isinstance(value, (STIXDomainObject, STIXRelationshipObject,
|
||||
MarkingDefinition)):
|
||||
return value
|
||||
try:
|
||||
dictified = get_dict(value)
|
||||
except ValueError:
|
||||
|
|
|
@ -158,3 +158,11 @@ def test_parse_unknown_type():
|
|||
with pytest.raises(stix2.exceptions.ParseError) as excinfo:
|
||||
stix2.parse(unknown)
|
||||
assert str(excinfo.value) == "Can't parse unknown object type 'other'! For custom types, use the CustomObject decorator."
|
||||
|
||||
|
||||
def test_stix_object_property():
|
||||
prop = stix2.core.STIXObjectProperty()
|
||||
|
||||
identity = stix2.Identity(name="test", identity_class="individual")
|
||||
assert prop.clean(identity) == identity
|
||||
assert prop.clean(identity) is identity
|
||||
|
|
Loading…
Reference in New Issue