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 .common import MarkingDefinition
|
||||||
from .properties import IDProperty, ListProperty, Property, TypeProperty
|
from .properties import IDProperty, ListProperty, Property, TypeProperty
|
||||||
from .sdo import (AttackPattern, Campaign, CourseOfAction, Identity, Indicator,
|
from .sdo import (AttackPattern, Campaign, CourseOfAction, Identity, Indicator,
|
||||||
IntrusionSet, Malware, ObservedData, Report, ThreatActor,
|
IntrusionSet, Malware, ObservedData, Report,
|
||||||
Tool, Vulnerability)
|
STIXDomainObject, ThreatActor, Tool, Vulnerability)
|
||||||
from .sro import Relationship, Sighting
|
from .sro import Relationship, Sighting, STIXRelationshipObject
|
||||||
from .utils import get_dict
|
from .utils import get_dict
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,6 +20,11 @@ class STIXObjectProperty(Property):
|
||||||
super(STIXObjectProperty, self).__init__()
|
super(STIXObjectProperty, self).__init__()
|
||||||
|
|
||||||
def clean(self, value):
|
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:
|
try:
|
||||||
dictified = get_dict(value)
|
dictified = get_dict(value)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
|
@ -158,3 +158,11 @@ def test_parse_unknown_type():
|
||||||
with pytest.raises(stix2.exceptions.ParseError) as excinfo:
|
with pytest.raises(stix2.exceptions.ParseError) as excinfo:
|
||||||
stix2.parse(unknown)
|
stix2.parse(unknown)
|
||||||
assert str(excinfo.value) == "Can't parse unknown object type 'other'! For custom types, use the CustomObject decorator."
|
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