Skip to content

Commit 58e1dfd

Browse files
authored
Merge pull request #8 from brianlam38/feature-reuploadscan
Adding reimport_scan feature and associated unit test
2 parents 87006a6 + d2ac1a1 commit 58e1dfd

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

defectdojo_api/defectdojo.py

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

671+
##### Re-upload API #####
672+
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.
675+
676+
:param test_id: Test identifier.
677+
:param file: Path to the scan file to be uploaded.
678+
679+
"""
680+
if tags is None:
681+
tags = ''
682+
683+
if build is None:
684+
build = ''
685+
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+
}
695+
696+
return self._request(
697+
'POST', 'reimportscan/',
698+
files=data
699+
)
700+
671701
##### Credential API #####
672702

673703
def list_credentials(self, name=None, username=None, limit=20):
674704
"""Retrieves all the globally configured credentials.
675-
676705
:param name_contains: Search by credential name.
677706
:param username: Search by username
678707
:param limit: Number of records to return.
679-
680708
"""
681709

682710
params = {}
@@ -697,7 +725,7 @@ def get_credential(self, cred_id, limit=20):
697725
:param credential_id: Credential identification.
698726
"""
699727
return self._request('GET', 'credentials/' + str(cred_id) + '/')
700-
728+
701729
##### Credential Mapping API #####
702730

703731
def list_credential_mappings(self, name=None, product_id_in=None, engagement_id_in=None, test_id_in=None, finding_id_in=None, limit=20):

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)