From fab6c2c09086940e3214da4442aaa33f312fde43 Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Fri, 23 Nov 2018 04:59:43 -0500 Subject: [PATCH 1/3] Add methods to set and get the vts feed version. --- ospd/ospd.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ospd/ospd.py b/ospd/ospd.py index 11ceac9d..42281ab7 100644 --- a/ospd/ospd.py +++ b/ospd/ospd.py @@ -275,6 +275,7 @@ def __init__(self, certfile, keyfile, cafile): self.add_scanner_param(name, param) self.vts = dict() self.vt_id_pattern = re.compile("[0-9a-zA-Z_\-:.]{1,80}") + self.vts_version = None def set_command_attributes(self, name, attributes): """ Sets the xml attributes of a specified command. """ @@ -354,6 +355,23 @@ def add_vt(self, vt_id, name=None, vt_params=None, vt_refs=None, return len(self.vts) + def set_vts_version(self, vts_version): + """ Add into the vts dictionary an entry to identify the + vts version. + + Parameters: + vts_version (str): Identifies a unique vts version. + """ + if not vts_version: + raise OSPDError('A vts_version parameter is required', + 'set_vts_version') + self.vts_version = vts_version + + def get_vts_version(self): + """Return the vts version. + """ + return self.vts_version + def command_exists(self, name): """ Checks if a commands exists. """ return name in self.commands.keys() From 9881c013c0e10c41e46280d2e392a27115fe613a Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Fri, 23 Nov 2018 05:00:16 -0500 Subject: [PATCH 2/3] Add unit test --- tests/testScanAndResult.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/testScanAndResult.py b/tests/testScanAndResult.py index 9600e6f6..7f088858 100644 --- a/tests/testScanAndResult.py +++ b/tests/testScanAndResult.py @@ -650,3 +650,13 @@ def testProgress(self): daemon.set_scan_target_progress(scan_id, 'localhost1', 75) daemon.set_scan_target_progress(scan_id, 'localhost2', 25) self.assertEqual(daemon.calculate_progress(scan_id), 50) + + def testSetGetVtsVersion(self): + daemon = DummyWrapper([]) + daemon.set_vts_version('1234') + version = daemon.get_vts_version() + self.assertEqual('1234', version) + + def testSetGetVtsVersion_Error(self): + daemon = DummyWrapper([]) + self.assertRaises(TypeError, daemon.set_vts_version) From 147f430a7897b678199f74c8b702e864f9c766e2 Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Fri, 23 Nov 2018 09:14:58 -0500 Subject: [PATCH 3/3] Add vts version element to . --- ospd/ospd.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ospd/ospd.py b/ospd/ospd.py index 42281ab7..480d0182 100644 --- a/ospd/ospd.py +++ b/ospd/ospd.py @@ -1482,7 +1482,15 @@ def handle_get_version_command(self): elem = SubElement(scanner, name) elem.text = value - return simple_response_str('get_version', 200, 'OK', [protocol, daemon, scanner]) + content = [protocol, daemon, scanner] + + if self.get_vts_version(): + vts = Element('vts') + elem = SubElement(vts, 'version') + elem.text = self.get_vts_version() + content.append(vts) + + return simple_response_str('get_version', 200, 'OK', content) def handle_command(self, command): """ Handles an osp command in a string.