From 9eb0538ac92431ac105625ebfa8a19e99e6e5a10 Mon Sep 17 00:00:00 2001
From: brianlam38 <brian.lam38@gmail.com>
Date: Wed, 13 Dec 2017 10:51:58 +1100
Subject: [PATCH] adding reimport_scan feature and associated unit test

---
 defectdojo_api/defectdojo.py      | 44 +++++++++++++++----------------
 tests/defectdojo_api_unit_test.py | 10 +++++++
 2 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/defectdojo_api/defectdojo.py b/defectdojo_api/defectdojo.py
index 79e4de6..06bccfd 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 5c0c9c9..ece142f 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()
-- 
GitLab