Fix Report SDO: I'd fixed ReferenceProperty to work the way I

thought it should, but forgot to fix Report to use
ReferenceProperty in the way I thought it should!  Oops.
Added some tests to ensure Report is working property with
custom ID types in object_refs.
pull/1/head
Michael Chisholm 2020-06-19 11:40:36 -04:00
parent d2f960f2fc
commit 387ce7e7cb
6 changed files with 65 additions and 3 deletions

View File

@ -138,6 +138,11 @@ def test_reference_property_blacklist_type():
"identity--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True,
)
with pytest.raises(CustomContentError):
ref_prop.clean(
"some-type--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False,
)
@pytest.mark.parametrize(
"d", [

View File

@ -4,6 +4,7 @@ import pytest
import pytz
import stix2
from stix2.exceptions import InvalidValueError
from .constants import (
CAMPAIGN_ID, IDENTITY_ID, INDICATOR_ID, INDICATOR_KWARGS, RELATIONSHIP_ID,
@ -133,3 +134,30 @@ def test_parse_report(data):
assert rept.name == "The Black Vine Cyberespionage Group"
# TODO: Add other examples
def test_report_on_custom():
with pytest.raises(InvalidValueError):
stix2.v20.Report(
name="my report",
labels=["a label"],
published="2016-01-20T17:00:00Z",
object_refs=[
"indicator--a740531e-63ff-4e49-a9e1-a0a3eed0e3e7",
"some-type--2672975a-ce1e-4473-a1c6-0d79868930c7"
]
)
report = stix2.v20.Report(
name="my report",
labels=["a label"],
published="2016-01-20T17:00:00Z",
object_refs=[
"indicator--a740531e-63ff-4e49-a9e1-a0a3eed0e3e7",
"some-type--2672975a-ce1e-4473-a1c6-0d79868930c7"
],
allow_custom=True,
)
assert "some-type--2672975a-ce1e-4473-a1c6-0d79868930c7" \
in report.object_refs

View File

@ -159,6 +159,11 @@ def test_reference_property_blacklist_type():
"identity--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True,
)
with pytest.raises(CustomContentError):
ref_prop.clean(
"some-type--8a8e8758-f92c-4058-ba38-f061cd42a0cf", False,
)
@pytest.mark.parametrize(
"d", [

View File

@ -9,6 +9,7 @@ from .constants import (
CAMPAIGN_ID, IDENTITY_ID, INDICATOR_ID, INDICATOR_KWARGS, RELATIONSHIP_ID,
REPORT_ID,
)
from stix2.exceptions import InvalidValueError
EXPECTED = """{
"type": "report",
@ -135,4 +136,27 @@ def test_parse_report(data):
assert rept.report_types == ["campaign"]
assert rept.name == "The Black Vine Cyberespionage Group"
# TODO: Add other examples
def test_report_on_custom():
with pytest.raises(InvalidValueError):
stix2.v21.Report(
name="my report",
published="2016-01-20T17:00:00Z",
object_refs=[
"indicator--a740531e-63ff-4e49-a9e1-a0a3eed0e3e7",
"some-type--2672975a-ce1e-4473-a1c6-0d79868930c7"
]
)
report = stix2.v21.Report(
name="my report",
published="2016-01-20T17:00:00Z",
object_refs=[
"indicator--a740531e-63ff-4e49-a9e1-a0a3eed0e3e7",
"some-type--2672975a-ce1e-4473-a1c6-0d79868930c7"
],
allow_custom=True,
)
assert "some-type--2672975a-ce1e-4473-a1c6-0d79868930c7" \
in report.object_refs

View File

@ -235,7 +235,7 @@ class Report(_DomainObject):
('name', StringProperty(required=True)),
('description', StringProperty()),
('published', TimestampProperty(required=True)),
('object_refs', ListProperty(ReferenceProperty(valid_types=["SCO", "SDO", "SRO"], spec_version='2.0'), required=True)),
('object_refs', ListProperty(ReferenceProperty(invalid_types=[], spec_version='2.0'), required=True)),
('revoked', BooleanProperty(default=lambda: False)),
('labels', ListProperty(StringProperty, required=True)),
('external_references', ListProperty(ExternalReference)),

View File

@ -646,7 +646,7 @@ class Report(_DomainObject):
('description', StringProperty()),
('report_types', ListProperty(StringProperty)),
('published', TimestampProperty(required=True)),
('object_refs', ListProperty(ReferenceProperty(valid_types=["SCO", "SDO", "SRO"], spec_version='2.1'), required=True)),
('object_refs', ListProperty(ReferenceProperty(invalid_types=[], spec_version='2.1'), required=True)),
('revoked', BooleanProperty(default=lambda: False)),
('labels', ListProperty(StringProperty)),
('confidence', IntegerProperty()),