Skip to content

Commit 39657a0

Browse files
committed
fix: add tests for previous 2 commits, fix resulting bugs
1 parent 3a6542b commit 39657a0

3 files changed

Lines changed: 37 additions & 6 deletions

File tree

mitreattack/stix20/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .custom_attack_objects import Asset, DataComponent, DataSource, Matrix, StixObjectFactory, Tactic
1+
from .custom_attack_objects import Asset, DataComponent, DataSource, Matrix, StixObjectFactory, Tactic, Analytic, DetectionStrategy
22
from .MitreAttackData import MitreAttackData
33

44
__all__ = [
@@ -9,4 +9,6 @@
99
"StixObjectFactory",
1010
"Tactic",
1111
"MitreAttackData",
12+
"Analytic",
13+
"DetectionStrategy",
1214
]

mitreattack/stix20/custom_attack_objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ class Analytic(CustomStixObject, object):
339339
("x_mitre_contributors", ListProperty(StringProperty())),
340340
("x-mitre-deprecated", BooleanProperty(default=lambda: False)),
341341
# Detection Strategy Properties
342-
("x_mitre_analytic_refs", ListProperty(StringProperty())),
342+
("x_mitre_analytic_refs", ListProperty(ReferenceProperty(valid_types="x-mitre-analytic", spec_version="2.0"))),
343343
],
344344
)
345345
class DetectionStrategy(CustomStixObject, object):

tests/test_stix20.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,33 @@
22
Tests for custom STIX 2.0 attack objects in the mitreattack.stix20 module.
33
44
This module verifies the correct behavior and properties of custom ATT&CK objects
5-
such as DataComponent, DataSource, Matrix, Tactic, Asset, and the StixObjectFactory.
5+
including DataComponent, DataSource, Matrix, Tactic, Asset, Analytic,
6+
DetectionStrategy, and the StixObjectFactory.
67
"""
78

89
import pytest
910
import stix2
1011
import stix2.exceptions
1112

12-
from mitreattack.stix20.custom_attack_objects import Asset, DataComponent, DataSource, Matrix, StixObjectFactory, Tactic
13+
from mitreattack.stix20.custom_attack_objects import (
14+
Analytic,
15+
Asset,
16+
DataComponent,
17+
DataSource,
18+
DetectionStrategy,
19+
Matrix,
20+
StixObjectFactory,
21+
Tactic,
22+
)
1323

1424

1525
class TestCustomAttackObjects:
1626
"""
1727
Test suite for custom ATT&CK STIX 2.0 objects and their factory.
1828
19-
This class contains tests for the creation and properties of custom ATT&CK objects,
20-
including DataComponent, DataSource, Matrix, Tactic, Asset, and the StixObjectFactory.
29+
This class contains tests for the creation and properties of custom ATT&CK objects
30+
including DataComponent, DataSource, Matrix, Tactic, Asset, Analytic,
31+
DetectionStrategy, and the StixObjectFactory.
2132
"""
2233

2334
def test_data_component(self):
@@ -52,6 +63,8 @@ def test_stix_object_factory(self):
5263
"x-mitre-matrix": Matrix,
5364
"x-mitre-tactic": Tactic,
5465
"x-mitre-asset": Asset,
66+
"x-mitre-analytic": Analytic,
67+
"x-mitre-detection-strategy": DetectionStrategy,
5568
}
5669

5770
object_name = "Object name"
@@ -88,3 +101,19 @@ def test_asset(self):
88101

89102
assert asset.name == name
90103
assert asset.type == "x-mitre-asset"
104+
105+
def test_analytic(self):
106+
"""Test Analytic creation and properties."""
107+
name = "Analytic"
108+
analytic = Analytic(name=name)
109+
110+
assert analytic.name == name
111+
assert analytic.type == "x-mitre-analytic"
112+
113+
def test_detection_strategy(self):
114+
"""Test Detection Strategy creation and properties."""
115+
name = "Detection Strategy"
116+
detection_strategy = DetectionStrategy(name=name)
117+
118+
assert detection_strategy.name == name
119+
assert detection_strategy.type == "x-mitre-detection-strategy"

0 commit comments

Comments
 (0)