Skip to content

Commit

Permalink
update for string rep
Browse files Browse the repository at this point in the history
  • Loading branch information
hblankenship committed Dec 6, 2024
1 parent 0b660d6 commit abeec99
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 54 deletions.
8 changes: 8 additions & 0 deletions dojo/api_v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,14 @@ def get_stringresponse(self, obj) -> str:

return result

def to_representation(self, data):
return {
"id": data.id,
"finding": data.finding.id,
"burpRequestBase64": data.burpRequestBase64.decode("utf-8"),
"burpResponseBase64": data.burpResponseBase64.decode("utf-8"),
}

def validate(self, data):
b64request = data.get("burpRequestBase64", None)
b64response = data.get("burpResponseBase64", None)
Expand Down
8 changes: 0 additions & 8 deletions dojo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3619,14 +3619,6 @@ class BurpRawRequestResponse(models.Model):
burpRequestBase64 = models.BinaryField()
burpResponseBase64 = models.BinaryField()

@property
def string_response(self):
return self.get_response()

@property
def string_request(self):
return self.get_request()

def get_request(self):
return str(base64.b64decode(self.burpRequestBase64), errors="ignore")

Expand Down
46 changes: 0 additions & 46 deletions unittests/test_rest_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -3076,49 +3076,3 @@ def __init__(self, *args, **kwargs):
self.test_type = TestType.STANDARD
self.deleted_objects = 1
BaseClass.RESTEndpointTest.__init__(self, *args, **kwargs)

# Overriding the test_update because the response is a string of the byte encoding and we are going to strip that away....
# but otherwise do all the same stuff (most of it isn't needed, though)
@skipIfNotSubclass(UpdateModelMixin)
def test_update(self):
current_objects = self.client.get(self.url, format="json").data
relative_url = self.url + "{}/".format(current_objects["results"][0]["id"])
response = self.client.patch(relative_url, self.update_fields)
self.assertEqual(200, response.status_code, response.content[:1000])

# self.check_schema_response("patch", "200", response, detail=True)

for key, value in self.update_fields.items():
# some exception as push_to_jira has been implemented strangely in the update methods in the api
if key not in ["push_to_jira", "ssh", "password", "api_key"]:
# Convert data to sets to avoid problems with lists
if isinstance(value, list):
clean_value = set(value)
else:
clean_value = value
if isinstance(response.data[key], list):
response_data = set(response.data[key])
elif isinstance(response.data[key], str):
if response.data[key].startswith("b'") and response.data[key].endswith("'"):
response_data = response.data[key][2:len(response.data[key]) - 1]
else:
response_data = response.data[key]

self.assertEqual(clean_value, response_data)

self.assertNotIn("push_to_jira", response.data)
self.assertNotIn("ssh", response.data)
self.assertNotIn("password", response.data)
self.assertNotIn("api_key", response.data)

if hasattr(self.endpoint_model, "tags") and self.update_fields and self.update_fields.get("tags", None):
self.assertEqual(len(self.update_fields.get("tags")), len(response.data.get("tags", None)))
for tag in self.update_fields.get("tags"):
logger.debug("looking for tag %s in tag list %s", tag, response.data["tags"])
self.assertIn(tag, response.data["tags"])

response = self.client.put(
relative_url, self.payload)
self.assertEqual(200, response.status_code, response.content[:1000])

self.check_schema_response("put", "200", response, detail=True)

0 comments on commit abeec99

Please sign in to comment.