diff --git a/stix2/observables.py b/stix2/observables.py index 7a92813..137b388 100644 --- a/stix2/observables.py +++ b/stix2/observables.py @@ -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) diff --git a/stix2/test/test_custom.py b/stix2/test/test_custom.py index 10baf7b..77598ca 100644 --- a/stix2/test/test_custom.py +++ b/stix2/test/test_custom.py @@ -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)