Update v21 tests for some missing methods, ensure we are calling and
using the right classes.stix2.1
parent
bfa86bf87e
commit
2c5ddc14af
|
@ -100,7 +100,7 @@ def test_bundle_with_wrong_type():
|
|||
with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo:
|
||||
stix2.v21.Bundle(type="not-a-bundle")
|
||||
|
||||
assert excinfo.value.cls == stix2.Bundle
|
||||
assert excinfo.value.cls == stix2.v21.Bundle
|
||||
assert excinfo.value.prop_name == "type"
|
||||
assert excinfo.value.reason == "must equal 'bundle'."
|
||||
assert str(excinfo.value) == "Invalid value for Bundle 'type': must equal 'bundle'."
|
||||
|
@ -110,7 +110,7 @@ def test_bundle_id_must_start_with_bundle():
|
|||
with pytest.raises(stix2.exceptions.InvalidValueError) as excinfo:
|
||||
stix2.v21.Bundle(id='my-prefix--')
|
||||
|
||||
assert excinfo.value.cls == stix2.Bundle
|
||||
assert excinfo.value.cls == stix2.v21.Bundle
|
||||
assert excinfo.value.prop_name == "id"
|
||||
assert excinfo.value.reason == "must start with 'bundle--'."
|
||||
assert str(excinfo.value) == "Invalid value for Bundle 'id': must start with 'bundle--'."
|
||||
|
@ -179,7 +179,7 @@ def test_parse_bundle(version):
|
|||
|
||||
assert bundle.type == "bundle"
|
||||
assert bundle.id.startswith("bundle--")
|
||||
assert type(bundle.objects[0]) is stix2.v21.sdo.Indicator
|
||||
assert type(bundle.objects[0]) is stix2.v21.Indicator
|
||||
assert bundle.objects[0].type == 'indicator'
|
||||
assert bundle.objects[1].type == 'malware'
|
||||
assert bundle.objects[2].type == 'relationship'
|
||||
|
|
|
@ -2,7 +2,6 @@ import pytest
|
|||
|
||||
import stix2
|
||||
import stix2.base
|
||||
import stix2.v21.sdo
|
||||
|
||||
from .constants import FAKE_TIME, MARKING_DEFINITION_ID
|
||||
|
||||
|
@ -263,7 +262,7 @@ def test_identity_custom_property_edit_markings():
|
|||
|
||||
|
||||
def test_custom_marking_no_init_1():
|
||||
@stix2.CustomMarking('x-new-obj', [
|
||||
@stix2.v21.CustomMarking('x-new-obj', [
|
||||
('property1', stix2.v21.properties.StringProperty(required=True)),
|
||||
])
|
||||
class NewObj():
|
||||
|
@ -274,7 +273,7 @@ def test_custom_marking_no_init_1():
|
|||
|
||||
|
||||
def test_custom_marking_no_init_2():
|
||||
@stix2.CustomMarking('x-new-obj2', [
|
||||
@stix2.v21.CustomMarking('x-new-obj2', [
|
||||
('property1', stix2.v21.properties.StringProperty(required=True)),
|
||||
])
|
||||
class NewObj2(object):
|
||||
|
@ -284,7 +283,7 @@ def test_custom_marking_no_init_2():
|
|||
assert no2.property1 == 'something'
|
||||
|
||||
|
||||
@stix2.sdo.CustomObject('x-new-type', [
|
||||
@stix2.v21.CustomObject('x-new-type', [
|
||||
('property1', stix2.v21.properties.StringProperty(required=True)),
|
||||
('property2', stix2.v21.properties.IntegerProperty()),
|
||||
])
|
||||
|
@ -317,8 +316,8 @@ def test_custom_object_type():
|
|||
|
||||
|
||||
def test_custom_object_no_init_1():
|
||||
@stix2.sdo.CustomObject('x-new-obj', [
|
||||
('property1', stix2.properties.StringProperty(required=True)),
|
||||
@stix2.v21.CustomObject('x-new-obj', [
|
||||
('property1', stix2.v21.properties.StringProperty(required=True)),
|
||||
])
|
||||
class NewObj():
|
||||
pass
|
||||
|
@ -328,8 +327,8 @@ def test_custom_object_no_init_1():
|
|||
|
||||
|
||||
def test_custom_object_no_init_2():
|
||||
@stix2.sdo.CustomObject('x-new-obj2', [
|
||||
('property1', stix2.properties.StringProperty(required=True)),
|
||||
@stix2.v21.CustomObject('x-new-obj2', [
|
||||
('property1', stix2.v21.properties.StringProperty(required=True)),
|
||||
])
|
||||
class NewObj2(object):
|
||||
pass
|
||||
|
@ -340,16 +339,16 @@ def test_custom_object_no_init_2():
|
|||
|
||||
def test_custom_object_invalid_type_name():
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
@stix2.sdo.CustomObject('x', [
|
||||
('property1', stix2.properties.StringProperty(required=True)),
|
||||
@stix2.v21.CustomObject('x', [
|
||||
('property1', stix2.v21.properties.StringProperty(required=True)),
|
||||
])
|
||||
class NewObj(object):
|
||||
pass # pragma: no cover
|
||||
assert "Invalid type name 'x': " in str(excinfo.value)
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
@stix2.sdo.CustomObject('x_new_object', [
|
||||
('property1', stix2.properties.StringProperty(required=True)),
|
||||
@stix2.v21.CustomObject('x_new_object', [
|
||||
('property1', stix2.v21.properties.StringProperty(required=True)),
|
||||
])
|
||||
class NewObj2(object):
|
||||
pass # pragma: no cover
|
||||
|
@ -375,7 +374,7 @@ def test_parse_unregistered_custom_object_type():
|
|||
}"""
|
||||
|
||||
with pytest.raises(stix2.exceptions.ParseError) as excinfo:
|
||||
stix2.parse(nt_string)
|
||||
stix2.parse(nt_string, version="2.1")
|
||||
assert "Can't parse unknown object type" in str(excinfo.value)
|
||||
assert "use the CustomObject decorator." in str(excinfo.value)
|
||||
|
||||
|
@ -390,14 +389,14 @@ def test_parse_unregistered_custom_object_type_w_allow_custom():
|
|||
"property1": "something"
|
||||
}"""
|
||||
|
||||
custom_obj = stix2.parse(nt_string, allow_custom=True)
|
||||
custom_obj = stix2.parse(nt_string, version="2.1", allow_custom=True)
|
||||
assert custom_obj["type"] == "x-foobar-observable"
|
||||
|
||||
|
||||
@stix2.observables.CustomObservable('x-new-observable', [
|
||||
('property1', stix2.properties.StringProperty(required=True)),
|
||||
('property2', stix2.properties.IntegerProperty()),
|
||||
('x_property3', stix2.properties.BooleanProperty()),
|
||||
@stix2.v21.CustomObservable('x-new-observable', [
|
||||
('property1', stix2.v21.properties.StringProperty(required=True)),
|
||||
('property2', stix2.v21.properties.IntegerProperty()),
|
||||
('x_property3', stix2.v21.properties.BooleanProperty()),
|
||||
])
|
||||
class NewObservable():
|
||||
def __init__(self, property2=None, **kwargs):
|
||||
|
@ -433,8 +432,8 @@ def test_custom_observable_raises_exception():
|
|||
|
||||
|
||||
def test_custom_observable_object_no_init_1():
|
||||
@stix2.observables.CustomObservable('x-new-observable', [
|
||||
('property1', stix2.properties.StringProperty()),
|
||||
@stix2.v21.CustomObservable('x-new-observable', [
|
||||
('property1', stix2.v21.properties.StringProperty()),
|
||||
])
|
||||
class NewObs():
|
||||
pass
|
||||
|
@ -444,8 +443,8 @@ def test_custom_observable_object_no_init_1():
|
|||
|
||||
|
||||
def test_custom_observable_object_no_init_2():
|
||||
@stix2.observables.CustomObservable('x-new-obs2', [
|
||||
('property1', stix2.properties.StringProperty()),
|
||||
@stix2.v21.CustomObservable('x-new-obs2', [
|
||||
('property1', stix2.v21.properties.StringProperty()),
|
||||
])
|
||||
class NewObs2(object):
|
||||
pass
|
||||
|
@ -456,16 +455,16 @@ def test_custom_observable_object_no_init_2():
|
|||
|
||||
def test_custom_observable_object_invalid_type_name():
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
@stix2.observables.CustomObservable('x', [
|
||||
('property1', stix2.properties.StringProperty()),
|
||||
@stix2.v21.CustomObservable('x', [
|
||||
('property1', stix2.v21.properties.StringProperty()),
|
||||
])
|
||||
class NewObs(object):
|
||||
pass # pragma: no cover
|
||||
assert "Invalid observable type name 'x':" in str(excinfo.value)
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
@stix2.observables.CustomObservable('x_new_obs', [
|
||||
('property1', stix2.properties.StringProperty()),
|
||||
@stix2.v21.CustomObservable('x_new_obs', [
|
||||
('property1', stix2.v21.properties.StringProperty()),
|
||||
])
|
||||
class NewObs2(object):
|
||||
pass # pragma: no cover
|
||||
|
@ -474,8 +473,8 @@ def test_custom_observable_object_invalid_type_name():
|
|||
|
||||
def test_custom_observable_object_invalid_ref_property():
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
@stix2.observables.CustomObservable('x-new-obs', [
|
||||
('property_ref', stix2.properties.StringProperty()),
|
||||
@stix2.v21.CustomObservable('x-new-obs', [
|
||||
('property_ref', stix2.v21.properties.StringProperty()),
|
||||
])
|
||||
class NewObs():
|
||||
pass
|
||||
|
@ -484,8 +483,8 @@ def test_custom_observable_object_invalid_ref_property():
|
|||
|
||||
def test_custom_observable_object_invalid_refs_property():
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
@stix2.observables.CustomObservable('x-new-obs', [
|
||||
('property_refs', stix2.properties.StringProperty()),
|
||||
@stix2.v21.CustomObservable('x-new-obs', [
|
||||
('property_refs', stix2.v21.properties.StringProperty()),
|
||||
])
|
||||
class NewObs():
|
||||
pass
|
||||
|
@ -494,8 +493,8 @@ def test_custom_observable_object_invalid_refs_property():
|
|||
|
||||
def test_custom_observable_object_invalid_refs_list_property():
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
@stix2.observables.CustomObservable('x-new-obs', [
|
||||
('property_refs', stix2.properties.ListProperty(stix2.properties.StringProperty)),
|
||||
@stix2.v21.CustomObservable('x-new-obs', [
|
||||
('property_refs', stix2.v21.properties.ListProperty(stix2.v21.properties.StringProperty)),
|
||||
])
|
||||
class NewObs():
|
||||
pass
|
||||
|
@ -503,9 +502,9 @@ def test_custom_observable_object_invalid_refs_list_property():
|
|||
|
||||
|
||||
def test_custom_observable_object_invalid_valid_refs():
|
||||
@stix2.observables.CustomObservable('x-new-obs', [
|
||||
('property1', stix2.properties.StringProperty(required=True)),
|
||||
('property_ref', stix2.properties.ObjectReferenceProperty(valid_types='email-addr')),
|
||||
@stix2.v21.CustomObservable('x-new-obs', [
|
||||
('property1', stix2.v21.properties.StringProperty(required=True)),
|
||||
('property_ref', stix2.v21.properties.ObjectReferenceProperty(valid_types='email-addr')),
|
||||
])
|
||||
class NewObs():
|
||||
pass
|
||||
|
@ -520,7 +519,7 @@ def test_custom_observable_object_invalid_valid_refs():
|
|||
def test_custom_no_properties_raises_exception():
|
||||
with pytest.raises(ValueError):
|
||||
|
||||
@stix2.sdo.CustomObject('x-new-object-type')
|
||||
@stix2.v21.CustomObject('x-new-object-type')
|
||||
class NewObject1(object):
|
||||
pass
|
||||
|
||||
|
@ -528,7 +527,7 @@ def test_custom_no_properties_raises_exception():
|
|||
def test_custom_wrong_properties_arg_raises_exception():
|
||||
with pytest.raises(ValueError):
|
||||
|
||||
@stix2.observables.CustomObservable('x-new-object-type', (("prop", stix2.properties.BooleanProperty())))
|
||||
@stix2.v21.CustomObservable('x-new-object-type', (("prop", stix2.v21.properties.BooleanProperty())))
|
||||
class NewObject2(object):
|
||||
pass
|
||||
|
||||
|
@ -539,7 +538,7 @@ def test_parse_custom_observable_object():
|
|||
"property1": "something"
|
||||
}"""
|
||||
|
||||
nt = stix2.parse_observable(nt_string, [])
|
||||
nt = stix2.parse_observable(nt_string, [], version='2.1')
|
||||
assert isinstance(nt, stix2.base._STIXBase)
|
||||
assert nt.property1 == 'something'
|
||||
|
||||
|
@ -551,10 +550,10 @@ def test_parse_unregistered_custom_observable_object():
|
|||
}"""
|
||||
|
||||
with pytest.raises(stix2.exceptions.CustomContentError) as excinfo:
|
||||
stix2.parse_observable(nt_string)
|
||||
stix2.parse_observable(nt_string, version='2.1')
|
||||
assert "Can't parse unknown observable type" in str(excinfo.value)
|
||||
|
||||
parsed_custom = stix2.parse_observable(nt_string, allow_custom=True)
|
||||
parsed_custom = stix2.parse_observable(nt_string, allow_custom=True, version='2.1')
|
||||
assert parsed_custom['property1'] == 'something'
|
||||
with pytest.raises(AttributeError) as excinfo:
|
||||
assert parsed_custom.property1 == 'something'
|
||||
|
@ -567,7 +566,7 @@ def test_parse_unregistered_custom_observable_object_with_no_type():
|
|||
}"""
|
||||
|
||||
with pytest.raises(stix2.exceptions.ParseError) as excinfo:
|
||||
stix2.parse_observable(nt_string, allow_custom=True)
|
||||
stix2.parse_observable(nt_string, allow_custom=True, version='2.1')
|
||||
assert "Can't parse observable with no 'type' property" in str(excinfo.value)
|
||||
|
||||
|
||||
|
@ -587,7 +586,7 @@ def test_parse_observed_data_with_custom_observable():
|
|||
}
|
||||
}
|
||||
}"""
|
||||
parsed = stix2.parse(input_str, allow_custom=True)
|
||||
parsed = stix2.parse(input_str, version="2.1", allow_custom=True)
|
||||
assert parsed.objects['0']['property1'] == 'something'
|
||||
|
||||
|
||||
|
@ -597,7 +596,7 @@ def test_parse_invalid_custom_observable_object():
|
|||
}"""
|
||||
|
||||
with pytest.raises(stix2.exceptions.ParseError) as excinfo:
|
||||
stix2.parse_observable(nt_string)
|
||||
stix2.parse_observable(nt_string, version='2.1')
|
||||
assert "Can't parse observable with no 'type' property" in str(excinfo.value)
|
||||
|
||||
|
||||
|
@ -639,7 +638,7 @@ def test_observable_custom_property_allowed():
|
|||
|
||||
def test_observed_data_with_custom_observable_object():
|
||||
no = NewObservable(property1='something')
|
||||
ob_data = stix2.ObservedData(
|
||||
ob_data = stix2.v21.ObservedData(
|
||||
first_observed=FAKE_TIME,
|
||||
last_observed=FAKE_TIME,
|
||||
number_observed=1,
|
||||
|
@ -649,9 +648,9 @@ def test_observed_data_with_custom_observable_object():
|
|||
assert ob_data.objects['0'].property1 == 'something'
|
||||
|
||||
|
||||
@stix2.observables.CustomExtension(stix2.DomainName, 'x-new-ext', [
|
||||
('property1', stix2.properties.StringProperty(required=True)),
|
||||
('property2', stix2.properties.IntegerProperty()),
|
||||
@stix2.v21.CustomExtension(stix2.v21.DomainName, 'x-new-ext', [
|
||||
('property1', stix2.v21.properties.StringProperty(required=True)),
|
||||
('property2', stix2.v21.properties.IntegerProperty()),
|
||||
])
|
||||
class NewExtension():
|
||||
def __init__(self, property2=None, **kwargs):
|
||||
|
@ -686,10 +685,11 @@ def test_custom_extension_wrong_observable_type():
|
|||
# NewExtension is an extension of DomainName, not File
|
||||
ext = NewExtension(property1='something')
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
stix2.File(name="abc.txt",
|
||||
extensions={
|
||||
"ntfs-ext": ext,
|
||||
})
|
||||
stix2.v21.File(
|
||||
name="abc.txt",
|
||||
extensions={
|
||||
"ntfs-ext": ext,
|
||||
})
|
||||
|
||||
assert 'Cannot determine extension type' in excinfo.value.reason
|
||||
|
||||
|
@ -705,8 +705,8 @@ def test_custom_extension_wrong_observable_type():
|
|||
}""",
|
||||
])
|
||||
def test_custom_extension_with_list_and_dict_properties_observable_type(data):
|
||||
@stix2.observables.CustomExtension(stix2.UserAccount, 'some-extension', [
|
||||
('keys', stix2.properties.ListProperty(stix2.properties.DictionaryProperty, required=True))
|
||||
@stix2.v21.CustomExtension(stix2.v21.UserAccount, 'some-extension', [
|
||||
('keys', stix2.v21.properties.ListProperty(stix2.v21.properties.DictionaryProperty, required=True))
|
||||
])
|
||||
class SomeCustomExtension:
|
||||
pass
|
||||
|
@ -721,29 +721,29 @@ def test_custom_extension_invalid_observable():
|
|||
class Foo(object):
|
||||
pass
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
@stix2.observables.CustomExtension(Foo, 'x-new-ext', [
|
||||
('property1', stix2.properties.StringProperty(required=True)),
|
||||
@stix2.v21.CustomExtension(Foo, 'x-new-ext', [
|
||||
('property1', stix2.v21.properties.StringProperty(required=True)),
|
||||
])
|
||||
class FooExtension():
|
||||
pass # pragma: no cover
|
||||
assert str(excinfo.value) == "'observable' must be a valid Observable class!"
|
||||
|
||||
class Bar(stix2.observables._Observable):
|
||||
class Bar(stix2.v21.observables._Observable):
|
||||
pass
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
@stix2.observables.CustomExtension(Bar, 'x-new-ext', [
|
||||
('property1', stix2.properties.StringProperty(required=True)),
|
||||
@stix2.v21.CustomExtension(Bar, 'x-new-ext', [
|
||||
('property1', stix2.v21.properties.StringProperty(required=True)),
|
||||
])
|
||||
class BarExtension():
|
||||
pass
|
||||
assert "Unknown observable type" in str(excinfo.value)
|
||||
assert "Custom observables must be created with the @CustomObservable decorator." in str(excinfo.value)
|
||||
|
||||
class Baz(stix2.observables._Observable):
|
||||
class Baz(stix2.v21.observables._Observable):
|
||||
_type = 'Baz'
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
@stix2.observables.CustomExtension(Baz, 'x-new-ext', [
|
||||
('property1', stix2.properties.StringProperty(required=True)),
|
||||
@stix2.v21.CustomExtension(Baz, 'x-new-ext', [
|
||||
('property1', stix2.v21.properties.StringProperty(required=True)),
|
||||
])
|
||||
class BazExtension():
|
||||
pass
|
||||
|
@ -753,16 +753,16 @@ def test_custom_extension_invalid_observable():
|
|||
|
||||
def test_custom_extension_invalid_type_name():
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
@stix2.observables.CustomExtension(stix2.File, 'x', {
|
||||
'property1': stix2.properties.StringProperty(required=True),
|
||||
@stix2.v21.CustomExtension(stix2.v21.File, 'x', {
|
||||
'property1': stix2.v21.properties.StringProperty(required=True),
|
||||
})
|
||||
class FooExtension():
|
||||
pass # pragma: no cover
|
||||
assert "Invalid extension type name 'x':" in str(excinfo.value)
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
@stix2.observables.CustomExtension(stix2.File, 'x_new_ext', {
|
||||
'property1': stix2.properties.StringProperty(required=True),
|
||||
@stix2.v21.CustomExtension(stix2.v21.File, 'x_new_ext', {
|
||||
'property1': stix2.v21.properties.StringProperty(required=True),
|
||||
})
|
||||
class BlaExtension():
|
||||
pass # pragma: no cover
|
||||
|
@ -771,7 +771,7 @@ def test_custom_extension_invalid_type_name():
|
|||
|
||||
def test_custom_extension_no_properties():
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
@stix2.observables.CustomExtension(stix2.DomainName, 'x-new-ext2', None)
|
||||
@stix2.v21.CustomExtension(stix2.v21.DomainName, 'x-new-ext2', None)
|
||||
class BarExtension():
|
||||
pass
|
||||
assert "Must supply a list, containing tuples." in str(excinfo.value)
|
||||
|
@ -779,7 +779,7 @@ def test_custom_extension_no_properties():
|
|||
|
||||
def test_custom_extension_empty_properties():
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
@stix2.observables.CustomExtension(stix2.DomainName, 'x-new-ext2', [])
|
||||
@stix2.v21.CustomExtension(stix2.v21.DomainName, 'x-new-ext2', [])
|
||||
class BarExtension():
|
||||
pass
|
||||
assert "Must supply a list, containing tuples." in str(excinfo.value)
|
||||
|
@ -787,15 +787,15 @@ def test_custom_extension_empty_properties():
|
|||
|
||||
def test_custom_extension_dict_properties():
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
@stix2.observables.CustomExtension(stix2.DomainName, 'x-new-ext2', {})
|
||||
@stix2.v21.CustomExtension(stix2.v21.DomainName, 'x-new-ext2', {})
|
||||
class BarExtension():
|
||||
pass
|
||||
assert "Must supply a list, containing tuples." in str(excinfo.value)
|
||||
|
||||
|
||||
def test_custom_extension_no_init_1():
|
||||
@stix2.observables.CustomExtension(stix2.DomainName, 'x-new-extension', [
|
||||
('property1', stix2.properties.StringProperty(required=True)),
|
||||
@stix2.v21.CustomExtension(stix2.v21.DomainName, 'x-new-extension', [
|
||||
('property1', stix2.v21.properties.StringProperty(required=True)),
|
||||
])
|
||||
class NewExt():
|
||||
pass
|
||||
|
@ -805,8 +805,8 @@ def test_custom_extension_no_init_1():
|
|||
|
||||
|
||||
def test_custom_extension_no_init_2():
|
||||
@stix2.observables.CustomExtension(stix2.DomainName, 'x-new-ext2', [
|
||||
('property1', stix2.properties.StringProperty(required=True)),
|
||||
@stix2.v21.CustomExtension(stix2.v21.DomainName, 'x-new-ext2', [
|
||||
('property1', stix2.v21.properties.StringProperty(required=True)),
|
||||
])
|
||||
class NewExt2(object):
|
||||
pass
|
||||
|
@ -827,7 +827,7 @@ def test_parse_observable_with_custom_extension():
|
|||
}
|
||||
}"""
|
||||
|
||||
parsed = stix2.parse_observable(input_str)
|
||||
parsed = stix2.parse_observable(input_str, version='2.1')
|
||||
assert parsed.extensions['x-new-ext'].property2 == 12
|
||||
|
||||
|
||||
|
@ -844,10 +844,10 @@ def test_parse_observable_with_unregistered_custom_extension():
|
|||
}"""
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
stix2.parse_observable(input_str)
|
||||
stix2.parse_observable(input_str, version='2.1')
|
||||
assert "Can't parse unknown extension type" in str(excinfo.value)
|
||||
|
||||
parsed_ob = stix2.parse_observable(input_str, allow_custom=True)
|
||||
parsed_ob = stix2.parse_observable(input_str, allow_custom=True, version='2.1')
|
||||
assert parsed_ob['extensions']['x-foobar-ext']['property1'] == 'foo'
|
||||
assert not isinstance(parsed_ob['extensions']['x-foobar-ext'], stix2.base._STIXBase)
|
||||
|
||||
|
@ -857,14 +857,14 @@ def test_register_custom_object():
|
|||
class CustomObject2(object):
|
||||
_type = 'awesome-object'
|
||||
|
||||
stix2._register_type(CustomObject2)
|
||||
stix2._register_object(CustomObject2, version="2.1")
|
||||
# Note that we will always check against newest OBJ_MAP.
|
||||
assert (CustomObject2._type, CustomObject2) in stix2.OBJ_MAP.items()
|
||||
assert (CustomObject2._type, CustomObject2) in stix2.v21.OBJ_MAP.items()
|
||||
|
||||
|
||||
def test_extension_property_location():
|
||||
assert 'extensions' in stix2.v21.observables.OBJ_MAP_OBSERVABLE['x-new-observable']._properties
|
||||
assert 'extensions' not in stix2.v21.observables.EXT_MAP['domain-name']['x-new-ext']._properties
|
||||
assert 'extensions' in stix2.v21.OBJ_MAP_OBSERVABLE['x-new-observable']._properties
|
||||
assert 'extensions' not in stix2.v21.EXT_MAP['domain-name']['x-new-ext']._properties
|
||||
|
||||
|
||||
@pytest.mark.parametrize("data", [
|
||||
|
@ -883,7 +883,7 @@ def test_extension_property_location():
|
|||
}""",
|
||||
])
|
||||
def test_custom_object_nested_dictionary(data):
|
||||
@stix2.sdo.CustomObject('x-example', [
|
||||
@stix2.v21.CustomObject('x-example', [
|
||||
('dictionary', stix2.v21.properties.DictionaryProperty()),
|
||||
])
|
||||
class Example(object):
|
||||
|
|
|
@ -439,7 +439,7 @@ def test_filesystem_object_with_custom_property_in_bundle(fs_store):
|
|||
|
||||
|
||||
def test_filesystem_custom_object(fs_store):
|
||||
@stix2.CustomObject('x-new-obj', [
|
||||
@stix2.v21.CustomObject('x-new-obj', [
|
||||
('property1', stix2.v21.properties.StringProperty(required=True)),
|
||||
])
|
||||
class NewObj():
|
||||
|
|
|
@ -63,14 +63,14 @@ def test_object_factory_obj_markings():
|
|||
stmt_marking = stix2.v21.StatementMarking("Copyright 2016, Example Corp")
|
||||
mark_def = stix2.v21.MarkingDefinition(definition_type="statement",
|
||||
definition=stmt_marking)
|
||||
factory = stix2.ObjectFactory(object_marking_refs=[mark_def, stix2.TLP_AMBER])
|
||||
factory = stix2.ObjectFactory(object_marking_refs=[mark_def, stix2.v21.TLP_AMBER])
|
||||
ind = factory.create(stix2.v21.Indicator, **INDICATOR_KWARGS)
|
||||
assert mark_def.id in ind.object_marking_refs
|
||||
assert stix2.TLP_AMBER.id in ind.object_marking_refs
|
||||
assert stix2.v21.TLP_AMBER.id in ind.object_marking_refs
|
||||
|
||||
factory = stix2.ObjectFactory(object_marking_refs=stix2.TLP_RED)
|
||||
factory = stix2.ObjectFactory(object_marking_refs=stix2.v21.TLP_RED)
|
||||
ind = factory.create(stix2.v21.Indicator, **INDICATOR_KWARGS)
|
||||
assert stix2.TLP_RED.id in ind.object_marking_refs
|
||||
assert stix2.v21.TLP_RED.id in ind.object_marking_refs
|
||||
|
||||
|
||||
def test_object_factory_list_append():
|
||||
|
@ -200,7 +200,7 @@ def test_parse_malware():
|
|||
],
|
||||
"is_family": false
|
||||
}"""
|
||||
mal = env.parse(data)
|
||||
mal = env.parse(data, version="2.1")
|
||||
|
||||
assert mal.type == 'malware'
|
||||
assert mal.spec_version == '2.1'
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from stix2 import TLP_RED, Malware, markings
|
||||
from stix2 import markings
|
||||
from stix2.v21 import Malware, TLP_RED
|
||||
from stix2.exceptions import MarkingNotFoundError
|
||||
|
||||
from .constants import MALWARE_MORE_KWARGS as MALWARE_KWARGS_CONST
|
||||
|
|
|
@ -4,7 +4,7 @@ import pytest
|
|||
import pytz
|
||||
|
||||
import stix2
|
||||
from stix2 import TLP_WHITE
|
||||
from stix2.v21 import TLP_WHITE
|
||||
|
||||
from .constants import MARKING_DEFINITION_ID
|
||||
|
||||
|
@ -166,6 +166,7 @@ def test_campaign_with_granular_markings_example():
|
|||
EXPECTED_TLP_MARKING_DEFINITION,
|
||||
{
|
||||
"id": "marking-definition--613f2e26-407d-48c7-9eca-b8e91df99dc9",
|
||||
"spec_version": "2.1",
|
||||
"type": "marking-definition",
|
||||
"created": "2017-01-20T00:00:00Z",
|
||||
"definition": {
|
||||
|
@ -185,7 +186,7 @@ def test_parse_marking_definition(data):
|
|||
assert gm.definition_type == "tlp"
|
||||
|
||||
|
||||
@stix2.common.CustomMarking('x-new-marking-type', [
|
||||
@stix2.v21.CustomMarking('x-new-marking-type', [
|
||||
('property1', stix2.v21.properties.StringProperty(required=True)),
|
||||
('property2', stix2.v21.properties.IntegerProperty()),
|
||||
])
|
||||
|
@ -223,7 +224,7 @@ def test_registered_custom_marking_raises_exception():
|
|||
def test_not_registered_marking_raises_exception():
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
# Used custom object on purpose to demonstrate a not-registered marking
|
||||
@stix2.sdo.CustomObject('x-new-marking-type2', [
|
||||
@stix2.v21.CustomObject('x-new-marking-type2', [
|
||||
('property1', stix2.v21.properties.StringProperty(required=True)),
|
||||
('property2', stix2.v21.properties.IntegerProperty()),
|
||||
])
|
||||
|
@ -246,7 +247,7 @@ def test_not_registered_marking_raises_exception():
|
|||
def test_marking_wrong_type_construction():
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
# Test passing wrong type for properties.
|
||||
@stix2.CustomMarking('x-new-marking-type2', ("a", "b"))
|
||||
@stix2.v21.CustomMarking('x-new-marking-type2', ("a", "b"))
|
||||
class NewObject3(object):
|
||||
pass
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@ import shutil
|
|||
|
||||
import pytest
|
||||
|
||||
from stix2 import (Bundle, Campaign, CustomObject, Filter, Identity, Indicator,
|
||||
Malware, MemorySource, MemoryStore, Relationship,
|
||||
properties)
|
||||
from stix2 import (Filter, MemorySource, MemoryStore, properties)
|
||||
from stix2.v21 import (Bundle, Campaign, CustomObject, Identity, Indicator,
|
||||
Malware, Relationship)
|
||||
from stix2.datastore import make_id
|
||||
|
||||
from .constants import (CAMPAIGN_ID, CAMPAIGN_KWARGS, IDENTITY_ID,
|
||||
|
@ -21,6 +21,7 @@ IND1 = {
|
|||
"modified": "2017-01-27T13:49:53.935Z",
|
||||
"name": "Malicious site hosting downloader",
|
||||
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
||||
"spec_version": "2.1",
|
||||
"type": "indicator",
|
||||
"valid_from": "2017-01-27T13:49:53.935382Z"
|
||||
}
|
||||
|
@ -33,6 +34,7 @@ IND2 = {
|
|||
"modified": "2017-01-27T13:49:53.935Z",
|
||||
"name": "Malicious site hosting downloader",
|
||||
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
||||
"spec_version": "2.1",
|
||||
"type": "indicator",
|
||||
"valid_from": "2017-01-27T13:49:53.935382Z"
|
||||
}
|
||||
|
@ -45,6 +47,7 @@ IND3 = {
|
|||
"modified": "2017-01-27T13:49:53.936Z",
|
||||
"name": "Malicious site hosting downloader",
|
||||
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
||||
"spec_version": "2.1",
|
||||
"type": "indicator",
|
||||
"valid_from": "2017-01-27T13:49:53.935382Z"
|
||||
}
|
||||
|
@ -57,6 +60,7 @@ IND4 = {
|
|||
"modified": "2017-01-27T13:49:53.935Z",
|
||||
"name": "Malicious site hosting downloader",
|
||||
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
||||
"spec_version": "2.1",
|
||||
"type": "indicator",
|
||||
"valid_from": "2017-01-27T13:49:53.935382Z"
|
||||
}
|
||||
|
@ -69,6 +73,7 @@ IND5 = {
|
|||
"modified": "2017-01-27T13:49:53.935Z",
|
||||
"name": "Malicious site hosting downloader",
|
||||
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
||||
"spec_version": "2.1",
|
||||
"type": "indicator",
|
||||
"valid_from": "2017-01-27T13:49:53.935382Z"
|
||||
}
|
||||
|
@ -81,6 +86,7 @@ IND6 = {
|
|||
"modified": "2017-01-31T13:49:53.935Z",
|
||||
"name": "Malicious site hosting downloader",
|
||||
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
||||
"spec_version": "2.1",
|
||||
"type": "indicator",
|
||||
"valid_from": "2017-01-27T13:49:53.935382Z"
|
||||
}
|
||||
|
@ -93,6 +99,7 @@ IND7 = {
|
|||
"modified": "2017-01-27T13:49:53.935Z",
|
||||
"name": "Malicious site hosting downloader",
|
||||
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
||||
"spec_version": "2.1",
|
||||
"type": "indicator",
|
||||
"valid_from": "2017-01-27T13:49:53.935382Z"
|
||||
}
|
||||
|
@ -105,6 +112,7 @@ IND8 = {
|
|||
"modified": "2017-01-27T13:49:53.935Z",
|
||||
"name": "Malicious site hosting downloader",
|
||||
"pattern": "[url:value = 'http://x4z9arb.cn/4712']",
|
||||
"spec_version": "2.1",
|
||||
"type": "indicator",
|
||||
"valid_from": "2017-01-27T13:49:53.935382Z"
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import pytest
|
||||
|
||||
from stix2 import TLP_AMBER, Malware, exceptions, markings
|
||||
from stix2 import exceptions, markings
|
||||
from stix2.v21 import TLP_AMBER, Malware
|
||||
|
||||
from .constants import FAKE_TIME, MALWARE_ID
|
||||
from .constants import MALWARE_KWARGS as MALWARE_KWARGS_CONST
|
||||
|
|
|
@ -275,12 +275,12 @@ def test_parse_autonomous_system_valid(data):
|
|||
}""",
|
||||
])
|
||||
def test_parse_email_address(data):
|
||||
odata = stix2.parse_observable(data, {"0": "user-account"})
|
||||
odata = stix2.parse_observable(data, {"0": "user-account"}, version='2.1')
|
||||
assert odata.type == "email-addr"
|
||||
|
||||
odata_str = re.compile('"belongs_to_ref": "0"', re.DOTALL).sub('"belongs_to_ref": "3"', data)
|
||||
with pytest.raises(stix2.exceptions.InvalidObjRefError):
|
||||
stix2.parse_observable(odata_str, {"0": "user-account"})
|
||||
stix2.parse_observable(odata_str, {"0": "user-account"}, version='2.1')
|
||||
|
||||
|
||||
@pytest.mark.parametrize("data", [
|
||||
|
@ -332,7 +332,7 @@ def test_parse_email_message(data):
|
|||
"4": "artifact",
|
||||
"5": "file",
|
||||
}
|
||||
odata = stix2.parse_observable(data, valid_refs)
|
||||
odata = stix2.parse_observable(data, valid_refs, version='2.1')
|
||||
assert odata.type == "email-message"
|
||||
assert odata.body_multipart[0].content_disposition == "inline"
|
||||
|
||||
|
@ -356,7 +356,7 @@ def test_parse_email_message_not_multipart(data):
|
|||
"1": "email-addr",
|
||||
}
|
||||
with pytest.raises(stix2.exceptions.DependentPropertiesError) as excinfo:
|
||||
stix2.parse_observable(data, valid_refs)
|
||||
stix2.parse_observable(data, valid_refs, version='2.1')
|
||||
|
||||
assert excinfo.value.cls == stix2.v21.EmailMessage
|
||||
assert excinfo.value.dependencies == [("is_multipart", "body")]
|
||||
|
@ -455,7 +455,7 @@ def test_parse_email_message_with_at_least_one_error(data):
|
|||
"5": "file",
|
||||
}
|
||||
with pytest.raises(stix2.exceptions.AtLeastOnePropertyError) as excinfo:
|
||||
stix2.parse_observable(data, valid_refs)
|
||||
stix2.parse_observable(data, valid_refs, version='2.1')
|
||||
|
||||
assert excinfo.value.cls == stix2.v21.EmailMIMEComponent
|
||||
assert excinfo.value.properties == ["body", "body_raw_ref"]
|
||||
|
@ -476,7 +476,8 @@ def test_parse_email_message_with_at_least_one_error(data):
|
|||
"""
|
||||
])
|
||||
def test_parse_basic_tcp_traffic(data):
|
||||
odata = stix2.parse_observable(data, {"0": "ipv4-addr", "1": "ipv4-addr"})
|
||||
odata = stix2.parse_observable(data, {"0": "ipv4-addr", "1": "ipv4-addr"},
|
||||
version='2.1')
|
||||
|
||||
assert odata.type == "network-traffic"
|
||||
assert odata.src_ref == "0"
|
||||
|
@ -504,7 +505,7 @@ def test_parse_basic_tcp_traffic(data):
|
|||
])
|
||||
def test_parse_basic_tcp_traffic_with_error(data):
|
||||
with pytest.raises(stix2.exceptions.AtLeastOnePropertyError) as excinfo:
|
||||
stix2.parse_observable(data, {"4": "network-traffic"})
|
||||
stix2.parse_observable(data, {"4": "network-traffic"}, version='2.1')
|
||||
|
||||
assert excinfo.value.cls == stix2.v21.NetworkTraffic
|
||||
assert excinfo.value.properties == ["dst_ref", "src_ref"]
|
||||
|
|
Loading…
Reference in New Issue