From bb9e43cb9608326e75d2f0e52b879484a310b49c Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Thu, 22 Oct 2020 16:42:05 +0200 Subject: [PATCH] Use empty string instead of None for credentials value --- CHANGELOG.md | 2 ++ ospd/protocol.py | 4 +++- tests/test_scan_and_result.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d137da7..9b96be82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed - Fix OSP version. [#326](https://github.com/greenbone/ospd/pull/326) +- Use empty string instead of None for credential. [#335](https://github.com/greenbone/ospd/pull/335) + [20.8.2]: https://github.com/greenbone/ospd/compare/v20.8.1...ospd-20.08 diff --git a/ospd/protocol.py b/ospd/protocol.py index 4fcd21cb..8591ee3a 100644 --- a/ospd/protocol.py +++ b/ospd/protocol.py @@ -142,7 +142,9 @@ def process_credentials_elements(cred_tree: Element) -> Dict: credentials[service]['port'] = credential.attrib.get('port') for param in credential: - credentials[service][param.tag] = param.text + credentials[service][param.tag] = ( + param.text if param.text else "" + ) return credentials diff --git a/tests/test_scan_and_result.py b/tests/test_scan_and_result.py index f53e6c01..79d5aa78 100644 --- a/tests/test_scan_and_result.py +++ b/tests/test_scan_and_result.py @@ -849,6 +849,34 @@ def test_target_with_credentials(self): response = self.daemon.get_scan_credentials(scan_id) self.assertEqual(response, cred_dict) + def test_target_with_credential_empty_community(self): + fs = FakeStream() + self.daemon.handle_command( + '' + '' + '' + '' + '192.168.0.0/2422' + '' + '' + '' + '' + '' + '', + fs, + ) + self.daemon.start_queued_scans() + response = fs.get_response() + + self.assertEqual(response.get('status'), '200') + + cred_dict = { + 'snmp': {'type': 'up', 'community': ''}, + } + scan_id = response.findtext('id') + response = self.daemon.get_scan_credentials(scan_id) + self.assertEqual(response, cred_dict) + def test_scan_get_target(self): fs = FakeStream() self.daemon.handle_command(