Example #1
0
class OSPGetVersionTestCase(unittest.TestCase):
    def setUp(self):
        self.connection = MockConnection()
        self.osp = Osp(self.connection)

    def test_get_version(self):
        self.osp.get_version()

        self.connection.send.has_been_called_with('<get_version/>')
Example #2
0
class OSPGetScannerDetailsTestCase(unittest.TestCase):
    def setUp(self):
        self.connection = MockConnection()
        self.osp = Osp(self.connection)

    def test_get_scanner_details_with_params(self):
        self.osp.get_scanner_details()

        self.connection.send.has_been_called_with('<get_scanner_details/>')
Example #3
0
class OSPHelpTestCase(unittest.TestCase):
    def setUp(self):
        self.connection = MockConnection()
        self.osp = Osp(self.connection)

    def test_help(self):
        self.osp.help()

        self.connection.send.has_been_called_with('<help/>')
Example #4
0
class OSPDeleteScanTestCase(unittest.TestCase):
    def setUp(self):
        self.connection = MockConnection()
        self.osp = Osp(self.connection)

    def test_delete_scan(self):
        self.osp.delete_scan(scan_id="123-456")

        self.connection.send.has_been_called_with(
            '<delete_scan scan_id="123-456"/>')

    def test_delete_scan_without_id(self):
        with self.assertRaises(ValueError):
            self.osp.delete_scan()
Example #5
0
class OSPGetVtsTestCase(unittest.TestCase):
    def setUp(self):
        self.connection = MockConnection()
        self.osp = Osp(self.connection)

    def test_get_vts_with_vt(self):
        self.osp.get_vts(vt_id="1.1.1.1.1.1")

        self.connection.send.has_been_called_with(
            '<get_vts vt_id="1.1.1.1.1.1"/>')

    def test_get_vts(self):
        self.osp.get_vts()

        self.connection.send.has_been_called_with("<get_vts/>")
Example #6
0
class OSPGetScanTestCase(unittest.TestCase):
    def setUp(self):
        self.connection = MockConnection()
        self.osp = Osp(self.connection)

    def test_get_scans_with_params(self):
        self.osp.get_scans(scan_id='123-456', details=False, pop_results=False)

        self.connection.send.has_been_called_with(
            '<get_scans scan_id="123-456" details="0" pop_results="0"/>')

    def test_get_scans_default_params(self):
        self.osp.get_scans()

        self.connection.send.has_been_called_with(
            '<get_scans details="1" pop_results="0"/>')
class OSPStopScanTestCase(unittest.TestCase):
    def setUp(self):
        self.connection = MockConnection()
        self.osp = Osp(self.connection)

    def test_stop_scan(self):
        self.osp.stop_scan(scan_id="123-456")

        self.connection.send.has_been_called_with(
            '<stop_scan scan_id="123-456"/>')

    def test_stop_scan_without_id(self):
        with self.assertRaises(RequiredArgument):
            self.osp.stop_scan(None)

        with self.assertRaises(RequiredArgument):
            self.osp.stop_scan('')
Example #8
0
 def setUp(self):
     self.connection = MockConnection()
     self.osp = Osp(self.connection)
