Skip to content

Commit

Permalink
Revert changes to tests to work with the Zope security fix.
Browse files Browse the repository at this point in the history
We must have an empty byte, not text, otherwise it is an indication that we get a possibly wrong Content-Type in a 304 status.
See zopefoundation/Zope#1089.

This reverts commit 52885bf.
  • Loading branch information
mauritsvanrees committed Jan 9, 2023
1 parent 6862062 commit 9accdb1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
4 changes: 4 additions & 0 deletions news/1089.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Revert changes to tests to work with the Zope security fix.
We must have an empty byte, not text, otherwise it is an indication that we get a possibly wrong Content-Type in a 304 status.
See `Zope issue 1089 <https://github.com/zopefoundation/Zope/issues/1089>`_.
[maurits]
23 changes: 13 additions & 10 deletions plone/app/caching/tests/test_profile_with_caching_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ def setUp(self):
def tearDown(self):
setRequest(None)

def assertBrowserEmpty(self, browser):
# assert that browser.contents is an empty bytes/string/unicode.
self.assertIsInstance(browser.contents, (six.binary_type, six.text_type))
self.assertFalse(browser.contents)

def test_composite_viewsxx(self):
# This is a clone of the same test for 'without-caching-proxy'
# Can we just call that test from this context?
Expand Down Expand Up @@ -198,7 +193,11 @@ def test_composite_viewsxx(self):
browser.open(self.portal['f1']['d1'].absolute_url())
# This should be a 304 response
self.assertEqual('304 Not Modified', browser.headers['Status'])
self.assertBrowserEmpty(browser)
# We MUST have an empty byte, not text, otherwise it is an indication that we
# get a possibly wrong Content-Type in a 304 status.
# See https://github.com/zopefoundation/Zope/issues/1089.
self.assertEqual(b'', browser.contents)
self.assertFalse(browser.headers['Content-Type'])

# Request the anonymous folder
now = stable_now()
Expand Down Expand Up @@ -266,7 +265,8 @@ def test_composite_viewsxx(self):
browser.headers['X-Cache-Operation'])
# This should be a 304 response
self.assertEqual('304 Not Modified', browser.headers['Status'])
self.assertBrowserEmpty(browser)
self.assertEqual(b'', browser.contents)
self.assertFalse(browser.headers['Content-Type'])

# Edit the page to update the etag
testText2 = 'Testing... body two'
Expand Down Expand Up @@ -359,7 +359,8 @@ def test_content_feeds(self):
browser.headers['X-Cache-Operation'])
# This should be a 304 response
self.assertEqual('304 Not Modified', browser.headers['Status'])
self.assertBrowserEmpty(browser)
self.assertEqual(b'', browser.contents)
self.assertFalse(browser.headers['Content-Type'])

# Request the authenticated rss feed
now = stable_now()
Expand Down Expand Up @@ -489,7 +490,8 @@ def test_content_files(self):
browser.headers['X-Cache-Operation'])
# This should be a 304 response
self.assertEqual('304 Not Modified', browser.headers['Status'])
self.assertBrowserEmpty(browser)
self.assertEqual(b'', browser.contents)
self.assertFalse(browser.headers['Content-Type'])

# Request an image scale
now = stable_now()
Expand Down Expand Up @@ -540,7 +542,8 @@ def test_resources(self):
browser.headers['X-Cache-Operation'])
# This should be a 304 response
self.assertEqual('304 Not Modified', browser.headers['Status'])
self.assertBrowserEmpty(browser)
self.assertEqual(b'', browser.contents)
self.assertFalse(browser.headers['Content-Type'])

# Request a large datafile (over 64K) to test files that use
# the "response.write()" function to initiate a streamed response.
Expand Down
23 changes: 13 additions & 10 deletions plone/app/caching/tests/test_profile_without_caching_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ def setUp(self):
def tearDown(self):
setRequest(None)

def assertBrowserEmpty(self, browser):
# assert that browser.contents is an empty bytes/string/unicode.
self.assertIsInstance(browser.contents, (six.binary_type, six.text_type))
self.assertFalse(browser.contents)

def test_composite_views(self):

catalog = self.portal['portal_catalog']
Expand Down Expand Up @@ -193,7 +188,11 @@ def test_composite_views(self):
browser.open(self.portal['f1']['d1'].absolute_url())
# This should be a 304 response
self.assertEqual('304 Not Modified', browser.headers['Status'])
self.assertBrowserEmpty(browser)
# We MUST have an empty byte, not text, otherwise it is an indication that we
# get a possibly wrong Content-Type in a 304 status.
# See https://github.com/zopefoundation/Zope/issues/1089.
self.assertEqual(b'', browser.contents)
self.assertFalse(browser.headers['Content-Type'])

# Request the anonymous folder
now = stable_now()
Expand Down Expand Up @@ -260,7 +259,8 @@ def test_composite_views(self):
browser.headers['X-Cache-Operation'])
# This should be a 304 response
self.assertEqual('304 Not Modified', browser.headers['Status'])
self.assertBrowserEmpty(browser)
self.assertEqual(b'', browser.contents)
self.assertFalse(browser.headers['Content-Type'])

# Edit the page to update the etag
testText2 = 'Testing... body two'
Expand Down Expand Up @@ -346,7 +346,8 @@ def test_content_feeds(self):
browser.headers['X-Cache-Operation'])
# This should be a 304 response
self.assertEqual('304 Not Modified', browser.headers['Status'])
self.assertBrowserEmpty(browser)
self.assertEqual(b'', browser.contents)
self.assertFalse(browser.headers['Content-Type'])

# Request the authenticated rss feed
now = stable_now()
Expand Down Expand Up @@ -432,7 +433,8 @@ def test_content_files(self):
browser.headers['X-Cache-Operation'])
# This should be a 304 response
self.assertEqual('304 Not Modified', browser.headers['Status'])
self.assertBrowserEmpty(browser)
self.assertEqual(b'', browser.contents)
self.assertFalse(browser.headers['Content-Type'])

# Request an image scale
now = stable_now()
Expand Down Expand Up @@ -481,7 +483,8 @@ def test_resources(self):
browser.headers['X-Cache-Operation'])
# This should be a 304 response
self.assertEqual('304 Not Modified', browser.headers['Status'])
self.assertBrowserEmpty(browser)
self.assertEqual(b'', browser.contents)
self.assertFalse(browser.headers['Content-Type'])

# Request a large datafile (over 64K) to test files that use
# the "response.write()" function to initiate a streamed response.
Expand Down

0 comments on commit 9accdb1

Please sign in to comment.