add `id` as special-case option in regex. closes #406

pull/1/head
Emmanuelle Vargas-Gonzalez 2020-06-08 09:27:12 -04:00
parent 41525f9be0
commit aa18575c83
3 changed files with 29 additions and 1 deletions

View File

@ -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):

View File

@ -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"]

View File

@ -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"]