|
2 | 2 | import json
|
3 | 3 | import logging
|
4 | 4 | import pathlib
|
| 5 | +import re |
5 | 6 | from collections import OrderedDict
|
6 | 7 | from enum import Enum
|
7 | 8 | from json import dumps
|
@@ -1141,6 +1142,31 @@ def test_request_response_get(self):
|
1141 | 1142 | response = self.client.get(f"/api/v2/{level}/files/")
|
1142 | 1143 | self.assertEqual(200, response.status_code)
|
1143 | 1144 |
|
| 1145 | + def test_file_with_quoted_name(self): |
| 1146 | + level = "findings/7" |
| 1147 | + with (get_unit_tests_scans_path("acunetix") / "one_finding.xml").open(encoding="utf-8") as testfile: |
| 1148 | + # Create a new file first |
| 1149 | + payload = { |
| 1150 | + "title": 'A file "title" with Quotes & other bad chars #broken', |
| 1151 | + "file": testfile, |
| 1152 | + } |
| 1153 | + response = self.client.post(f"/api/v2/{level}/files/", payload) |
| 1154 | + self.assertEqual(201, response.status_code, response.data) |
| 1155 | + file_id = response.data.get("id") |
| 1156 | + |
| 1157 | + # Download the file and ensure the content is accurate |
| 1158 | + response = self.client.get(f"/api/v2/{level}/files/download/{file_id}/") |
| 1159 | + downloaded_file = b"".join(response.streaming_content).decode().replace("\\n", "\n") |
| 1160 | + file_data = (get_unit_tests_scans_path("acunetix") / "one_finding.xml").read_text(encoding="utf-8") |
| 1161 | + self.assertEqual(file_data, downloaded_file) |
| 1162 | + # Check the name of the file is correct |
| 1163 | + if (match := re.search(r'filename="?(?P<filename>[^";]+)"?', response.get("Content-Disposition"))): |
| 1164 | + filename = match.group("filename") |
| 1165 | + self.assertEqual(filename, "A file -title- with Quotes - other bad chars -broken.xml") |
| 1166 | + else: |
| 1167 | + msg = "Content-Disposition header must contain the filename parameter" |
| 1168 | + raise NotImplementedError(msg) |
| 1169 | + |
1144 | 1170 |
|
1145 | 1171 | class FindingsTest(BaseClass.BaseClassTest):
|
1146 | 1172 | fixtures = ["dojo_testdata.json"]
|
|
0 commit comments