Skip to content

Commit

Permalink
Corrected last_modified issue #810
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveMcGrath committed Sep 17, 2024
1 parent b9b6aed commit 2169503
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tenable/io/scans.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
20 changes: 20 additions & 0 deletions tests/io/test_scans.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, 12, 1, tzinfo=datetime.UTC)
dt_int = 1733032800
responses.get(
'https://nourl/scans',
json={'scans': []},
match=[
query_param_matcher({'last_modification_date': 1733032800,'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) == []

0 comments on commit 2169503

Please sign in to comment.