Check custom extension properties is not empty

stix2.1
Chris Lenk 2017-10-06 15:05:39 -04:00
parent 2b65f7205b
commit e57c36f525
2 changed files with 10 additions and 2 deletions

View File

@ -916,7 +916,7 @@ def CustomExtension(observable=None, type='x-custom-observable', properties=None
'extensions': ExtensionsProperty(enclosing_type=_type),
}
if not isinstance(properties, dict):
if not isinstance(properties, dict) or not properties:
raise ValueError("'properties' must be a dict!")
_properties.update(properties)

View File

@ -366,7 +366,15 @@ def test_custom_extension_invalid_observable():
def test_custom_extension_no_properties():
with pytest.raises(ValueError) as excinfo:
@stix2.observables.CustomExtension(stix2.DomainName, 'x-new-ext', None)
@stix2.observables.CustomExtension(stix2.DomainName, 'x-new-ext2', None)
class BarExtension():
pass
assert "'properties' must be a dict!" in str(excinfo.value)
def test_custom_extension_empty_properties():
with pytest.raises(ValueError) as excinfo:
@stix2.observables.CustomExtension(stix2.DomainName, 'x-new-ext2', {})
class BarExtension():
pass
assert "'properties' must be a dict!" in str(excinfo.value)