master
Desai, Kartikey H 2019-12-16 16:32:55 -05:00
parent d4c0115735
commit 8719a7206f
2 changed files with 34 additions and 3 deletions

View File

@ -16,8 +16,8 @@ import stix2
from .base import _Observable, _STIXBase
from .core import STIX2_OBJ_MAPS, parse, parse_observable
from .exceptions import (
CustomContentError, DictionaryKeyError, MissingPropertiesError,
MutuallyExclusivePropertiesError,
CustomContentError, DictionaryKeyError, ExtraPropertiesError,
MissingPropertiesError, MutuallyExclusivePropertiesError,
)
from .utils import _get_dict, get_class_hierarchy_names, parse_into_datetime
@ -200,7 +200,10 @@ class ListProperty(Property):
obj_type = self.contained
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:
result.append(obj_type(valid))

View File

@ -205,3 +205,31 @@ def test_invalid_indicator_pattern():
assert excinfo.value.cls == stix2.v21.Indicator
assert excinfo.value.prop_name == 'pattern'
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