Skip to content

Commit

Permalink
Merge pull request #407 from emmanvg/flexibility-selector-syntax
Browse files Browse the repository at this point in the history
Update SELECTOR_REGEX for GranularMarkings
  • Loading branch information
clenk authored Jun 8, 2020
2 parents 6faf6b9 + aa18575 commit 8bde22f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stix2/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 14 additions & 0 deletions stix2/test/v20/test_granular_markings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
14 changes: 14 additions & 0 deletions stix2/test/v21/test_granular_markings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

0 comments on commit 8bde22f

Please sign in to comment.