diff --git a/defectdojo_api/defectdojo.py b/defectdojo_api/defectdojo.py index 79e4de6bf8bf57feb05a746ac9368a242994ae3c..06bccfd6cda571a8f108b19b5f67d3d528c9966d 100644 --- a/defectdojo_api/defectdojo.py +++ b/defectdojo_api/defectdojo.py @@ -668,35 +668,35 @@ class DefectDojoAPI(object): files=data ) - ##### Credential API ##### + ##### Re-upload API ##### - def list_credentials(self, name=None, username=None, limit=20): - """Retrieves all the globally configured credentials. + def reupload_scan(self, test_id, scan_type, file, active, scan_date, tags=None, build=None): + """Re-uploads and processes a scan file. - :param name_contains: Search by credential name. - :param username: Search by username - :param limit: Number of records to return. + :param test_id: Test identifier. + :param file: Path to the scan file to be uploaded. """ + if tags is None: + tags = '' - params = {} - if limit: - params['limit'] = limit - - if name: - params['name__contains'] = name - - if username: - params['username__contains'] = username + if build is None: + build = '' - return self._request('GET', 'credentials/', params) + data = { + 'test': ('', self.get_test_uri(test_id)), + 'file': open(file, 'rb'), + 'scan_type': ('', scan_type), + 'active': ('', active), + 'scan_date': ('', scan_date), + 'tags': ('', tags), + 'build_id': ('', build) + } - def get_credential(self, cred_id, limit=20): - """ - Retrieves a credential using the given credential id. - :param credential_id: Credential identification. - """ - return self._request('GET', 'credentials/' + str(cred_id) + '/') + return self._request( + 'POST', 'reimportscan/', + files=data + ) ##### Credential Mapping API ##### diff --git a/tests/defectdojo_api_unit_test.py b/tests/defectdojo_api_unit_test.py index 5c0c9c90948b3d733596c66088982d3aafabd4f4..ece142f48597d59bdce0d2f80d589e9266977580 100644 --- a/tests/defectdojo_api_unit_test.py +++ b/tests/defectdojo_api_unit_test.py @@ -158,5 +158,15 @@ class TestDefectDojoAPI(unittest.TestCase): self.assertIsNotNone(upload_scan.id()) + #### Re-upload API Test #### + def test_20_reupload_scan(self): + dir_path = os.path.dirname(os.path.realpath(__file__)) + + date = datetime.now() + upload_scan = self.dd.upload_scan(self.__class__.test_id, "Burp Scan", dir_path + "/scans/Bodgeit-burp.xml", + "true", date.strftime("%Y/%m/%d"), "API") + + self.assertIsNotNone(upload_scan.id()) + if __name__ == '__main__': unittest.main()