Skip to content

Commit

Permalink
Fix tests to work with the Zope security fix.
Browse files Browse the repository at this point in the history
Accept binary and text type, as long as it is empty.
Fixes #106
  • Loading branch information
mauritsvanrees committed Dec 21, 2022
1 parent 567dce4 commit 52885bf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
2 changes: 2 additions & 0 deletions news/106.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix tests to work with the Zope security fix.
[maurits]
15 changes: 10 additions & 5 deletions plone/app/caching/tests/test_profile_with_caching_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ 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 @@ -193,7 +198,7 @@ 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.assertEqual(b'', browser.contents)
self.assertBrowserEmpty(browser)

# Request the anonymous folder
now = stable_now()
Expand Down Expand Up @@ -261,7 +266,7 @@ 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.assertEqual(b'', browser.contents)
self.assertBrowserEmpty(browser)

# Edit the page to update the etag
testText2 = 'Testing... body two'
Expand Down Expand Up @@ -354,7 +359,7 @@ 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.assertEqual(b'', browser.contents)
self.assertBrowserEmpty(browser)

# Request the authenticated rss feed
now = stable_now()
Expand Down Expand Up @@ -484,7 +489,7 @@ 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.assertEqual(b'', browser.contents)
self.assertBrowserEmpty(browser)

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

# Request a large datafile (over 64K) to test files that use
# the "response.write()" function to initiate a streamed response.
Expand Down
15 changes: 10 additions & 5 deletions plone/app/caching/tests/test_profile_without_caching_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ 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 @@ -188,7 +193,7 @@ 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.assertEqual(b'', browser.contents)
self.assertBrowserEmpty(browser)

# Request the anonymous folder
now = stable_now()
Expand Down Expand Up @@ -255,7 +260,7 @@ 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.assertEqual(b'', browser.contents)
self.assertBrowserEmpty(browser)

# Edit the page to update the etag
testText2 = 'Testing... body two'
Expand Down Expand Up @@ -341,7 +346,7 @@ 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.assertEqual(b'', browser.contents)
self.assertBrowserEmpty(browser)

# Request the authenticated rss feed
now = stable_now()
Expand Down Expand Up @@ -427,7 +432,7 @@ 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.assertEqual(b'', browser.contents)
self.assertBrowserEmpty(browser)

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

# 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 52885bf

Please sign in to comment.