From ba936af5c3b3a3fca8ea9341c6e43272a2ae9e6c Mon Sep 17 00:00:00 2001 From: John Rouillard Date: Sun, 8 Dec 2024 18:26:09 -0500 Subject: [PATCH] feat: add test download via /binary_content via dispatch - issue2551068 CI showed I missed a code path. Dispatch and format_dispatch_output did not have a test case though the /binary_content code path. Added this test and verifies the data, content-type, lack of ETag header, presence of header to prevent browser sniffing. --- test/rest_common.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/rest_common.py b/test/rest_common.py index b3bf4398..522fddda 100644 --- a/test/rest_common.py +++ b/test/rest_common.py @@ -3052,6 +3052,28 @@ def testDispatch(self): del(self.headers) + # TEST #11 + # GET: test that /binary_content can be downloaded + form = cgi.FieldStorage() + + self.server.client.env.update({'REQUEST_METHOD': 'GET'}) + + headers={"accept": "*/*" } + self.headers=headers + self.server.client.request.headers.get=self.get_header + results = self.server.dispatch('GET', + "/rest/data/file/1/binary_content", form) + + self.assertEqual(results, b'PNG\x01abcdefghi\njklmnop') + self.assertEqual(self.server.client.additional_headers['Content-Type'], + 'image/png') + self.assertNotIn("ETag", self.server.client.additional_headers) + self.assertEqual( + self.server.client.additional_headers["X-Content-Type-Options"], + "nosniff") + + print("11: " + b2s(results)) + def testAcceptHeaderParsing(self): self.server.client.env['REQUEST_METHOD'] = 'GET'