Parse dictionaries as well as strings and file-like objects
parent
dd382520d6
commit
168105603b
|
@ -15,6 +15,9 @@ from .sro import Relationship
|
||||||
def parse(data):
|
def parse(data):
|
||||||
"""Deserialize a string or file-like object into a STIX object"""
|
"""Deserialize a string or file-like object into a STIX object"""
|
||||||
|
|
||||||
|
if type(data) is dict:
|
||||||
|
obj = data
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
obj = json.loads(data)
|
obj = json.loads(data)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
|
|
|
@ -91,8 +91,19 @@ def test_invalid_kwarg_to_malware():
|
||||||
assert str(excinfo.value) == "unexpected keyword arguments: ['my_custom_property']"
|
assert str(excinfo.value) == "unexpected keyword arguments: ['my_custom_property']"
|
||||||
|
|
||||||
|
|
||||||
def test_parse_malware():
|
@pytest.mark.parametrize("data", [
|
||||||
mal = stix2.parse(EXPECTED_MALWARE)
|
EXPECTED_MALWARE,
|
||||||
|
{
|
||||||
|
"type": "malware",
|
||||||
|
"id": "malware--fedcba98-7654-3210-fedc-ba9876543210",
|
||||||
|
"created": "2016-05-12T08:17:27Z",
|
||||||
|
"modified": "2016-05-12T08:17:27Z",
|
||||||
|
"labels": ["ransomware"],
|
||||||
|
"name": "Cryptolocker",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
def test_parse_malware(data):
|
||||||
|
mal = stix2.parse(data)
|
||||||
|
|
||||||
assert mal.type == 'malware'
|
assert mal.type == 'malware'
|
||||||
assert mal.id == MALWARE_ID
|
assert mal.id == MALWARE_ID
|
||||||
|
|
Loading…
Reference in New Issue