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
							parent
							
								
									d2f960f2fc
								
							
						
					
					
						commit
						387ce7e7cb
					
				| 
						 | 
					@ -138,6 +138,11 @@ def test_reference_property_blacklist_type():
 | 
				
			||||||
            "identity--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True,
 | 
					            "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(
 | 
					@pytest.mark.parametrize(
 | 
				
			||||||
    "d", [
 | 
					    "d", [
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,7 @@ import pytest
 | 
				
			||||||
import pytz
 | 
					import pytz
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import stix2
 | 
					import stix2
 | 
				
			||||||
 | 
					from stix2.exceptions import InvalidValueError
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from .constants import (
 | 
					from .constants import (
 | 
				
			||||||
    CAMPAIGN_ID, IDENTITY_ID, INDICATOR_ID, INDICATOR_KWARGS, RELATIONSHIP_ID,
 | 
					    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"
 | 
					    assert rept.name == "The Black Vine Cyberespionage Group"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# TODO: Add other examples
 | 
					# 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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -159,6 +159,11 @@ def test_reference_property_blacklist_type():
 | 
				
			||||||
            "identity--8a8e8758-f92c-4058-ba38-f061cd42a0cf", True,
 | 
					            "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(
 | 
					@pytest.mark.parametrize(
 | 
				
			||||||
    "d", [
 | 
					    "d", [
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,6 +9,7 @@ from .constants import (
 | 
				
			||||||
    CAMPAIGN_ID, IDENTITY_ID, INDICATOR_ID, INDICATOR_KWARGS, RELATIONSHIP_ID,
 | 
					    CAMPAIGN_ID, IDENTITY_ID, INDICATOR_ID, INDICATOR_KWARGS, RELATIONSHIP_ID,
 | 
				
			||||||
    REPORT_ID,
 | 
					    REPORT_ID,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					from stix2.exceptions import InvalidValueError
 | 
				
			||||||
 | 
					
 | 
				
			||||||
EXPECTED = """{
 | 
					EXPECTED = """{
 | 
				
			||||||
    "type": "report",
 | 
					    "type": "report",
 | 
				
			||||||
| 
						 | 
					@ -135,4 +136,27 @@ def test_parse_report(data):
 | 
				
			||||||
    assert rept.report_types == ["campaign"]
 | 
					    assert rept.report_types == ["campaign"]
 | 
				
			||||||
    assert rept.name == "The Black Vine Cyberespionage Group"
 | 
					    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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -235,7 +235,7 @@ class Report(_DomainObject):
 | 
				
			||||||
        ('name', StringProperty(required=True)),
 | 
					        ('name', StringProperty(required=True)),
 | 
				
			||||||
        ('description', StringProperty()),
 | 
					        ('description', StringProperty()),
 | 
				
			||||||
        ('published', TimestampProperty(required=True)),
 | 
					        ('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)),
 | 
					        ('revoked', BooleanProperty(default=lambda: False)),
 | 
				
			||||||
        ('labels', ListProperty(StringProperty, required=True)),
 | 
					        ('labels', ListProperty(StringProperty, required=True)),
 | 
				
			||||||
        ('external_references', ListProperty(ExternalReference)),
 | 
					        ('external_references', ListProperty(ExternalReference)),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -646,7 +646,7 @@ class Report(_DomainObject):
 | 
				
			||||||
        ('description', StringProperty()),
 | 
					        ('description', StringProperty()),
 | 
				
			||||||
        ('report_types', ListProperty(StringProperty)),
 | 
					        ('report_types', ListProperty(StringProperty)),
 | 
				
			||||||
        ('published', TimestampProperty(required=True)),
 | 
					        ('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)),
 | 
					        ('revoked', BooleanProperty(default=lambda: False)),
 | 
				
			||||||
        ('labels', ListProperty(StringProperty)),
 | 
					        ('labels', ListProperty(StringProperty)),
 | 
				
			||||||
        ('confidence', IntegerProperty()),
 | 
					        ('confidence', IntegerProperty()),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue