diff --git a/tenable/io/scans.py b/tenable/io/scans.py index 42b2a0fd6..6c5aff746 100644 --- a/tenable/io/scans.py +++ b/tenable/io/scans.py @@ -1175,7 +1175,7 @@ def launch(self, def list(self, folder_id: Optional[int] = None, - last_modified: Optional[int] = None + last_modified: Optional[datetime] = None ) -> List[Dict]: ''' Retrieve the list of configured scans. @@ -1199,11 +1199,13 @@ def list(self, params = {} if folder_id: params['folder_id'] = folder_id - if last_modified: + if last_modified and isinstance(last_modified, datetime): # for the last_modified datetime attribute, we will want to convert # that into a timestamp integer before passing it to the API. - lm = int(time.mktime(last_modified).timetuple()) + lm = int(time.mktime(last_modified.timetuple())) params['last_modification_date'] = lm + if last_modified and isinstance(last_modified, int): + params['last_modification_date'] = last_modified return self._get(params=params).scans diff --git a/tests/io/test_scans.py b/tests/io/test_scans.py index 80f7d5f27..53e9d35ce 100644 --- a/tests/io/test_scans.py +++ b/tests/io/test_scans.py @@ -4,10 +4,14 @@ import uuid import time import os +import datetime import responses from io import BytesIO from sys import stdout import pytest +import responses +from tenable.io import TenableIO +from responses.matchers import query_param_matcher from tenable.reports.nessusv2 import NessusReportv2 from tenable.errors import UnexpectedValueError, NotFoundError, BadRequestError from tests.checker import check, single @@ -1955,3 +1959,19 @@ def test_scan_create_scan_document_credentials_compliance_plugins(api): 'auth_method': 'Password'}]}}, 'compliance': {'test': 'testvalue'}, 'plugins': {12122: 13, 12050: 13}}) + + +@responses.activate +def test_list_api(): + dt = datetime.datetime(2024, 1, 1) + dt_int = int(time.mktime(dt.timetuple())) + responses.get( + 'https://nourl/scans', + json={'scans': []}, + match=[ + query_param_matcher({'last_modification_date': dt_int,'folder_id': 1}) + ] + ) + tvm = TenableIO(url='https://nourl', access_key='something', secret_key='something') + assert tvm.scans.list(folder_id=1, last_modified=dt) == [] + assert tvm.scans.list(folder_id=1, last_modified=dt_int) == []