Update stix2.1 course-of-action support to the latest spec.
parent
06e23b08b8
commit
caa1d45ae2
|
@ -4,6 +4,7 @@ import pytest
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
import stix2
|
import stix2
|
||||||
|
import stix2.exceptions
|
||||||
|
|
||||||
from .constants import COURSE_OF_ACTION_ID
|
from .constants import COURSE_OF_ACTION_ID
|
||||||
|
|
||||||
|
@ -15,7 +16,14 @@ EXPECTED = """{
|
||||||
"created": "2016-04-06T20:03:48.000Z",
|
"created": "2016-04-06T20:03:48.000Z",
|
||||||
"modified": "2016-04-06T20:03:48.000Z",
|
"modified": "2016-04-06T20:03:48.000Z",
|
||||||
"name": "Add TCP port 80 Filter Rule to the existing Block UDP 1434 Filter",
|
"name": "Add TCP port 80 Filter Rule to the existing Block UDP 1434 Filter",
|
||||||
"description": "This is how to add a filter rule to block inbound access to TCP port 80 to the existing UDP 1434 filter ..."
|
"description": "This is how to add a filter rule to block inbound access to TCP port 80 to the existing UDP 1434 filter ...",
|
||||||
|
"action_type": "textual:text/plain",
|
||||||
|
"os_execution_envs": [
|
||||||
|
"a",
|
||||||
|
"b",
|
||||||
|
"c"
|
||||||
|
],
|
||||||
|
"action_bin": "aGVsbG8gd29ybGQ="
|
||||||
}"""
|
}"""
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,6 +35,9 @@ def test_course_of_action_example():
|
||||||
modified="2016-04-06T20:03:48.000Z",
|
modified="2016-04-06T20:03:48.000Z",
|
||||||
name="Add TCP port 80 Filter Rule to the existing Block UDP 1434 Filter",
|
name="Add TCP port 80 Filter Rule to the existing Block UDP 1434 Filter",
|
||||||
description="This is how to add a filter rule to block inbound access to TCP port 80 to the existing UDP 1434 filter ...",
|
description="This is how to add a filter rule to block inbound access to TCP port 80 to the existing UDP 1434 filter ...",
|
||||||
|
action_type="textual:text/plain",
|
||||||
|
os_execution_envs=["a", "b", "c"],
|
||||||
|
action_bin="aGVsbG8gd29ybGQ="
|
||||||
)
|
)
|
||||||
|
|
||||||
assert str(coa) == EXPECTED
|
assert str(coa) == EXPECTED
|
||||||
|
@ -44,6 +55,9 @@ def test_course_of_action_example():
|
||||||
"name": "Add TCP port 80 Filter Rule to the existing Block UDP 1434 Filter",
|
"name": "Add TCP port 80 Filter Rule to the existing Block UDP 1434 Filter",
|
||||||
"spec_version": "2.1",
|
"spec_version": "2.1",
|
||||||
"type": "course-of-action",
|
"type": "course-of-action",
|
||||||
|
"action_type": "textual:text/plain",
|
||||||
|
"os_execution_envs": ["a", "b", "c"],
|
||||||
|
"action_bin": "aGVsbG8gd29ybGQ="
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@ -58,5 +72,20 @@ def test_parse_course_of_action(data):
|
||||||
assert coa.created_by_ref == "identity--f431f809-377b-45e0-aa1c-6a4751cae5ff"
|
assert coa.created_by_ref == "identity--f431f809-377b-45e0-aa1c-6a4751cae5ff"
|
||||||
assert coa.description == "This is how to add a filter rule to block inbound access to TCP port 80 to the existing UDP 1434 filter ..."
|
assert coa.description == "This is how to add a filter rule to block inbound access to TCP port 80 to the existing UDP 1434 filter ..."
|
||||||
assert coa.name == "Add TCP port 80 Filter Rule to the existing Block UDP 1434 Filter"
|
assert coa.name == "Add TCP port 80 Filter Rule to the existing Block UDP 1434 Filter"
|
||||||
|
assert coa.action_type == "textual:text/plain"
|
||||||
|
assert coa.os_execution_envs == ["a", "b", "c"]
|
||||||
|
assert coa.action_bin == "aGVsbG8gd29ybGQ="
|
||||||
|
|
||||||
|
|
||||||
|
def test_course_of_action_constraint():
|
||||||
|
with pytest.raises(stix2.exceptions.MutuallyExclusivePropertiesError):
|
||||||
|
stix2.v21.CourseOfAction(
|
||||||
|
name="Add TCP port 80 Filter Rule to the existing Block UDP 1434 Filter",
|
||||||
|
action_bin="aGVsbG8gd29ybGQ=",
|
||||||
|
action_reference=stix2.v21.ExternalReference(
|
||||||
|
source_name="a source",
|
||||||
|
description="description of a source"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
# TODO: Add other examples
|
# TODO: Add other examples
|
||||||
|
|
|
@ -97,6 +97,10 @@ class CourseOfAction(STIXDomainObject):
|
||||||
('modified', TimestampProperty(default=lambda: NOW, precision='millisecond')),
|
('modified', TimestampProperty(default=lambda: NOW, precision='millisecond')),
|
||||||
('name', StringProperty(required=True)),
|
('name', StringProperty(required=True)),
|
||||||
('description', StringProperty()),
|
('description', StringProperty()),
|
||||||
|
('action_type', StringProperty()),
|
||||||
|
('os_execution_envs', ListProperty(StringProperty)),
|
||||||
|
('action_bin', StringProperty()),
|
||||||
|
('action_reference', StringProperty()),
|
||||||
('revoked', BooleanProperty(default=lambda: False)),
|
('revoked', BooleanProperty(default=lambda: False)),
|
||||||
('labels', ListProperty(StringProperty)),
|
('labels', ListProperty(StringProperty)),
|
||||||
('confidence', IntegerProperty()),
|
('confidence', IntegerProperty()),
|
||||||
|
@ -106,6 +110,14 @@ class CourseOfAction(STIXDomainObject):
|
||||||
('granular_markings', ListProperty(GranularMarking)),
|
('granular_markings', ListProperty(GranularMarking)),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
def _check_object_constraints(self):
|
||||||
|
super(CourseOfAction, self)._check_object_constraints()
|
||||||
|
|
||||||
|
self._check_mutually_exclusive_properties(
|
||||||
|
["action_bin", "action_reference"],
|
||||||
|
at_least_one=False
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Identity(STIXDomainObject):
|
class Identity(STIXDomainObject):
|
||||||
# TODO: Add link
|
# TODO: Add link
|
||||||
|
|
Loading…
Reference in New Issue