Add Autonomous System
parent
2c67b90638
commit
1a75d830bb
|
@ -3,7 +3,7 @@
|
||||||
# flake8: noqa
|
# flake8: noqa
|
||||||
|
|
||||||
from .bundle import Bundle
|
from .bundle import Bundle
|
||||||
from .observables import Artifact, File
|
from .observables import Artifact, AutonomousSystem, File
|
||||||
from .other import ExternalReference, KillChainPhase, MarkingDefinition, \
|
from .other import ExternalReference, KillChainPhase, MarkingDefinition, \
|
||||||
GranularMarking, StatementMarking, TLPMarking
|
GranularMarking, StatementMarking, TLPMarking
|
||||||
from .sdo import AttackPattern, Campaign, CourseOfAction, Identity, Indicator, \
|
from .sdo import AttackPattern, Campaign, CourseOfAction, Identity, Indicator, \
|
||||||
|
@ -34,6 +34,7 @@ OBJ_MAP = {
|
||||||
|
|
||||||
OBJ_MAP_OBSERVABLE = {
|
OBJ_MAP_OBSERVABLE = {
|
||||||
'artifact': Artifact,
|
'artifact': Artifact,
|
||||||
|
'autonomous-system': AutonomousSystem,
|
||||||
'file': File,
|
'file': File,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ from .base import Observable
|
||||||
# HashesProperty, HexProperty, IDProperty,
|
# HashesProperty, HexProperty, IDProperty,
|
||||||
# IntegerProperty, ListProperty, ReferenceProperty,
|
# IntegerProperty, ListProperty, ReferenceProperty,
|
||||||
# StringProperty, TimestampProperty, TypeProperty)
|
# StringProperty, TimestampProperty, TypeProperty)
|
||||||
from .properties import BinaryProperty, HashesProperty, StringProperty, TypeProperty
|
from .properties import BinaryProperty, HashesProperty, IntegerProperty, StringProperty, TypeProperty
|
||||||
|
|
||||||
|
|
||||||
class Artifact(Observable):
|
class Artifact(Observable):
|
||||||
|
@ -19,6 +19,16 @@ class Artifact(Observable):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class AutonomousSystem(Observable):
|
||||||
|
_type = 'autonomous-system'
|
||||||
|
_properties = {
|
||||||
|
'type': TypeProperty(_type),
|
||||||
|
'number': IntegerProperty(),
|
||||||
|
'name': StringProperty(),
|
||||||
|
'rir': StringProperty(),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class File(Observable):
|
class File(Observable):
|
||||||
_type = 'file'
|
_type = 'file'
|
||||||
_properties = {
|
_properties = {
|
||||||
|
|
|
@ -335,3 +335,14 @@ class SelectorProperty(Property):
|
||||||
if not SELECTOR_REGEX.match(value):
|
if not SELECTOR_REGEX.match(value):
|
||||||
raise ValueError("must adhere to selector syntax.")
|
raise ValueError("must adhere to selector syntax.")
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
class ObjectReferenceProperty(Property):
|
||||||
|
def _init(self, valid_refs=None):
|
||||||
|
self.valid_refs = valid_refs
|
||||||
|
super(ObjectReferenceProperty, self).__init__()
|
||||||
|
|
||||||
|
def clean(self, value):
|
||||||
|
if value not in self.valid_refs:
|
||||||
|
raise ValueError("must refer to observable objects in the same "
|
||||||
|
"Observable Objects container.")
|
||||||
|
|
|
@ -115,4 +115,22 @@ def test_parse_artifact_invalid(data):
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
stix2.parse(odata_str)
|
stix2.parse(odata_str)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("data", [
|
||||||
|
""""0": {
|
||||||
|
"type": "autonomous-system",
|
||||||
|
"number": 15139,
|
||||||
|
"name": "Slime Industries",
|
||||||
|
"rir": "ARIN"
|
||||||
|
}""",
|
||||||
|
])
|
||||||
|
def test_parse_autonomous_system_valid(data):
|
||||||
|
odata_str = re.compile('"objects".+\},', re.DOTALL).sub('"objects": { %s },' % data, EXPECTED)
|
||||||
|
odata = stix2.parse(odata_str)
|
||||||
|
assert odata.objects["0"].type == "autonomous-system"
|
||||||
|
assert odata.objects["0"].number == 15139
|
||||||
|
assert odata.objects["0"].name == "Slime Industries"
|
||||||
|
assert odata.objects["0"].rir == "ARIN"
|
||||||
|
|
||||||
|
|
||||||
# TODO: Add other examples
|
# TODO: Add other examples
|
||||||
|
|
Loading…
Reference in New Issue