Update tests.
parent
9baaad6e08
commit
59fdd3082e
|
@ -2,6 +2,7 @@ import importlib
|
||||||
import pkgutil
|
import pkgutil
|
||||||
|
|
||||||
import stix2
|
import stix2
|
||||||
|
|
||||||
from .exceptions import ParseError
|
from .exceptions import ParseError
|
||||||
from .utils import _get_dict
|
from .utils import _get_dict
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,8 @@ import json
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import stix2
|
import stix2
|
||||||
import stix2.v20.sdo
|
|
||||||
import stix2.v21.bundle
|
import stix2.v21.bundle
|
||||||
|
import stix2.v21.sdo
|
||||||
|
|
||||||
EXPECTED_BUNDLE = """{
|
EXPECTED_BUNDLE = """{
|
||||||
"type": "bundle",
|
"type": "bundle",
|
||||||
|
@ -179,8 +179,7 @@ def test_parse_bundle(version):
|
||||||
|
|
||||||
assert bundle.type == "bundle"
|
assert bundle.type == "bundle"
|
||||||
assert bundle.id.startswith("bundle--")
|
assert bundle.id.startswith("bundle--")
|
||||||
# TODO: update this to a STIX 2.1 indicator
|
assert type(bundle.objects[0]) is stix2.v21.sdo.Indicator
|
||||||
assert type(bundle.objects[0]) is stix2.v20.sdo.Indicator
|
|
||||||
assert bundle.objects[0].type == 'indicator'
|
assert bundle.objects[0].type == 'indicator'
|
||||||
assert bundle.objects[1].type == 'malware'
|
assert bundle.objects[1].type == 'malware'
|
||||||
assert bundle.objects[2].type == 'relationship'
|
assert bundle.objects[2].type == 'relationship'
|
||||||
|
|
|
@ -2,7 +2,7 @@ import pytest
|
||||||
|
|
||||||
import stix2
|
import stix2
|
||||||
import stix2.base
|
import stix2.base
|
||||||
import stix2.v20.sdo
|
import stix2.v21.sdo
|
||||||
|
|
||||||
from .constants import FAKE_TIME, MARKING_DEFINITION_ID
|
from .constants import FAKE_TIME, MARKING_DEFINITION_ID
|
||||||
|
|
||||||
|
@ -95,8 +95,7 @@ def test_identity_custom_property_allowed():
|
||||||
def test_parse_identity_custom_property(data):
|
def test_parse_identity_custom_property(data):
|
||||||
with pytest.raises(stix2.exceptions.ExtraPropertiesError) as excinfo:
|
with pytest.raises(stix2.exceptions.ExtraPropertiesError) as excinfo:
|
||||||
identity = stix2.parse(data)
|
identity = stix2.parse(data)
|
||||||
# TODO: update to create and check a STIX 2.1 Identity object
|
assert excinfo.value.cls == stix2.v21.sdo.Identity
|
||||||
assert excinfo.value.cls == stix2.v20.sdo.Identity
|
|
||||||
assert excinfo.value.properties == ['foo']
|
assert excinfo.value.properties == ['foo']
|
||||||
assert "Unexpected properties for" in str(excinfo.value)
|
assert "Unexpected properties for" in str(excinfo.value)
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
import datetime as dt
|
import datetime as dt
|
||||||
|
|
||||||
import pytest
|
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
import stix2
|
import stix2
|
||||||
|
@ -21,7 +20,7 @@ TEST_CAMPAIGN = """{
|
||||||
"description": "More information about bank attack"
|
"description": "More information about bank attack"
|
||||||
}"""
|
}"""
|
||||||
|
|
||||||
TEST_LANGUAGE_CONTENT = """{
|
TEST_LANGUAGE_CONTENT = u"""{
|
||||||
"type": "language-content",
|
"type": "language-content",
|
||||||
"id": "language-content--b86bd89f-98bb-4fa9-8cb2-9ad421da981d",
|
"id": "language-content--b86bd89f-98bb-4fa9-8cb2-9ad421da981d",
|
||||||
"created": "2017-02-08T21:31:22.007Z",
|
"created": "2017-02-08T21:31:22.007Z",
|
||||||
|
@ -30,18 +29,17 @@ TEST_LANGUAGE_CONTENT = """{
|
||||||
"object_modified": "2017-02-08T21:31:22.007Z",
|
"object_modified": "2017-02-08T21:31:22.007Z",
|
||||||
"contents": {
|
"contents": {
|
||||||
"de": {
|
"de": {
|
||||||
"name": "Bank Angriff 1",
|
"description": "Weitere Informationen über Banküberfall",
|
||||||
"description": "Weitere Informationen über Banküberfall"
|
"name": "Bank Angriff 1"
|
||||||
},
|
},
|
||||||
"fr": {
|
"fr": {
|
||||||
"name": "Attaque Bank 1",
|
"description": "Plus d'informations sur la crise bancaire",
|
||||||
"description": "Plus d'informations sur la crise bancaire"
|
"name": "Attaque Bank 1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}"""
|
}"""
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(reason="Dictionary keys are too short")
|
|
||||||
def test_language_content_campaign():
|
def test_language_content_campaign():
|
||||||
now = dt.datetime(2017, 2, 8, 21, 31, 22, microsecond=7000, tzinfo=pytz.utc)
|
now = dt.datetime(2017, 2, 8, 21, 31, 22, microsecond=7000, tzinfo=pytz.utc)
|
||||||
|
|
||||||
|
@ -66,5 +64,8 @@ def test_language_content_campaign():
|
||||||
|
|
||||||
camp = stix2.parse(TEST_CAMPAIGN)
|
camp = stix2.parse(TEST_CAMPAIGN)
|
||||||
|
|
||||||
assert str(lc) in TEST_LANGUAGE_CONTENT
|
# In order to provide the same representation, we need to disable escaping
|
||||||
|
# in json.dumps(). https://docs.python.org/3/library/json.html#json.dumps
|
||||||
|
# or https://docs.python.org/2/library/json.html#json.dumps
|
||||||
|
assert lc.serialize(pretty=True, ensure_ascii=False) == TEST_LANGUAGE_CONTENT
|
||||||
assert lc.modified == camp.modified
|
assert lc.modified == camp.modified
|
||||||
|
|
|
@ -2,12 +2,13 @@ import pytest
|
||||||
|
|
||||||
from stix2 import CustomObject, EmailMIMEComponent, ExtensionsProperty, TCPExt
|
from stix2 import CustomObject, EmailMIMEComponent, ExtensionsProperty, TCPExt
|
||||||
from stix2.exceptions import AtLeastOnePropertyError, DictionaryKeyError
|
from stix2.exceptions import AtLeastOnePropertyError, DictionaryKeyError
|
||||||
from stix2.properties import (BinaryProperty, BooleanProperty,
|
from stix2.v20.properties import (BinaryProperty, BooleanProperty,
|
||||||
DictionaryProperty, EmbeddedObjectProperty,
|
DictionaryProperty, EmbeddedObjectProperty,
|
||||||
EnumProperty, FloatProperty, HashesProperty,
|
EnumProperty, FloatProperty, HashesProperty,
|
||||||
HexProperty, IDProperty, IntegerProperty,
|
HexProperty, IDProperty, IntegerProperty,
|
||||||
ListProperty, Property, ReferenceProperty,
|
ListProperty, Property, ReferenceProperty,
|
||||||
StringProperty, TimestampProperty, TypeProperty)
|
StringProperty, TimestampProperty,
|
||||||
|
TypeProperty)
|
||||||
|
|
||||||
from .constants import FAKE_TIME
|
from .constants import FAKE_TIME
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue