Skip to content

Commit

Permalink
Merge pull request #470 from chisholm/where_sighted_refs_types
Browse files Browse the repository at this point in the history
Fix Sighting bug with reference type enforcement on where_sighted_refs
  • Loading branch information
clenk authored Nov 16, 2020
2 parents a751df3 + 169ef87 commit 3cef32e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions stix2/test/v21/test_sighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import stix2

from .constants import IDENTITY_ID, INDICATOR_ID, SIGHTING_ID, SIGHTING_KWARGS
from .constants import (
IDENTITY_ID, INDICATOR_ID, LOCATION_ID, SIGHTING_ID, SIGHTING_KWARGS,
)

EXPECTED_SIGHTING = """{
"type": "sighting",
Expand All @@ -15,7 +17,8 @@
"modified": "2016-04-06T20:06:37.000Z",
"sighting_of_ref": "indicator--a740531e-63ff-4e49-a9e1-a0a3eed0e3e7",
"where_sighted_refs": [
"identity--311b2d2d-f010-4473-83ec-1edf84858f4c"
"identity--311b2d2d-f010-4473-83ec-1edf84858f4c",
"location--a6e9345f-5a15-4c29-8bb3-7dcc5d168d64"
]
}"""

Expand All @@ -41,7 +44,7 @@ def test_sighting_all_required_properties():
created=now,
modified=now,
sighting_of_ref=INDICATOR_ID,
where_sighted_refs=[IDENTITY_ID],
where_sighted_refs=[IDENTITY_ID, LOCATION_ID],
)
assert str(s) == EXPECTED_SIGHTING

Expand Down Expand Up @@ -101,6 +104,7 @@ def test_create_sighting_from_objects_rather_than_ids(malware): # noqa: F811
"type": "sighting",
"where_sighted_refs": [
IDENTITY_ID,
LOCATION_ID,
],
},
],
Expand All @@ -114,4 +118,4 @@ def test_parse_sighting(data):
assert sighting.created == dt.datetime(2016, 4, 6, 20, 6, 37, tzinfo=pytz.utc)
assert sighting.modified == dt.datetime(2016, 4, 6, 20, 6, 37, tzinfo=pytz.utc)
assert sighting.sighting_of_ref == INDICATOR_ID
assert sighting.where_sighted_refs == [IDENTITY_ID]
assert sighting.where_sighted_refs == [IDENTITY_ID, LOCATION_ID]
2 changes: 1 addition & 1 deletion stix2/v21/sro.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Sighting(_RelationshipObject):
('count', IntegerProperty(min=0, max=999999999)),
('sighting_of_ref', ReferenceProperty(valid_types="SDO", spec_version='2.1', required=True)),
('observed_data_refs', ListProperty(ReferenceProperty(valid_types='observed-data', spec_version='2.1'))),
('where_sighted_refs', ListProperty(ReferenceProperty(valid_types='identity', spec_version='2.1'))),
('where_sighted_refs', ListProperty(ReferenceProperty(valid_types=['identity', 'location'], spec_version='2.1'))),
('summary', BooleanProperty()),
('revoked', BooleanProperty(default=lambda: False)),
('labels', ListProperty(StringProperty)),
Expand Down

0 comments on commit 3cef32e

Please sign in to comment.