From aa18575c835fdeff8ae4eb415b07d38e90fd332c Mon Sep 17 00:00:00 2001 From: Emmanuelle Vargas-Gonzalez Date: Mon, 8 Jun 2020 09:27:12 -0400 Subject: [PATCH] add `id` as special-case option in regex. closes #406 --- stix2/properties.py | 2 +- stix2/test/v20/test_granular_markings.py | 14 ++++++++++++++ stix2/test/v21/test_granular_markings.py | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/stix2/properties.py b/stix2/properties.py index c876c11..a267eb5 100644 --- a/stix2/properties.py +++ b/stix2/properties.py @@ -537,7 +537,7 @@ def enumerate_types(types, spec_version): return return_types -SELECTOR_REGEX = re.compile(r"^[a-z0-9_-]{3,250}(\.(\[\d+\]|[a-z0-9_-]{1,250}))*$") +SELECTOR_REGEX = re.compile(r"^([a-z0-9_-]{3,250}(\.(\[\d+\]|[a-z0-9_-]{1,250}))*|id)$") class SelectorProperty(Property): diff --git a/stix2/test/v20/test_granular_markings.py b/stix2/test/v20/test_granular_markings.py index e912cc1..ae2da3b 100644 --- a/stix2/test/v20/test_granular_markings.py +++ b/stix2/test/v20/test_granular_markings.py @@ -1089,3 +1089,17 @@ def test_clear_marking_not_present(data): """Test clearing markings for a selector that has no associated markings.""" with pytest.raises(MarkingNotFoundError): data = markings.clear_markings(data, ["labels"]) + + +def test_set_marking_on_id_property(): + malware = Malware( + granular_markings=[ + { + "selectors": ["id"], + "marking_ref": MARKING_IDS[0], + }, + ], + **MALWARE_KWARGS + ) + + assert "id" in malware["granular_markings"][0]["selectors"] diff --git a/stix2/test/v21/test_granular_markings.py b/stix2/test/v21/test_granular_markings.py index 1c3194b..ff8fe26 100644 --- a/stix2/test/v21/test_granular_markings.py +++ b/stix2/test/v21/test_granular_markings.py @@ -1307,3 +1307,17 @@ def test_clear_marking_not_present(data): """Test clearing markings for a selector that has no associated markings.""" with pytest.raises(MarkingNotFoundError): markings.clear_markings(data, ["malware_types"]) + + +def test_set_marking_on_id_property(): + malware = Malware( + granular_markings=[ + { + "selectors": ["id"], + "marking_ref": MARKING_IDS[0], + }, + ], + **MALWARE_KWARGS + ) + + assert "id" in malware["granular_markings"][0]["selectors"]