Fixes #334
parent
8aca39a0b0
commit
1084c75d33
|
@ -388,11 +388,10 @@ class _Observable(_STIXBase):
|
||||||
temp_deep_copy = copy.deepcopy(dict(kwargs[key]))
|
temp_deep_copy = copy.deepcopy(dict(kwargs[key]))
|
||||||
_recursive_stix_to_dict(temp_deep_copy)
|
_recursive_stix_to_dict(temp_deep_copy)
|
||||||
streamlined_obj_vals.append(temp_deep_copy)
|
streamlined_obj_vals.append(temp_deep_copy)
|
||||||
elif isinstance(kwargs[key], list) and isinstance(kwargs[key][0], _STIXBase):
|
elif isinstance(kwargs[key], list):
|
||||||
for obj in kwargs[key]:
|
temp_deep_copy = copy.deepcopy(kwargs[key])
|
||||||
temp_deep_copy = copy.deepcopy(dict(obj))
|
_recursive_stix_list_to_dict(temp_deep_copy)
|
||||||
_recursive_stix_to_dict(temp_deep_copy)
|
streamlined_obj_vals.append(temp_deep_copy)
|
||||||
streamlined_obj_vals.append(temp_deep_copy)
|
|
||||||
else:
|
else:
|
||||||
streamlined_obj_vals.append(kwargs[key])
|
streamlined_obj_vals.append(kwargs[key])
|
||||||
|
|
||||||
|
@ -448,5 +447,20 @@ def _recursive_stix_to_dict(input_dict):
|
||||||
|
|
||||||
# There may stil be nested _STIXBase objects
|
# There may stil be nested _STIXBase objects
|
||||||
_recursive_stix_to_dict(input_dict[key])
|
_recursive_stix_to_dict(input_dict[key])
|
||||||
|
elif isinstance(input_dict[key], list):
|
||||||
|
_recursive_stix_list_to_dict(input_dict[key])
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def _recursive_stix_list_to_dict(input_list):
|
||||||
|
for i in range(len(input_list)):
|
||||||
|
if isinstance(input_list[i], _STIXBase):
|
||||||
|
input_list[i] = dict(input_list[i])
|
||||||
|
elif isinstance(input_list[i], dict):
|
||||||
|
pass
|
||||||
|
elif isinstance(input_list[i], list):
|
||||||
|
_recursive_stix_list_to_dict(input_list[i])
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
_recursive_stix_to_dict(input_list[i])
|
||||||
|
|
|
@ -1574,3 +1574,47 @@ def test_ipv6_belongs_to_refs_deprecation():
|
||||||
value="2001:0db8:85a3:0000:0000:8a2e:0370:7334",
|
value="2001:0db8:85a3:0000:0000:8a2e:0370:7334",
|
||||||
belongs_to_refs=["autonomous-system--52e0a49d-d683-5801-a7b8-145765a1e116"],
|
belongs_to_refs=["autonomous-system--52e0a49d-d683-5801-a7b8-145765a1e116"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_id_gen_recursive_dict_conversion_1():
|
||||||
|
file_observable = stix2.v21.File(
|
||||||
|
name="example.exe",
|
||||||
|
size=68 * 1000,
|
||||||
|
magic_number_hex="50000000",
|
||||||
|
hashes={
|
||||||
|
"SHA-256": "841a8921140aba50671ebb0770fecc4ee308c4952cfeff8de154ab14eeef4649",
|
||||||
|
},
|
||||||
|
extensions={
|
||||||
|
"windows-pebinary-ext": stix2.v21.WindowsPEBinaryExt(
|
||||||
|
pe_type="exe",
|
||||||
|
machine_hex="014c",
|
||||||
|
sections=[
|
||||||
|
stix2.v21.WindowsPESection(
|
||||||
|
name=".data",
|
||||||
|
size=4096,
|
||||||
|
entropy=7.980693,
|
||||||
|
hashes={"SHA-256": "6e3b6f3978e5cd96ba7abee35c24e867b7e64072e2ecb22d0ee7a6e6af6894d0"},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert file_observable.id == "file--5219d93d-13c1-5f1f-896b-039f10ec67ea"
|
||||||
|
|
||||||
|
|
||||||
|
def test_id_gen_recursive_dict_conversion_2():
|
||||||
|
wrko = stix2.v21.WindowsRegistryKey(
|
||||||
|
values=[
|
||||||
|
stix2.v21.WindowsRegistryValueType(
|
||||||
|
name="Foo",
|
||||||
|
data="qwerty",
|
||||||
|
),
|
||||||
|
stix2.v21.WindowsRegistryValueType(
|
||||||
|
name="Bar",
|
||||||
|
data="42",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
assert wrko.id == "windows-registry-key--c087d9fe-a03e-5922-a1cd-da116e5b8a7b"
|
||||||
|
|
Loading…
Reference in New Issue