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

Commit

Permalink
Merge pull request #24 from jjnicola/stop-scan
Browse files Browse the repository at this point in the history
Add dummy stop_scan method to be implemented in the wrapper.
  • Loading branch information
janowagner authored Jun 26, 2018
2 parents 5099f8f + 59a8468 commit a8e77a1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ospd/ospd.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ def handle_stop_scan_command(self, scan_et):
raise OSPDError('Scan already stopped or finished.', 'stop_scan')

logger.info('{0}: Scan stopping {1}.'.format(scan_id, scan_process.ident))
self.stop_scan(scan_id)
scan_process.terminate()
os.killpg(os.getpgid(scan_process.ident), 15)
scan_process.join()
Expand All @@ -456,6 +457,10 @@ def handle_stop_scan_command(self, scan_et):
logger.info('{0}: Scan stopped.'.format(scan_id))
return simple_response_str('stop_scan', 200, 'OK')

def stop_scan(self, scan_id):
""" Should be implemented by subclass in case of a clean up before
terminating is needed. """

def exec_scan(self, scan_id, target):
""" Asserts to False. Should be implemented by subclass. """
raise NotImplementedError
Expand Down
18 changes: 18 additions & 0 deletions tests/testScanAndResult.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,21 @@ def testiScanWithError(self):
response = ET.fromstring(daemon.handle_command('<delete_scan scan_id="%s" />' % scan_id))
self.assertEqual(response.get('status'), '200')
print(ET.tostring(response))

def testStopScan(self):
daemon = DummyWrapper([])
response = ET.fromstring(
daemon.handle_command('<start_scan ' +
'target="localhost" ports="80, 443">' +
'<scanner_params /></start_scan>'))
print(ET.tostring(response))
scan_id = response.findtext('id')
time.sleep(0.01)

response = daemon.stop_scan(scan_id)
self.assertEqual(response, None)

response = ET.fromstring(daemon.handle_command(
'<stop_scan scan_id="%s" />' % scan_id))
self.assertEqual(response.get('status'), '200')
print(ET.tostring(response))

0 comments on commit a8e77a1

Please sign in to comment.