Skip to content

Commit

Permalink
add: [musts] Checking the SDOs timestamp properties
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisr3d committed Apr 8, 2024
1 parent cdd96fa commit 7886abe
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions stix2validator/v20/musts.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,27 @@ 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:
timestamp_properties = enums.TIMESTAMP_PROPERTIES[instance['type']]
if len(timestamp_properties) == 2:
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 +447,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 7886abe

Please sign in to comment.