GH-188: Test that references are always valid UUID v4.
parent
e5903f1832
commit
e749218f9b
|
@ -309,7 +309,7 @@ class HexProperty(Property):
|
||||||
|
|
||||||
|
|
||||||
REF_REGEX = re.compile("^[a-z][a-z-]+[a-z]--[0-9a-fA-F]{8}-[0-9a-fA-F]{4}"
|
REF_REGEX = re.compile("^[a-z][a-z-]+[a-z]--[0-9a-fA-F]{8}-[0-9a-fA-F]{4}"
|
||||||
"-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")
|
"-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$")
|
||||||
|
|
||||||
|
|
||||||
class ReferenceProperty(Property):
|
class ReferenceProperty(Property):
|
||||||
|
|
|
@ -97,7 +97,7 @@ filters = [
|
||||||
Filter("granular_markings.marking_ref", "=", "marking-definition--5e57c739-391a-4eb3-b6be-7d15ca92d5ed"),
|
Filter("granular_markings.marking_ref", "=", "marking-definition--5e57c739-391a-4eb3-b6be-7d15ca92d5ed"),
|
||||||
Filter("external_references.external_id", "in", "CVE-2014-0160,CVE-2017-6608"),
|
Filter("external_references.external_id", "in", "CVE-2014-0160,CVE-2017-6608"),
|
||||||
Filter("created_by_ref", "=", "identity--f1350682-3290-4e0d-be58-69e290537647"),
|
Filter("created_by_ref", "=", "identity--f1350682-3290-4e0d-be58-69e290537647"),
|
||||||
Filter("object_marking_refs", "=", "marking-definition--613f2e26-0000-0000-0000-b8e91df99dc9"),
|
Filter("object_marking_refs", "=", "marking-definition--613f2e26-0000-4000-8000-b8e91df99dc9"),
|
||||||
Filter("granular_markings.selectors", "in", "description"),
|
Filter("granular_markings.selectors", "in", "description"),
|
||||||
Filter("external_references.source_name", "=", "CVE"),
|
Filter("external_references.source_name", "=", "CVE"),
|
||||||
Filter("objects", "=", {"0": {"type": "file", "name": "HAL 9000.exe"}})
|
Filter("objects", "=", {"0": {"type": "file", "name": "HAL 9000.exe"}})
|
||||||
|
@ -262,7 +262,7 @@ def test_apply_common_filters9():
|
||||||
|
|
||||||
|
|
||||||
def test_apply_common_filters10():
|
def test_apply_common_filters10():
|
||||||
# "Return any object that matches marking-definition--613f2e26-0000-0000-0000-b8e91df99dc9 in object_marking_refs" (None)
|
# "Return any object that matches marking-definition--613f2e26-0000-4000-8000-b8e91df99dc9 in object_marking_refs" (None)
|
||||||
resp = list(apply_common_filters(stix_objs, [filters[11]]))
|
resp = list(apply_common_filters(stix_objs, [filters[11]]))
|
||||||
assert len(resp) == 0
|
assert len(resp) == 0
|
||||||
|
|
||||||
|
|
|
@ -155,7 +155,7 @@ def test_memory_source_get(mem_source):
|
||||||
|
|
||||||
|
|
||||||
def test_memory_source_get_nonexistant_object(mem_source):
|
def test_memory_source_get_nonexistant_object(mem_source):
|
||||||
resp = mem_source.get("tool--d81f86b8-975b-bc0b-775e-810c5ad45a4f")
|
resp = mem_source.get("tool--8d0b222c-7a3b-44a0-b9c6-31b051efb32e")
|
||||||
assert resp is None
|
assert resp is None
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -245,10 +245,14 @@ def test_boolean_property_invalid(value):
|
||||||
def test_reference_property():
|
def test_reference_property():
|
||||||
ref_prop = ReferenceProperty()
|
ref_prop = ReferenceProperty()
|
||||||
|
|
||||||
assert ref_prop.clean("my-type--3a331bfe-0566-55e1-a4a0-9a2cd355a300")
|
assert ref_prop.clean("my-type--00000000-0000-4000-8000-000000000000")
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
ref_prop.clean("foo")
|
ref_prop.clean("foo")
|
||||||
|
|
||||||
|
# This is not a valid V4 UUID
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
ref_prop.clean("my-type--00000000-0000-0000-0000-000000000000")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("value", [
|
@pytest.mark.parametrize("value", [
|
||||||
'2017-01-01T12:34:56Z',
|
'2017-01-01T12:34:56Z',
|
||||||
|
|
Loading…
Reference in New Issue