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

Use empty string instead of None for credentials value #335

Merged
merged 1 commit into from
Oct 23, 2020
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion ospd/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 28 additions & 0 deletions tests/test_scan_and_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<start_scan>'
'<scanner_params /><vts><vt id="1.2.3.4" />'
'</vts>'
'<targets><target>'
'<hosts>192.168.0.0/24</hosts><ports>22'
'</ports><credentials>'
'<credential type="up" service="snmp">'
'<community></community></credential>'
'</credentials>'
'</target></targets>'
'</start_scan>',
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(
Expand Down