Skip to content

Commit b2bbaee

Browse files
authored
Merge pull request #605 from mfang90739/fix_issue_586
Fix constraint violation checking for GranularMarking in v21.
2 parents fa8c95b + a2beb46 commit b2bbaee

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

stix2/test/v21/test_markings.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ def test_granular_example_with_bad_selector():
170170
assert str(excinfo.value) == "Invalid value for GranularMarking 'selectors': must adhere to selector syntax."
171171

172172

173+
def test_granular_marking_mutual_exclusion_error():
174+
with pytest.raises(stix2.exceptions.MutuallyExclusivePropertiesError) as excinfo:
175+
stix2.v21.GranularMarking(
176+
lang="en",
177+
marking_ref=stix2.TLP_GREEN,
178+
selectors=["foo"],
179+
)
180+
assert excinfo.value.cls == stix2.v21.GranularMarking
181+
assert excinfo.value.properties == ["lang", "marking_ref"]
182+
assert 'are mutually exclusive' in str(excinfo.value)
183+
184+
173185
def test_campaign_with_granular_markings_example():
174186
campaign = stix2.v21.Campaign(
175187
id="campaign--8e2e2d2b-17d4-4cbf-938f-98ee46b3cd3f",

stix2/v21/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class GranularMarking(_STIXBase21):
7777
def _check_object_constraints(self):
7878
super(GranularMarking, self)._check_object_constraints()
7979
self._check_at_least_one_property(['lang', 'marking_ref'])
80+
self._check_mutually_exclusive_properties(['lang', 'marking_ref'])
8081

8182

8283
class LanguageContent(_STIXBase21):

0 commit comments

Comments
 (0)