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

Commit

Permalink
Merge pull request #119 from jjnicola/results-dict
Browse files Browse the repository at this point in the history
Use ordered dictionary to maintain the results order
  • Loading branch information
jjnicola authored Jul 24, 2019
2 parents 1d2395a + df9fd73 commit fedb21c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
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'])

0 comments on commit fedb21c

Please sign in to comment.