Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Use ordered dictionary to maintain the results order #119

Merged
merged 2 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ospd/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import multiprocessing

from enum import Enum
from collections import OrderedDict

from ospd.network import target_str_to_list

Expand Down Expand Up @@ -84,7 +85,7 @@ def add_result(

assert scan_id
assert len(name) or len(value)
result = dict()
result = OrderedDict()
result['type'] = result_type
result['name'] = name
result['severity'] = severity
Expand Down
30 changes: 30 additions & 0 deletions tests/test_scan_and_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,3 +1095,33 @@ def test_resume_task(self):
)
result = response.findall('scan/results/result')
self.assertEqual(len(result), 2)

def test_result_order (self):
daemon = DummyWrapper([])
response = secET.fromstring(
daemon.handle_command(
'<start_scan parallel="1">'
'<scanner_params />'
'<targets><target>'
'<hosts>a</hosts>'
'<ports>22</ports>'
'</target></targets>'
'</start_scan>'
)
)

scan_id = response.findtext('id')

daemon.add_scan_log(scan_id, host='a', name='a')
daemon.add_scan_log(scan_id, host='c', name='c')
daemon.add_scan_log(scan_id, host='b', name='b')
hosts = ['a','c','b']
response = secET.fromstring(
daemon.handle_command('<get_scans details="1"/>'
)
)
results = response.findall("scan/results/")

for idx, res in enumerate(results):
att_dict = res.attrib
self.assertEqual(hosts[idx], att_dict['name'])