From f301bc144f9d3b425479a724723df4697a6a6e83 Mon Sep 17 00:00:00 2001 From: Michael Chisholm Date: Wed, 14 Apr 2021 12:48:32 -0400 Subject: [PATCH] Disable custom vocab enforcement. Custom values for open-vocab properties are now always accepted and not considered customizations (has_custom will be False). Just commented out the enforcement code and xfail'd the unit tests, which makes it easy to reinstate these behaviors later. It was decided this is too likely to break user code, and we don't currently have a way to disallow customizations in other places while still allowing custom open vocab values. Safest to always allow custom open vocab values, for now. --- stix2/properties.py | 16 +++++++++++----- stix2/test/test_properties.py | 4 ++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/stix2/properties.py b/stix2/properties.py index e977240..b67f627 100644 --- a/stix2/properties.py +++ b/stix2/properties.py @@ -690,12 +690,18 @@ class OpenVocabProperty(StringProperty): value, allow_custom, ) - has_custom = cleaned_value not in self.allowed + # Disabled: it was decided that enforcing this is too strict (might + # break too much user code). Revisit when we have the capability for + # more granular config settings when creating objects. + # + # has_custom = cleaned_value not in self.allowed + # + # if not allow_custom and has_custom: + # raise CustomContentError( + # "custom value in open vocab: '{}'".format(cleaned_value), + # ) - if not allow_custom and has_custom: - raise CustomContentError( - "custom value in open vocab: '{}'".format(cleaned_value), - ) + has_custom = False return cleaned_value, has_custom diff --git a/stix2/test/test_properties.py b/stix2/test/test_properties.py index f19d1b5..d37319c 100644 --- a/stix2/test/test_properties.py +++ b/stix2/test/test_properties.py @@ -368,6 +368,10 @@ def test_enum_property_invalid(): enum_prop.clean('z', True) +@pytest.mark.xfail( + reason="Temporarily disabled custom open vocab enforcement", + strict=True +) @pytest.mark.parametrize( "vocab", [ ['a', 'b', 'c'],