Revert object_properties() to #85 fix. Update tests accordingly
parent
d31b110330
commit
79475586d8
|
@ -40,7 +40,14 @@ class _STIXBase(collections.Mapping):
|
||||||
"""Base class for STIX object types"""
|
"""Base class for STIX object types"""
|
||||||
|
|
||||||
def object_properties(self):
|
def object_properties(self):
|
||||||
return list(self._properties.keys())
|
props = set(self._properties.keys())
|
||||||
|
custom_props = list(set(self._inner.keys()) - props)
|
||||||
|
custom_props.sort()
|
||||||
|
|
||||||
|
all_properties = list(self._properties.keys())
|
||||||
|
all_properties.extend(custom_props) # Any custom properties to the bottom
|
||||||
|
|
||||||
|
return all_properties
|
||||||
|
|
||||||
def _check_property(self, prop_name, prop, kwargs):
|
def _check_property(self, prop_name, prop, kwargs):
|
||||||
if prop_name not in kwargs:
|
if prop_name not in kwargs:
|
||||||
|
@ -102,13 +109,6 @@ class _STIXBase(collections.Mapping):
|
||||||
extra_kwargs = list(set(kwargs) - set(cls._properties))
|
extra_kwargs = list(set(kwargs) - set(cls._properties))
|
||||||
if extra_kwargs:
|
if extra_kwargs:
|
||||||
raise ExtraPropertiesError(cls, extra_kwargs)
|
raise ExtraPropertiesError(cls, extra_kwargs)
|
||||||
else:
|
|
||||||
from .properties import CustomProperty
|
|
||||||
|
|
||||||
# The custom properties will get added to the bottom.
|
|
||||||
# Matched with a CustomProperty.
|
|
||||||
extra_kwargs = list(set(kwargs) - set(cls._properties))
|
|
||||||
self._properties.update([(x, CustomProperty()) for x in extra_kwargs])
|
|
||||||
|
|
||||||
# Remove any keyword arguments whose value is None
|
# Remove any keyword arguments whose value is None
|
||||||
setting_kwargs = {}
|
setting_kwargs = {}
|
||||||
|
|
|
@ -498,29 +498,48 @@ def test_composite_datasource_operations():
|
||||||
objects=STIX_OBJS1,
|
objects=STIX_OBJS1,
|
||||||
spec_version="2.0",
|
spec_version="2.0",
|
||||||
type="bundle")
|
type="bundle")
|
||||||
cds = CompositeDataSource()
|
cds1 = CompositeDataSource()
|
||||||
ds1 = MemorySource(stix_data=BUNDLE1)
|
ds1_1 = MemorySource(stix_data=BUNDLE1)
|
||||||
ds2 = MemorySource(stix_data=STIX_OBJS2)
|
ds1_2 = MemorySource(stix_data=STIX_OBJS2)
|
||||||
|
|
||||||
cds.add_data_sources([ds1, ds2])
|
cds2 = CompositeDataSource()
|
||||||
|
ds2_1 = MemorySource(stix_data=BUNDLE1)
|
||||||
|
ds2_2 = MemorySource(stix_data=STIX_OBJS2)
|
||||||
|
|
||||||
indicators = cds.all_versions("indicator--d81f86b9-975b-bc0b-775e-810c5ad45a4f")
|
cds1.add_data_sources([ds1_1, ds1_2])
|
||||||
|
cds2.add_data_sources([ds2_1, ds2_2])
|
||||||
|
|
||||||
|
indicators = cds1.all_versions("indicator--d81f86b9-975b-bc0b-775e-810c5ad45a4f")
|
||||||
|
|
||||||
# In STIX_OBJS2 changed the 'modified' property to a later time...
|
# In STIX_OBJS2 changed the 'modified' property to a later time...
|
||||||
assert len(indicators) == 2
|
assert len(indicators) == 2
|
||||||
|
|
||||||
indicator = cds.get("indicator--d81f86b9-975b-bc0b-775e-810c5ad45a4f")
|
cds1.add_data_sources([cds2])
|
||||||
|
|
||||||
|
indicator = cds1.get("indicator--d81f86b9-975b-bc0b-775e-810c5ad45a4f")
|
||||||
|
|
||||||
assert indicator["id"] == "indicator--d81f86b9-975b-bc0b-775e-810c5ad45a4f"
|
assert indicator["id"] == "indicator--d81f86b9-975b-bc0b-775e-810c5ad45a4f"
|
||||||
assert indicator["modified"] == "2017-01-31T13:49:53.935Z"
|
assert indicator["modified"] == "2017-01-31T13:49:53.935Z"
|
||||||
assert indicator["type"] == "indicator"
|
assert indicator["type"] == "indicator"
|
||||||
|
|
||||||
query = [
|
query1 = [
|
||||||
Filter("type", "=", "indicator")
|
Filter("type", "=", "indicator")
|
||||||
]
|
]
|
||||||
|
|
||||||
results = cds.query(query)
|
query2 = [
|
||||||
|
Filter("valid_from", "=", "2017-01-27T13:49:53.935382Z")
|
||||||
|
]
|
||||||
|
|
||||||
|
cds1.filters.update(query2)
|
||||||
|
|
||||||
|
results = cds1.query(query1)
|
||||||
|
|
||||||
# STIX_OBJS2 has indicator with later time, one with different id, one with
|
# STIX_OBJS2 has indicator with later time, one with different id, one with
|
||||||
# original time in STIX_OBJS1
|
# original time in STIX_OBJS1
|
||||||
assert len(results) == 3
|
assert len(results) == 3
|
||||||
|
|
||||||
|
indicator = cds1.get("indicator--d81f86b9-975b-bc0b-775e-810c5ad45a4f")
|
||||||
|
|
||||||
|
assert indicator["id"] == "indicator--d81f86b9-975b-bc0b-775e-810c5ad45a4f"
|
||||||
|
assert indicator["modified"] == "2017-01-31T13:49:53.935Z"
|
||||||
|
assert indicator["type"] == "indicator"
|
||||||
|
|
|
@ -340,7 +340,7 @@ def test_filesystem_object_with_custom_property(fs_store):
|
||||||
|
|
||||||
fs_store.add(camp, True)
|
fs_store.add(camp, True)
|
||||||
|
|
||||||
camp_r = fs_store.get(camp.id)
|
camp_r = fs_store.get(camp.id, allow_custom=True)
|
||||||
assert camp_r.id == camp.id
|
assert camp_r.id == camp.id
|
||||||
assert camp_r.x_empire == camp.x_empire
|
assert camp_r.x_empire == camp.x_empire
|
||||||
|
|
||||||
|
@ -352,9 +352,9 @@ def test_filesystem_object_with_custom_property_in_bundle(fs_store):
|
||||||
allow_custom=True)
|
allow_custom=True)
|
||||||
|
|
||||||
bundle = Bundle(camp, allow_custom=True)
|
bundle = Bundle(camp, allow_custom=True)
|
||||||
fs_store.add(bundle, True)
|
fs_store.add(bundle, allow_custom=True)
|
||||||
|
|
||||||
camp_r = fs_store.get(camp.id)
|
camp_r = fs_store.get(camp.id, allow_custom=True)
|
||||||
assert camp_r.id == camp.id
|
assert camp_r.id == camp.id
|
||||||
assert camp_r.x_empire == camp.x_empire
|
assert camp_r.x_empire == camp.x_empire
|
||||||
|
|
||||||
|
@ -367,9 +367,9 @@ def test_filesystem_custom_object(fs_store):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
newobj = NewObj(property1='something')
|
newobj = NewObj(property1='something')
|
||||||
fs_store.add(newobj, True)
|
fs_store.add(newobj, allow_custom=True)
|
||||||
|
|
||||||
newobj_r = fs_store.get(newobj.id)
|
newobj_r = fs_store.get(newobj.id, allow_custom=True)
|
||||||
assert newobj_r.id == newobj.id
|
assert newobj_r.id == newobj.id
|
||||||
assert newobj_r.property1 == 'something'
|
assert newobj_r.property1 == 'something'
|
||||||
|
|
||||||
|
|
|
@ -62,4 +62,15 @@ def test_parse_no_type():
|
||||||
"identity_class": "individual"
|
"identity_class": "individual"
|
||||||
}""")
|
}""")
|
||||||
|
|
||||||
|
|
||||||
|
def test_identity_with_custom():
|
||||||
|
identity = stix2.Identity(
|
||||||
|
name="John Smith",
|
||||||
|
identity_class="individual",
|
||||||
|
custom_properties={'x_foo': 'bar'}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert identity.x_foo == "bar"
|
||||||
|
assert "x_foo" in identity.object_properties()
|
||||||
|
|
||||||
# TODO: Add other examples
|
# TODO: Add other examples
|
||||||
|
|
Loading…
Reference in New Issue