Skip to content

Commit

Permalink
Merge pull request #169 from oasis-open/fix-tlp-markings
Browse files Browse the repository at this point in the history
Fix tlp markings checks
  • Loading branch information
clenk authored Apr 29, 2021
2 parents eef6310 + fe72801 commit c60af65
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
8 changes: 6 additions & 2 deletions stix2validator/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,12 @@ def pretty_error(error, verbose=False):
msg = "'artifact' object must contain either 'payload_bin' "\
"or 'url'"
elif 'type' in error.instance and error.instance['type'] == 'marking-definition':
msg = "'definition' must contain a valid statement, TLP, or "\
"custom marking definition"
if error.instance.get('definition_type', '') == 'tlp':
msg = "TLP marking definitions must match one of those "\
"defined in the STIX specification."
else:
msg = "'definition' must contain a valid statement, TLP, or "\
"custom marking definition"
elif 'type' in error.instance and error.instance['type'] == 'file':
if (('is_encrypted' not in error.instance or
error.instance['is_encrypted'] is False) and
Expand Down
2 changes: 1 addition & 1 deletion stix2validator/schemas-2.0
2 changes: 1 addition & 1 deletion stix2validator/schemas-2.1
14 changes: 11 additions & 3 deletions stix2validator/test/v20/marking_definition_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,17 @@ def test_marking_definition_invalid_definition(self):
self.assertFalseWithOptions(marking_definition)

def test_granular_marking_id_selector(self):
marking_definition = copy.deepcopy(self.valid_marking_definition)
marking_definition['granular_markings'] = [{
marking_definition = {
"type": "marking-definition",
"id": "marking-definition--34098fce-860f-48ae-8e50-ebd3cc5e41da",
"created": "2016-08-01T00:00:00.000Z",
"definition_type": "statement",
"definition": {
"statement": "Copyright 2016, Example Corp"
},
"granular_markings": [{
"marking_ref": "marking-definition--4478bf48-9af2-4afa-9fc5-7075f6af04af",
"selectors": ["id"]
}]
}]
}
self.assertTrueWithOptions(marking_definition)
16 changes: 13 additions & 3 deletions stix2validator/test/v21/marking_definition_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"id": "marking-definition--34098fce-860f-48ae-8e50-ebd3cc5e41da",
"created": "2017-01-20T00:00:00.000Z",
"definition_type": "tlp",
"name": "TLP:GREEN",
"definition": {
"tlp": "green"
}
Expand Down Expand Up @@ -79,11 +80,20 @@ def test_marking_definition_invalid_definition(self):
self.assertFalseWithOptions(marking_definition)

def test_granular_marking_id_selector(self):
marking_definition = copy.deepcopy(self.valid_marking_definition)
marking_definition['granular_markings'] = [{
marking_definition = {
"type": "marking-definition",
"spec_version": "2.1",
"id": "marking-definition--4a0042fe-8b88-40fe-9600-dfa128ce6fbd",
"created": "2016-08-01T00:00:00.000Z",
"definition_type": "statement",
"definition": {
"statement": "Copyright 2019, Example Corp"
},
"granular_markings": [{
"marking_ref": "marking-definition--4478bf48-9af2-4afa-9fc5-7075f6af04af",
"selectors": ["id"]
}]
}]
}
self.assertTrueWithOptions(marking_definition)

def test_marking_definition_missing_properties(self):
Expand Down

0 comments on commit c60af65

Please sign in to comment.