Fixes #308
parent
d4c0115735
commit
8719a7206f
|
@ -16,8 +16,8 @@ import stix2
|
||||||
from .base import _Observable, _STIXBase
|
from .base import _Observable, _STIXBase
|
||||||
from .core import STIX2_OBJ_MAPS, parse, parse_observable
|
from .core import STIX2_OBJ_MAPS, parse, parse_observable
|
||||||
from .exceptions import (
|
from .exceptions import (
|
||||||
CustomContentError, DictionaryKeyError, MissingPropertiesError,
|
CustomContentError, DictionaryKeyError, ExtraPropertiesError,
|
||||||
MutuallyExclusivePropertiesError,
|
MissingPropertiesError, MutuallyExclusivePropertiesError,
|
||||||
)
|
)
|
||||||
from .utils import _get_dict, get_class_hierarchy_names, parse_into_datetime
|
from .utils import _get_dict, get_class_hierarchy_names, parse_into_datetime
|
||||||
|
|
||||||
|
@ -200,7 +200,10 @@ class ListProperty(Property):
|
||||||
obj_type = self.contained
|
obj_type = self.contained
|
||||||
|
|
||||||
if isinstance(valid, collections.Mapping):
|
if isinstance(valid, collections.Mapping):
|
||||||
result.append(obj_type(**valid))
|
try:
|
||||||
|
result.append(obj_type(**valid))
|
||||||
|
except ExtraPropertiesError:
|
||||||
|
result.append(obj_type(allow_custom=True, **valid))
|
||||||
else:
|
else:
|
||||||
result.append(obj_type(valid))
|
result.append(obj_type(valid))
|
||||||
|
|
||||||
|
|
|
@ -205,3 +205,31 @@ def test_invalid_indicator_pattern():
|
||||||
assert excinfo.value.cls == stix2.v21.Indicator
|
assert excinfo.value.cls == stix2.v21.Indicator
|
||||||
assert excinfo.value.prop_name == 'pattern'
|
assert excinfo.value.prop_name == 'pattern'
|
||||||
assert 'mismatched input' in excinfo.value.reason
|
assert 'mismatched input' in excinfo.value.reason
|
||||||
|
|
||||||
|
|
||||||
|
def test_indicator_with_custom_embedded_objs():
|
||||||
|
now = dt.datetime(2017, 1, 1, 0, 0, 1, tzinfo=pytz.utc)
|
||||||
|
epoch = dt.datetime(1970, 1, 1, 0, 0, 1, tzinfo=pytz.utc)
|
||||||
|
|
||||||
|
ext_ref = stix2.v21.ExternalReference(
|
||||||
|
source_name="Test",
|
||||||
|
description="Example Custom Ext Ref",
|
||||||
|
random_custom_prop="This is a custom property",
|
||||||
|
allow_custom=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
ind = stix2.v21.Indicator(
|
||||||
|
type="indicator",
|
||||||
|
id=INDICATOR_ID,
|
||||||
|
created=now,
|
||||||
|
modified=now,
|
||||||
|
pattern="[file:hashes.MD5 = 'd41d8cd98f00b204e9800998ecf8427e']",
|
||||||
|
pattern_type="stix",
|
||||||
|
valid_from=epoch,
|
||||||
|
indicator_types=['malicious-activity'],
|
||||||
|
external_references=[ext_ref],
|
||||||
|
)
|
||||||
|
|
||||||
|
assert ind.indicator_types == ['malicious-activity']
|
||||||
|
assert len(ind.external_references) == 1
|
||||||
|
assert ind.external_references[0] == ext_ref
|
||||||
|
|
Loading…
Reference in New Issue