Add functionality to _valid_refs to accept actual cyber observable objects instead of just strings with their types

master
Desai, Kartikey H 2019-05-10 10:22:45 -04:00
parent ddd4fa3e95
commit f79b3c9876
2 changed files with 22 additions and 1 deletions

View File

@ -308,7 +308,10 @@ class _Observable(_STIXBase):
allowed_types = prop.valid_types
try:
ref_type = self._STIXBase__valid_refs[ref]
try:
ref_type = self._STIXBase__valid_refs[ref].type
except AttributeError:
ref_type = self._STIXBase__valid_refs[ref]
except TypeError:
raise ValueError("'%s' must be created with _valid_refs as a dict, not a list." % self.__class__.__name__)

View File

@ -940,6 +940,24 @@ def test_ip4_address_example():
assert ip4.resolves_to_refs == ["4", "5"]
def test_ip4_address_valid_refs():
mac1 = stix2.v21.MACAddress(
value="a1:b2:c3:d4:e5:f6",
)
mac2 = stix2.v21.MACAddress(
value="a7:b8:c9:d0:e1:f2",
)
ip4 = stix2.v21.IPv4Address(
_valid_refs={"1": mac1, "2": mac2},
value="177.60.40.7",
resolves_to_refs=["1", "2"],
)
assert ip4.value == "177.60.40.7"
assert ip4.resolves_to_refs == ["1", "2"]
def test_ip4_address_example_cidr():
ip4 = stix2.v21.IPv4Address(value="198.51.100.0/24")