From e954375c90e45c4ef457756c3b8a2ca4d14c97d1 Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Fri, 19 Jul 2019 10:04:41 +0200 Subject: [PATCH 1/2] Use ordered dictionary to maintain the results order --- ospd/misc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ospd/misc.py b/ospd/misc.py index 275207c8..10f501d3 100644 --- a/ospd/misc.py +++ b/ospd/misc.py @@ -29,6 +29,7 @@ import multiprocessing from enum import Enum +from collections import OrderedDict from ospd.network import target_str_to_list @@ -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 From df9fd73655e705c5b87ae0fc4808058c16751419 Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Wed, 24 Jul 2019 10:03:49 +0200 Subject: [PATCH 2/2] Add test to check preservation of result's order. --- tests/test_scan_and_result.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_scan_and_result.py b/tests/test_scan_and_result.py index a6fbc78f..631d0dc9 100644 --- a/tests/test_scan_and_result.py +++ b/tests/test_scan_and_result.py @@ -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( + '' + '' + '' + 'a' + '22' + '' + '' + ) + ) + + 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('' + ) + ) + results = response.findall("scan/results/") + + for idx, res in enumerate(results): + att_dict = res.attrib + self.assertEqual(hosts[idx], att_dict['name'])