Merge pull request #407 from emmanvg/flexibility-selector-syntax

Update SELECTOR_REGEX for GranularMarkings
pull/1/head
Chris Lenk 2020-06-08 13:54:39 -04:00 committed by GitHub
commit 8bde22fa1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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"]