From c235b6b206ba400bdd3b33efe29ceb06b9965774 Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Tue, 26 Nov 2019 14:25:38 +0100 Subject: [PATCH] Modify __init__() method and use new syntax for super(). --- CHANGELOG.md | 3 +++ ospd/ospd_ssh.py | 9 +++------ tests/test_ssh_daemon.py | 16 +++++++++++----- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01334629..36f28f63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added - Add solution method to solution of vt object. [#166](https://github.com/greenbone/ospd/pull/166) +### Changes +- Modify __init__() method and use new syntax for super(). [#186](https://github.com/greenbone/ospd/pull/186) + ## [2.0.1] (unreleased) ### Added diff --git a/ospd/ospd_ssh.py b/ospd/ospd_ssh.py index f74680f3..2f13fc05 100644 --- a/ospd/ospd_ssh.py +++ b/ospd/ospd_ssh.py @@ -78,15 +78,12 @@ class OSPDaemonSimpleSSH(OSPDaemon): an array. """ - def __init__(self, certfile, keyfile, cafile, niceness=None): + def __init__(self, **kwargs): """ Initializes the daemon and add parameters needed to remote SSH execution. """ + super().__init__(**kwargs) - super(OSPDaemonSimpleSSH, self).__init__( - certfile=certfile, keyfile=keyfile, cafile=cafile, niceness=niceness - ) - - self._niceness = niceness + self._niceness = kwargs.get('niceness', None) if paramiko is None: raise ImportError( diff --git a/tests/test_ssh_daemon.py b/tests/test_ssh_daemon.py index 4501518a..47d8dbd2 100644 --- a/tests/test_ssh_daemon.py +++ b/tests/test_ssh_daemon.py @@ -71,16 +71,22 @@ def AutoAddPolicy(): # pylint: disable=invalid-name ssh_exception = FakeExceptions +class DummyWrapper(OSPDaemonSimpleSSH): + def __init__(self, niceness=10): + super().__init__(niceness=niceness) + + class SSHDaemonTestCase(unittest.TestCase): def test_no_paramiko(self): ospd_ssh.paramiko = None with self.assertRaises(ImportError): - OSPDaemonSimpleSSH('cert', 'key', 'ca', '10') + OSPDaemonSimpleSSH() def test_run_command(self): ospd_ssh.paramiko = fakeparamiko - daemon = OSPDaemonSimpleSSH('cert', 'key', 'ca', '10') + + daemon = DummyWrapper(niceness=10) scanid = daemon.create_scan( None, [['host.example.com', '80, 443', '', '', '']], @@ -96,7 +102,7 @@ def test_run_command(self): def test_run_command_legacy_credential(self): ospd_ssh.paramiko = fakeparamiko - daemon = OSPDaemonSimpleSSH('cert', 'key', 'ca', '10') + daemon = DummyWrapper(niceness=10) scanid = daemon.create_scan( None, [['host.example.com', '80, 443', '', '', '']], @@ -112,7 +118,7 @@ def test_run_command_legacy_credential(self): def test_run_command_new_credential(self): ospd_ssh.paramiko = fakeparamiko - daemon = OSPDaemonSimpleSSH('cert', 'key', 'ca', '10') + daemon = DummyWrapper(niceness=10) cred_dict = { 'ssh': { @@ -138,7 +144,7 @@ def test_run_command_new_credential(self): def test_run_command_no_credential(self): ospd_ssh.paramiko = fakeparamiko - daemon = OSPDaemonSimpleSSH('cert', 'key', 'ca', '10') + daemon = DummyWrapper(niceness=10) scanid = daemon.create_scan( None, [['host.example.com', '80, 443', '', '', '']],