add new file test_extension_definition.py and assigned new UUIDs to the constants
parent
35ef718b70
commit
203a2746e0
|
@ -28,10 +28,10 @@ SIGHTING_ID = "sighting--bfbc19db-ec35-4e45-beed-f8bde2a772fb"
|
|||
VULNERABILITY_ID = "vulnerability--0c7b5b88-8ff7-4a4d-aa9d-feb398cd0061"
|
||||
|
||||
EXTENSION_DEFINITION_IDS = [
|
||||
"extension-definition--a932fcc6-e032-176c-126f-cb970a5a1fff", # new-sdo
|
||||
"extension-definition--d83fce45-ef58-4c6c-a3f4-1fbc32e98c6e", # property-extension
|
||||
"extension-definition--71736db5-10db-43d3-b0e3-65cf81601fe1", # top-level-property-extension
|
||||
"extension-definition--a932fcc6-e032-176c-126f-cb970a5a1fff", # new-sdo, new-sco, property-extension
|
||||
"extension-definition--1f611280-fbe1-48e8-92ab-ff47ce02d5b7", # new-sdo
|
||||
"extension-definition--368f4787-5b43-467c-9693-0c9de4289c4b", # property-extension
|
||||
"extension-definition--dd73de4f-a7f3-49ea-8ec1-8e884196b7a8", # top-level-property-extension
|
||||
"extension-definition--150c1738-28c9-44d0-802d-70523218240b", # new-sdo, new-sco, property-extension
|
||||
]
|
||||
MARKING_IDS = [
|
||||
"marking-definition--613f2e26-407d-48c7-9eca-b8e91df99dc9",
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
import datetime as dt
|
||||
|
||||
import pytest
|
||||
import pytz
|
||||
|
||||
import stix2
|
||||
|
||||
from .constants import EXTENSION_DEFINITION_IDS
|
||||
|
||||
EXPECTED = f"""{{
|
||||
"type": "extension-definition",
|
||||
"spec_version": "2.1",
|
||||
"id": "{EXTENSION_DEFINITION_IDS[0]}",
|
||||
"created_by_ref": "identity--11b76a96-5d2b-45e0-8a5a-f6994f370731",
|
||||
"created": "2014-02-20T09:16:08.000Z",
|
||||
"modified": "2014-02-20T09:16:08.000Z",
|
||||
"name": "New SDO 1",
|
||||
"description": "This schema creates a new object type called my-favorite-sdo-1",
|
||||
"schema": "https://www.example.com/schema-my-favorite-sdo-1/v1/",
|
||||
"version": "1.2.1",
|
||||
"extension_types": [
|
||||
"new-sdo"
|
||||
]
|
||||
}}"""
|
||||
|
||||
|
||||
def test_extension_definition_example():
|
||||
extension_definition = stix2.v21.ExtensionDefinition(
|
||||
id=EXTENSION_DEFINITION_IDS[0],
|
||||
created_by_ref="identity--11b76a96-5d2b-45e0-8a5a-f6994f370731",
|
||||
created="2014-02-20T09:16:08.000Z",
|
||||
modified="2014-02-20T09:16:08.000Z",
|
||||
name="New SDO 1",
|
||||
description="This schema creates a new object type called my-favorite-sdo-1",
|
||||
schema="https://www.example.com/schema-my-favorite-sdo-1/v1/",
|
||||
version="1.2.1",
|
||||
extension_types=["new-sdo"],
|
||||
)
|
||||
|
||||
assert extension_definition.serialize(pretty=True) == EXPECTED
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"data", [
|
||||
EXPECTED,
|
||||
{
|
||||
"id": f"{EXTENSION_DEFINITION_IDS[0]}",
|
||||
"type": "extension-definition",
|
||||
"spec_version": "2.1",
|
||||
"created_by_ref": "identity--11b76a96-5d2b-45e0-8a5a-f6994f370731",
|
||||
"created": "2014-02-20T09:16:08.000Z",
|
||||
"modified": "2014-02-20T09:16:08.000Z",
|
||||
"name": "New SDO 1",
|
||||
"description": "This schema creates a new object type called my-favorite-sdo-1",
|
||||
"schema": "https://www.example.com/schema-my-favorite-sdo-1/v1/",
|
||||
"version": "1.2.1",
|
||||
"extension_types": ["new-sdo"]
|
||||
},
|
||||
],
|
||||
)
|
||||
def test_parse_extension_definition(data):
|
||||
extension_definition = stix2.parse(data, version="2.1")
|
||||
|
||||
assert extension_definition.type == 'extension-definition'
|
||||
assert extension_definition.spec_version == '2.1'
|
||||
assert extension_definition.id == EXTENSION_DEFINITION_IDS[0]
|
||||
assert extension_definition.created == dt.datetime(2014, 2, 20, 9, 16, 8, tzinfo=pytz.utc)
|
||||
assert extension_definition.modified == dt.datetime(2014, 2, 20, 9, 16, 8, tzinfo=pytz.utc)
|
||||
assert extension_definition.name == 'New SDO 1'
|
||||
assert extension_definition.description == 'This schema creates a new object type called my-favorite-sdo-1'
|
||||
assert extension_definition.schema == 'https://www.example.com/schema-my-favorite-sdo-1/v1/'
|
||||
assert extension_definition.version == '1.2.1'
|
||||
assert extension_definition.extension_types == ['new-sdo']
|
||||
|
||||
|
||||
def test_parse_no_type():
|
||||
with pytest.raises(stix2.exceptions.ParseError):
|
||||
stix2.parse("""{
|
||||
"id": "{EXTENSION_DEFINITION_IDS[0]}",
|
||||
"spec_version": "2.1",
|
||||
"name": "New SDO 1",
|
||||
"description": "This schema creates a new object type called my-favorite-sdo-1",
|
||||
"created": "2014-02-20T09:16:08.989000Z",
|
||||
"modified": "2014-02-20T09:16:08.989000Z",
|
||||
"created_by_ref": "identity--11b76a96-5d2b-45e0-8a5a-f6994f370731",
|
||||
"schema": "https://www.example.com/schema-my-favorite-sdo-1/v1/",
|
||||
"version": "1.2.1",
|
||||
"extension_types": [ "new-sdo" ]
|
||||
}""", version="2.1",
|
||||
)
|
||||
|
||||
|
||||
def test_extension_definition_with_custom():
|
||||
extension_definition = stix2.v21.ExtensionDefinition(
|
||||
created_by_ref="identity--11b76a96-5d2b-45e0-8a5a-f6994f370731",
|
||||
created="2014-02-20T09:16:08.000Z",
|
||||
modified="2014-02-20T09:16:08.000Z",
|
||||
name="New SDO 1",
|
||||
description="This schema creates a new object type called my-favorite-sdo-1",
|
||||
schema="https://www.example.com/schema-my-favorite-sdo-1/v1/",
|
||||
version="1.2.1",
|
||||
extension_types=["new-sdo"],
|
||||
custom_properties={'x_foo': 'bar'},
|
||||
)
|
||||
|
||||
assert extension_definition.x_foo == "bar"
|
||||
assert "x_foo" in extension_definition.object_properties()
|
Loading…
Reference in New Issue