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

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnicola committed Nov 7, 2019
1 parent 2f813b4 commit 36fdc54
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/test_argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
DEFAULT_PORT,
DEFAULT_KEY_FILE,
DEFAULT_NICENESS,
DEFAULT_SCANINFO_STORE_TIME,
)


Expand Down Expand Up @@ -93,3 +94,4 @@ def test_defaults(self):
self.assertEqual(args.log_level, logging.WARNING)
self.assertEqual(args.address, DEFAULT_ADDRESS)
self.assertEqual(args.port, DEFAULT_PORT)
self.assertEqual(args.port, DEFAULT_SCANINFO_STORE_TIME)
50 changes: 50 additions & 0 deletions tests/test_scan_and_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,56 @@ def test_get_vts_vts_with_mtime(self):
ET.tostring(modification_time[0]).decode('utf-8'),
)

def test_clean_forgotten_scans(self):
daemon = DummyWrapper([])

response = secET.fromstring(
daemon.handle_command(
'<start_scan target="localhost" ports="80, '
'443"><scanner_params /></start_scan>'
)
)
scan_id = response.findtext('id')

finished = False
while not finished:
response = secET.fromstring(
daemon.handle_command(
'<get_scans scan_id="%s" details="1"/>' % scan_id
)
)
scans = response.findall('scan')
self.assertEqual(1, len(scans))

scan = scans[0]
status = scan.get('status')

if status == "init" or status == "running":
self.assertEqual('0', scan.get('end_time'))
time.sleep(0.010)
else:
finished = True

response = secET.fromstring(
daemon.handle_command(
'<get_scans scan_id="%s" details="1"/>' % scan_id
)
)
self.assertEqual(len(list(daemon.scan_collection.ids_iterator())), 1)

# Set an old end_time
daemon.scan_collection.scans_table[scan_id]['end_time'] = 123456
# Run the check
daemon.clean_forgotten_scans()
#Not removed
self.assertEqual(len(list(daemon.scan_collection.ids_iterator())), 1)

# Set the max time and run again
daemon.scaninfo_store_time = 1
daemon.clean_forgotten_scans()
# Now is removed
self.assertEqual(len(list(daemon.scan_collection.ids_iterator())), 0)

def test_scan_with_error(self):
daemon = DummyWrapper([Result('error', value='something went wrong')])

Expand Down

0 comments on commit 36fdc54

Please sign in to comment.