changeset 8182:5fcc1a379564

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.
author John Rouillard <rouilj@ieee.org>
date Sun, 08 Dec 2024 18:26:09 -0500
parents 0a6ca45c53b4
children 8c17d0def3f3
files test/rest_common.py
diffstat 1 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/test/rest_common.py	Sun Dec 08 18:03:07 2024 -0500
+++ b/test/rest_common.py	Sun Dec 08 18:26:09 2024 -0500
@@ -3052,6 +3052,28 @@
 
         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'
 

Roundup Issue Tracker: http://roundup-tracker.org/