Skip to content

Commit

Permalink
feat: add test download via /binary_content via dispatch - issue2551068
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rouilj committed Dec 8, 2024
1 parent 2dccdf2 commit ba936af
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/rest_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down

0 comments on commit ba936af

Please sign in to comment.