From e57c36f52553e4e3e350817558b963784b6e5c79 Mon Sep 17 00:00:00 2001 From: Chris Lenk Date: Fri, 6 Oct 2017 15:05:39 -0400 Subject: [PATCH] Check custom extension properties is not empty --- stix2/observables.py | 2 +- stix2/test/test_custom.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) 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)