def test_unknown_scan_id(self): daemon = DummyWrapper([]) cmd = StopScan(daemon) request = et.fromstring('<stop_scan scan_id="foo" />') with self.assertRaises(OspdCommandError): cmd.handle_xml(request)
def test_stop_scan(self, mock_create_process, mock_os): mock_process = mock_create_process.return_value mock_process.is_alive.return_value = True mock_process.pid = "foo" fs = FakeStream() daemon = DummyWrapper([]) request = ('<start_scan>' '<targets>' '<target>' '<hosts>localhosts</hosts>' '<ports>22</ports>' '</target>' '</targets>' '<scanner_params />' '</start_scan>') daemon.handle_command(request, fs) response = fs.get_response() assert_called(mock_create_process) assert_called(mock_process.start) scan_id = response.findtext('id') request = et.fromstring('<stop_scan scan_id="%s" />' % scan_id) cmd = StopScan(daemon) cmd.handle_xml(request) assert_called(mock_process.terminate) mock_os.getpgid.assert_called_with('foo')
def test_missing_scan_id(self): request = et.fromstring('<stop_scan />') cmd = StopScan(None) with self.assertRaises(OspdCommandError): cmd.handle_xml(request)