From 36f70357852d949683cb42b05e255d2197fd13ee Mon Sep 17 00:00:00 2001 From: "Desai, Kartikey H" Date: Wed, 19 Feb 2020 09:34:23 -0500 Subject: [PATCH 1/4] Fixes #338 --- stix2/test/v21/test_course_of_action.py | 34 ++----------------------- stix2/v21/sdo.py | 20 +++++---------- 2 files changed, 8 insertions(+), 46 deletions(-) diff --git a/stix2/test/v21/test_course_of_action.py b/stix2/test/v21/test_course_of_action.py index 44079fb..ca8a303 100644 --- a/stix2/test/v21/test_course_of_action.py +++ b/stix2/test/v21/test_course_of_action.py @@ -8,42 +8,23 @@ import stix2.utils COA_WITH_BIN_JSON = """{ "type": "course-of-action", - "spec_version": "2.1", "id": "course-of-action--8e2e2d2b-17d4-4cbf-938f-98ee46b3cd3f", "created_by_ref": "identity--311b2d2d-f010-4473-83ec-1edf84858f4c", "created": "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", - "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=" + "description": "This is how to add a filter rule to block inbound access to TCP port 80 to the existing UDP 1434 filter ..." }""" COA_WITH_REF_JSON = """{ "type": "course-of-action", - "spec_version": "2.1", "id": "course-of-action--8e2e2d2b-17d4-4cbf-938f-98ee46b3cd3f", "created_by_ref": "identity--311b2d2d-f010-4473-83ec-1edf84858f4c", "created": "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", - "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_reference": { - "source_name": "a source", - "description": "description of a source" - } + "description": "This is how to add a filter rule to block inbound access to TCP port 80 to the existing UDP 1434 filter ..." }""" @@ -84,15 +65,4 @@ def test_parse_course_of_action(sdo_json, sdo_dict): assert getattr(coa, attr_name) == cmp_value -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 diff --git a/stix2/v21/sdo.py b/stix2/v21/sdo.py index 1d97261..59ef168 100644 --- a/stix2/v21/sdo.py +++ b/stix2/v21/sdo.py @@ -13,10 +13,9 @@ from ..exceptions import ( InvalidValueError, PropertyPresenceError, STIXDeprecationWarning, ) from ..properties import ( - BinaryProperty, BooleanProperty, EmbeddedObjectProperty, EnumProperty, - FloatProperty, IDProperty, IntegerProperty, ListProperty, - ObservableProperty, PatternProperty, ReferenceProperty, StringProperty, - TimestampProperty, TypeProperty, + BooleanProperty, EnumProperty, FloatProperty, IDProperty, IntegerProperty, + ListProperty, ObservableProperty, PatternProperty, ReferenceProperty, + StringProperty, TimestampProperty, TypeProperty, ) from ..utils import NOW from .common import ExternalReference, GranularMarking, KillChainPhase @@ -99,23 +98,16 @@ class CourseOfAction(STIXDomainObject): _type = 'course-of-action' _properties = OrderedDict([ ('type', TypeProperty(_type)), - ('spec_version', StringProperty(fixed='2.1')), - ('id', IDProperty(_type, spec_version='2.1')), - ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), + ('id', IDProperty(_type, spec_version='2.0')), + ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.0')), ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), ('modified', TimestampProperty(default=lambda: NOW, precision='millisecond')), ('name', StringProperty(required=True)), ('description', StringProperty()), - ('action_type', StringProperty()), - ('os_execution_envs', ListProperty(StringProperty)), - ('action_bin', BinaryProperty()), - ('action_reference', EmbeddedObjectProperty(ExternalReference)), ('revoked', BooleanProperty(default=lambda: False)), ('labels', ListProperty(StringProperty)), - ('confidence', IntegerProperty()), - ('lang', StringProperty()), ('external_references', ListProperty(ExternalReference)), - ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), + ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.0'))), ('granular_markings', ListProperty(GranularMarking)), ]) From 8885a757cb81943ed01f928280bcf04aea4fdbc6 Mon Sep 17 00:00:00 2001 From: "Desai, Kartikey H" Date: Mon, 24 Feb 2020 12:09:11 -0500 Subject: [PATCH 2/4] Fix properties spec version back to 2.1, and re-adjust tests. Fixes #338 --- stix2/test/v21/test_course_of_action.py | 2 ++ stix2/v21/sdo.py | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/stix2/test/v21/test_course_of_action.py b/stix2/test/v21/test_course_of_action.py index ca8a303..5eea908 100644 --- a/stix2/test/v21/test_course_of_action.py +++ b/stix2/test/v21/test_course_of_action.py @@ -8,6 +8,7 @@ import stix2.utils COA_WITH_BIN_JSON = """{ "type": "course-of-action", + "spec_version": "2.1", "id": "course-of-action--8e2e2d2b-17d4-4cbf-938f-98ee46b3cd3f", "created_by_ref": "identity--311b2d2d-f010-4473-83ec-1edf84858f4c", "created": "2016-04-06T20:03:48.000Z", @@ -19,6 +20,7 @@ COA_WITH_BIN_JSON = """{ COA_WITH_REF_JSON = """{ "type": "course-of-action", + "spec_version": "2.1", "id": "course-of-action--8e2e2d2b-17d4-4cbf-938f-98ee46b3cd3f", "created_by_ref": "identity--311b2d2d-f010-4473-83ec-1edf84858f4c", "created": "2016-04-06T20:03:48.000Z", diff --git a/stix2/v21/sdo.py b/stix2/v21/sdo.py index 59ef168..12a83bd 100644 --- a/stix2/v21/sdo.py +++ b/stix2/v21/sdo.py @@ -98,8 +98,9 @@ class CourseOfAction(STIXDomainObject): _type = 'course-of-action' _properties = OrderedDict([ ('type', TypeProperty(_type)), - ('id', IDProperty(_type, spec_version='2.0')), - ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.0')), + ('spec_version', StringProperty(fixed='2.1')), + ('id', IDProperty(_type, spec_version='2.1')), + ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), ('modified', TimestampProperty(default=lambda: NOW, precision='millisecond')), ('name', StringProperty(required=True)), @@ -107,7 +108,7 @@ class CourseOfAction(STIXDomainObject): ('revoked', BooleanProperty(default=lambda: False)), ('labels', ListProperty(StringProperty)), ('external_references', ListProperty(ExternalReference)), - ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.0'))), + ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('granular_markings', ListProperty(GranularMarking)), ]) From 82517ae28499a9a1029d2ebacfcb65fd0b7612a0 Mon Sep 17 00:00:00 2001 From: "Desai, Kartikey H" Date: Mon, 24 Feb 2020 12:28:07 -0500 Subject: [PATCH 3/4] Fixes #338 --- stix2/v21/sdo.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/stix2/v21/sdo.py b/stix2/v21/sdo.py index 12a83bd..7685401 100644 --- a/stix2/v21/sdo.py +++ b/stix2/v21/sdo.py @@ -112,14 +112,6 @@ class CourseOfAction(STIXDomainObject): ('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 Grouping(STIXDomainObject): # TODO: Add link From 3dd9351d38f3026233583c1d79f42e1c8989021d Mon Sep 17 00:00:00 2001 From: Chris Lenk Date: Thu, 12 Mar 2020 09:18:23 -0400 Subject: [PATCH 4/4] Bring back lang, confidence for Course of Action --- stix2/v21/sdo.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stix2/v21/sdo.py b/stix2/v21/sdo.py index 7685401..be6da3a 100644 --- a/stix2/v21/sdo.py +++ b/stix2/v21/sdo.py @@ -107,6 +107,8 @@ class CourseOfAction(STIXDomainObject): ('description', StringProperty()), ('revoked', BooleanProperty(default=lambda: False)), ('labels', ListProperty(StringProperty)), + ('confidence', IntegerProperty()), + ('lang', StringProperty()), ('external_references', ListProperty(ExternalReference)), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('granular_markings', ListProperty(GranularMarking)),