Skip to content

Commit

Permalink
add: [musts] Comparing timestamp properties
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisr3d committed Apr 8, 2024
1 parent deab60a commit 4db3a2f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions stix2validator/v20/musts.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,25 @@ def datetime_from_str(str_datetime):
return str_datetime


def modified_created(instance):
"""`modified` property must be later or equal to `created` property
def timestamp_comparison(instance):
"""
Ensure `modified` property is later or equal to `created` property.
Same for any present timestamp property.
"""
if 'modified' in instance and 'created' in instance and \
compare_timestamps(instance['modified'], instance['created']):
msg = "'modified' (%s) must be later or equal to 'created' (%s)"
return JSONError(msg % (instance['modified'], instance['created']),
instance['id'])
if instance['type'] in enums.TIMESTAMP_PROPERTIES:
first, last = enums.TIMESTAMP_PROPERTIES[instance['type']]
if first in instance and last in instance and \
compare_timestamps(instance[last], instance[first]):
msg = "'%s' (%s) must be later or equal to '%s' (%s)"
return JSONError(
msg % (last, instance[last], first, instance[first]),
instance['id']
)


def object_marking_circular_refs(instance):
Expand Down Expand Up @@ -434,7 +445,7 @@ def list_musts(options):
"""
validator_list = [
timestamp,
modified_created,
timestamp_comparison,
object_marking_circular_refs,
granular_markings_circular_refs,
marking_selector_syntax,
Expand Down

0 comments on commit 4db3a2f

Please sign in to comment.