Example #9
0
class OSPStartScanTestCase(unittest.TestCase):
    def setUp(self):
        self.connection = MockConnection()
        self.osp = Osp(self.connection)

    def test_start_scan(self):
        scanner_params = dict()
        scanner_params['key1'] = 'value1'

        targets = list()
        _target1 = dict()
        _target1['hosts'] = 'localhost'
        _target1['ports'] = '22,80'
        targets.append(_target1)

        _target2 = dict()
        _target2['hosts'] = '192.168.10.1'
        _target2['ports'] = '443'
        _credential1 = dict()
        _credential1 = {
            'smb': {
                'username': '******',
                'password': '******',
                'port': 'port',
                'type': 'type'
            }
        }
        _target2['credentials'] = _credential1
        targets.append(_target2)

        vts = dict()
        vts['vt1'] = {'value_id': 'value'}
        vts['vt_groups'] = ['family=A', 'family=B']

        self.osp.start_scan(scan_id='123-456',
                            parallel=10,
                            scanner_params=scanner_params,
                            targets=targets,
                            vt_selection=vts)

        self.connection.send.has_been_called_with(
            '<start_scan scan_id="123-456" parallel="10">'
            '<scanner_params key1="value1"/>'
            '<targets><target><hosts>localhost</hosts>'
            '<ports>22,80</ports></target>'
            '<target><hosts>192.168.10.1</hosts>'
            '<ports>443</ports>'
            '<credentials>'
            '<credential port="port" service="smb" type="type">'
            '<username>username</username>'
            '<password>pass</password>'
            '</credential></credentials>'
            '</target></targets><vt_selection>'
            '<vt_single id="vt1">'
            '<vt_value id="value_id">value</vt_value></vt_single>'
            '<vt_group filter="family=A"/><vt_group filter="family=B"/>'
            '</vt_selection></start_scan>')

    def test_start_scan_without_target(self):
        with self.assertRaises(RequiredArgument):
            self.osp.start_scan()

    def test_start_scan_legacy(self):
        self.osp.start_scan(scan_id='123-456',
                            parallel=10,
                            target="localhost",
                            ports="22")
        self.connection.send.has_been_called_with(
            '<start_scan scan_id="123-456" parallel="10" '
            'target="localhost" ports="22">'
            '<scanner_params/></start_scan>')
class OSPStartScanTestCase(unittest.TestCase):
    def setUp(self):
        self.connection = MockConnection()
        self.osp = Osp(self.connection)

    def test_start_scan(self):
        scanner_params = OrderedDict()
        scanner_params["key1"] = "value1"

        targets = list()
        _target1 = OrderedDict()
        _target1["hosts"] = "localhost"
        _target1["ports"] = "22,80"
        targets.append(_target1)

        _target2 = OrderedDict()
        _target2["hosts"] = "192.168.10.1"
        _target2["ports"] = "443"
        _smb = OrderedDict()
        _smb["username"] = "******"
        _smb["password"] = "******"
        _smb["port"] = "port"
        _smb["type"] = "type"
        _credential1 = {"smb": _smb}
        _target2["credentials"] = _credential1
        targets.append(_target2)

        vts = OrderedDict()
        vts["vt1"] = {"value_id": "value"}
        vts["vt_groups"] = ["family=A", "family=B"]

        self.osp.start_scan(
            scan_id="123-456",
            parallel=10,
            scanner_params=scanner_params,
            targets=targets,
            vt_selection=vts,
        )

        self.connection.send.has_been_called_with(
            '<start_scan scan_id="123-456" parallel="10">'
            '<scanner_params key1="value1"/>'
            "<targets><target><hosts>localhost</hosts>"
            "<ports>22,80</ports></target>"
            "<target><hosts>192.168.10.1</hosts>"
            "<ports>443</ports>"
            "<credentials>"
            '<credential type="type" port="port" service="smb">'
            "<username>username</username>"
            "<password>pass</password>"
            "</credential></credentials>"
            "</target></targets><vt_selection>"
            '<vt_single id="vt1">'
            '<vt_value id="value_id">value</vt_value></vt_single>'
            '<vt_group filter="family=A"/><vt_group filter="family=B"/>'
            "</vt_selection></start_scan>")

    def test_start_scan_without_target(self):
        with self.assertRaises(RequiredArgument):
            self.osp.start_scan()

    def test_start_scan_legacy(self):
        self.osp.start_scan(scan_id="123-456",
                            parallel=10,
                            target="localhost",
                            ports="22")
        self.connection.send.has_been_called_with(
            '<start_scan scan_id="123-456" parallel="10" '
            'target="localhost" ports="22">'
            "<scanner_params/></start_scan>")