Skip to content

Commit 9eb0538

Browse files
committed
adding reimport_scan feature and associated unit test
1 parent 87006a6 commit 9eb0538

2 files changed

Lines changed: 32 additions & 22 deletions

File tree

defectdojo_api/defectdojo.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -668,35 +668,35 @@ def upload_scan(self, engagement_id, scan_type, file, active, scan_date, tags=No
668668
files=data
669669
)
670670

671-
##### Credential API #####
671+
##### Re-upload API #####
672672

673-
def list_credentials(self, name=None, username=None, limit=20):
674-
"""Retrieves all the globally configured credentials.
673+
def reupload_scan(self, test_id, scan_type, file, active, scan_date, tags=None, build=None):
674+
"""Re-uploads and processes a scan file.
675675
676-
:param name_contains: Search by credential name.
677-
:param username: Search by username
678-
:param limit: Number of records to return.
676+
:param test_id: Test identifier.
677+
:param file: Path to the scan file to be uploaded.
679678
680679
"""
680+
if tags is None:
681+
tags = ''
681682

682-
params = {}
683-
if limit:
684-
params['limit'] = limit
685-
686-
if name:
687-
params['name__contains'] = name
688-
689-
if username:
690-
params['username__contains'] = username
683+
if build is None:
684+
build = ''
691685

692-
return self._request('GET', 'credentials/', params)
686+
data = {
687+
'test': ('', self.get_test_uri(test_id)),
688+
'file': open(file, 'rb'),
689+
'scan_type': ('', scan_type),
690+
'active': ('', active),
691+
'scan_date': ('', scan_date),
692+
'tags': ('', tags),
693+
'build_id': ('', build)
694+
}
693695

694-
def get_credential(self, cred_id, limit=20):
695-
"""
696-
Retrieves a credential using the given credential id.
697-
:param credential_id: Credential identification.
698-
"""
699-
return self._request('GET', 'credentials/' + str(cred_id) + '/')
696+
return self._request(
697+
'POST', 'reimportscan/',
698+
files=data
699+
)
700700

701701
##### Credential Mapping API #####
702702

tests/defectdojo_api_unit_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,15 @@ def test_19_upload_scan(self):
158158

159159
self.assertIsNotNone(upload_scan.id())
160160

161+
#### Re-upload API Test ####
162+
def test_20_reupload_scan(self):
163+
dir_path = os.path.dirname(os.path.realpath(__file__))
164+
165+
date = datetime.now()
166+
upload_scan = self.dd.upload_scan(self.__class__.test_id, "Burp Scan", dir_path + "/scans/Bodgeit-burp.xml",
167+
"true", date.strftime("%Y/%m/%d"), "API")
168+
169+
self.assertIsNotNone(upload_scan.id())
170+
161171
if __name__ == '__main__':
162172
unittest.main()

0 commit comments

Comments
 (0)