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

Add dummy stop_scan method to be implemented in the wrapper. #24

Merged
merged 1 commit into from
Jun 26, 2018
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
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))