Add few tests to improve some code coverage
parent
9c7128d074
commit
8447c9fcd9
|
@ -450,6 +450,14 @@
|
|||
"mem.source.filters.add([f1,f2])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"##### Note: The `defanged` property is now always included (implicitly) for STIX 2.1 Cyber Observable Objects (SCOs)\n",
|
||||
"This is important to remember if you are writing a filter that involves checking the `objects` property of a STIX 2.1 `ObservedData` object. If any of the objects associated with the `objects` property are STIX 2.1 SCOs, then your filter must include the `defanged` property. For an example, refer to `filters[14]` & `filters[15]` in stix2/test/v21/test_datastore_filters.py "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
|
@ -726,21 +734,21 @@
|
|||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "cti-python-stix2",
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "cti-python-stix2"
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 2
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython2",
|
||||
"version": "2.7.12"
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.6.7"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
|
|
@ -465,21 +465,21 @@ def test_parse_email_message_not_multipart(data):
|
|||
"type": "file",
|
||||
"id": "file--65f2873d-38c2-56b4-bfa5-e3ef21e8a3c3",
|
||||
"hashes": {
|
||||
"SHA-256": "19c549ec2628b989382f6b280cbd7bb836a0b461332c0fe53511ce7d584b89d3"
|
||||
"SHA-1": "6e71b3cac15d32fe2d36c270887df9479c25c640"
|
||||
}
|
||||
},
|
||||
"2": {
|
||||
"type": "file",
|
||||
"id": "file--ef2d6dca-ec7d-5ab7-8dd9-ec9c0dee0eac",
|
||||
"hashes": {
|
||||
"SHA-256": "0969de02ecf8a5f003e3f6d063d848c8a193aada092623f8ce408c15bcb5f038"
|
||||
"SHA-512": "b7e98c78c24fb4c2c7b175e90474b21eae0ccf1b5ea4708b4e0f2d2940004419edc7161c18a1e71b2565df099ba017bcaa67a248e2989b6268ce078b88f2e210"
|
||||
}
|
||||
},
|
||||
"3": {
|
||||
"type": "file",
|
||||
"name": "foo.zip",
|
||||
"hashes": {
|
||||
"SHA-256": "35a01331e9ad96f751278b891b6ea09699806faedfa237d40513d92ad1b7100f"
|
||||
"SHA3-256": "35a01331e9ad96f751278b891b6ea09699806faedfa237d40513d92ad1b7100f"
|
||||
},
|
||||
"mime_type": "application/zip",
|
||||
"extensions": {
|
||||
|
@ -1490,3 +1490,39 @@ def test_deterministic_id_no_contributing_props():
|
|||
uuid_obj_2 = uuid.UUID(email_msg_2.id[-36:])
|
||||
assert uuid_obj_2.variant == uuid.RFC_4122
|
||||
assert uuid_obj_2.version == 4
|
||||
|
||||
|
||||
def test_ipv4_resolves_to_refs_deprecation():
|
||||
with pytest.warns(stix2.exceptions.STIXDeprecationWarning):
|
||||
|
||||
stix2.v21.IPv4Address(
|
||||
value="26.09.19.70",
|
||||
resolves_to_refs=["mac-addr--08900593-0265-52fc-93c0-5b4a942f5887"],
|
||||
)
|
||||
|
||||
|
||||
def test_ipv4_belongs_to_refs_deprecation():
|
||||
with pytest.warns(stix2.exceptions.STIXDeprecationWarning):
|
||||
|
||||
stix2.v21.IPv4Address(
|
||||
value="21.12.19.64",
|
||||
belongs_to_refs=["autonomous-system--52e0a49d-d683-5801-a7b8-145765a1e116"],
|
||||
)
|
||||
|
||||
|
||||
def test_ipv6_resolves_to_refs_deprecation():
|
||||
with pytest.warns(stix2.exceptions.STIXDeprecationWarning):
|
||||
|
||||
stix2.v21.IPv6Address(
|
||||
value="2001:0db8:85a3:0000:0000:8a2e:0370:7334",
|
||||
resolves_to_refs=["mac-addr--08900593-0265-52fc-93c0-5b4a942f5887"],
|
||||
)
|
||||
|
||||
|
||||
def test_ipv6_belongs_to_refs_deprecation():
|
||||
with pytest.warns(stix2.exceptions.STIXDeprecationWarning):
|
||||
|
||||
stix2.v21.IPv6Address(
|
||||
value="2001:0db8:85a3:0000:0000:8a2e:0370:7334",
|
||||
belongs_to_refs=["autonomous-system--52e0a49d-d683-5801-a7b8-145765a1e116"],
|
||||
)
|
||||
|
|
|
@ -385,7 +385,7 @@ class File(_Observable):
|
|||
('mtime', TimestampProperty()),
|
||||
('atime', TimestampProperty()),
|
||||
('parent_directory_ref', ReferenceProperty(valid_types='directory', spec_version='2.1')),
|
||||
('contains_refs', ListProperty(ReferenceProperty(invalid_types=[""], spec_version='2.1'))),
|
||||
('contains_refs', ListProperty(ReferenceProperty(invalid_types="", spec_version='2.1'))),
|
||||
('content_ref', ReferenceProperty(valid_types='artifact', spec_version='2.1')),
|
||||
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)),
|
||||
('spec_version', StringProperty(fixed='2.1')),
|
||||
|
|
|
@ -6,11 +6,9 @@ import warnings
|
|||
|
||||
from six.moves.urllib.parse import quote_plus
|
||||
|
||||
from ..core import STIX2_OBJ_MAPS, STIXDomainObject
|
||||
from ..core import STIXDomainObject
|
||||
from ..custom import _custom_object_builder
|
||||
from ..exceptions import (
|
||||
InvalidValueError, PropertyPresenceError, STIXDeprecationWarning,
|
||||
)
|
||||
from ..exceptions import PropertyPresenceError, STIXDeprecationWarning
|
||||
from ..properties import (
|
||||
BinaryProperty, BooleanProperty, EmbeddedObjectProperty, EnumProperty,
|
||||
FloatProperty, IDProperty, IntegerProperty, ListProperty,
|
||||
|
@ -597,16 +595,9 @@ class ObservedData(STIXDomainObject):
|
|||
|
||||
self._check_mutually_exclusive_properties(
|
||||
["objects", "object_refs"],
|
||||
at_least_one=False,
|
||||
)
|
||||
|
||||
if self.get('object_refs'):
|
||||
for identifier in self.get('object_refs'):
|
||||
identifier_prefix = identifier[:identifier.index('--')]
|
||||
if identifier_prefix in STIX2_OBJ_MAPS['v21']['observables'].keys():
|
||||
break
|
||||
else:
|
||||
raise InvalidValueError(self.__class__, 'object_refs', "At least one identifier must be of a SCO type if this property specified")
|
||||
|
||||
|
||||
class Opinion(STIXDomainObject):
|
||||
# TODO: Add link
|
||||
|
|
Loading…
Reference in New Issue