Merge pull request #409 from chisholm/fix_sco_ref_props

Change ObjectReferenceProperty to ReferenceProperty in 2.1 SCO classes
pull/1/head
Chris Lenk 2020-06-10 09:34:37 -04:00 committed by GitHub
commit fdb8875f1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 16 deletions

View File

@ -537,8 +537,10 @@ _JSON_ESCAPE_MAP = {
"f": "\f", "f": "\f",
"n": "\n", "n": "\n",
"r": "\r", "r": "\r",
"t": "\t" "t": "\t",
} }
def _un_json_escape(json_string): def _un_json_escape(json_string):
""" """
Removes JSON string literal escapes. We should undo these things Python's Removes JSON string literal escapes. We should undo these things Python's

View File

@ -189,14 +189,16 @@ def test_empty_hash():
SomeSCO(hashes={}) SomeSCO(hashes={})
@pytest.mark.parametrize("json_escaped, expected_unescaped", [ @pytest.mark.parametrize(
"json_escaped, expected_unescaped", [
("", ""), ("", ""),
("a", "a"), ("a", "a"),
(r"\n", "\n"), (r"\n", "\n"),
(r"\n\r\b\t\\\/\"", "\n\r\b\t\\/\""), (r"\n\r\b\t\\\/\"", "\n\r\b\t\\/\""),
(r"\\n", r"\n"), (r"\\n", r"\n"),
(r"\\\n", "\\\n") (r"\\\n", "\\\n"),
]) ],
)
def test_json_unescaping(json_escaped, expected_unescaped): def test_json_unescaping(json_escaped, expected_unescaped):
actual_unescaped = stix2.base._un_json_escape(json_escaped) actual_unescaped = stix2.base._un_json_escape(json_escaped)
assert actual_unescaped == expected_unescaped assert actual_unescaped == expected_unescaped

View File

@ -1,6 +1,5 @@
import datetime as dt import datetime as dt
import re import re
import uuid
import pytest import pytest
import pytz import pytz
@ -900,6 +899,27 @@ def test_file_example_with_RasterImageExt_Object():
assert f.extensions["raster-image-ext"].exif_tags["XResolution"] == 4928 assert f.extensions["raster-image-ext"].exif_tags["XResolution"] == 4928
def test_file_with_archive_ext_object():
ad = stix2.v21.Directory(path="archived/path")
f_obj = stix2.v21.File(
name="foo", extensions={
"archive-ext": {
"contains_refs": [ad, ],
},
},
)
f_ref = stix2.v21.File(
name="foo", extensions={
"archive-ext": {
"contains_refs": [ad.id, ],
},
},
)
assert f_obj["id"] == f_ref["id"]
assert f_obj["extensions"]["archive-ext"]["contains_refs"][0] == ad["id"]
RASTER_IMAGE_EXT = """{ RASTER_IMAGE_EXT = """{
"type": "observed-data", "type": "observed-data",
"spec_version": "2.1", "spec_version": "2.1",

View File

@ -14,8 +14,7 @@ from ..properties import (
BinaryProperty, BooleanProperty, DictionaryProperty, BinaryProperty, BooleanProperty, DictionaryProperty,
EmbeddedObjectProperty, EnumProperty, ExtensionsProperty, FloatProperty, EmbeddedObjectProperty, EnumProperty, ExtensionsProperty, FloatProperty,
HashesProperty, HexProperty, IDProperty, IntegerProperty, ListProperty, HashesProperty, HexProperty, IDProperty, IntegerProperty, ListProperty,
ObjectReferenceProperty, ReferenceProperty, StringProperty, ReferenceProperty, StringProperty, TimestampProperty, TypeProperty,
TimestampProperty, TypeProperty,
) )
from .base import _Extension, _Observable, _STIXBase21 from .base import _Extension, _Observable, _STIXBase21
from .common import GranularMarking from .common import GranularMarking
@ -144,7 +143,7 @@ class EmailMIMEComponent(_STIXBase21):
_properties = OrderedDict([ _properties = OrderedDict([
('body', StringProperty()), ('body', StringProperty()),
('body_raw_ref', ObjectReferenceProperty(valid_types=['artifact', 'file'])), ('body_raw_ref', ReferenceProperty(valid_types=['artifact', 'file'], spec_version="2.1")),
('content_type', StringProperty()), ('content_type', StringProperty()),
('content_disposition', StringProperty()), ('content_disposition', StringProperty()),
]) ])
@ -201,7 +200,7 @@ class ArchiveExt(_Extension):
_type = 'archive-ext' _type = 'archive-ext'
_properties = OrderedDict([ _properties = OrderedDict([
('contains_refs', ListProperty(ObjectReferenceProperty(valid_types=['file', 'directory']), required=True)), ('contains_refs', ListProperty(ReferenceProperty(valid_types=['file', 'directory'], spec_version="2.1"), required=True)),
('comment', StringProperty()), ('comment', StringProperty()),
]) ])
@ -465,7 +464,7 @@ class HTTPRequestExt(_Extension):
('request_version', StringProperty()), ('request_version', StringProperty()),
('request_header', DictionaryProperty(spec_version='2.1')), ('request_header', DictionaryProperty(spec_version='2.1')),
('message_body_length', IntegerProperty()), ('message_body_length', IntegerProperty()),
('message_body_data_ref', ObjectReferenceProperty(valid_types='artifact')), ('message_body_data_ref', ReferenceProperty(valid_types='artifact', spec_version="2.1")),
]) ])
@ -654,7 +653,7 @@ class WindowsServiceExt(_Extension):
"SERVICE_SYSTEM_ALERT", "SERVICE_SYSTEM_ALERT",
]), ]),
), ),
('service_dll_refs', ListProperty(ObjectReferenceProperty(valid_types='file'))), ('service_dll_refs', ListProperty(ReferenceProperty(valid_types='file', spec_version="2.1"))),
( (
'service_type', EnumProperty(allowed=[ 'service_type', EnumProperty(allowed=[
"SERVICE_KERNEL_DRIVER", "SERVICE_KERNEL_DRIVER",