From 52885bf0f81ccb655196a65226e424ae74b9b253 Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Wed, 21 Dec 2022 12:20:56 +0100 Subject: [PATCH] Fix tests to work with the Zope security fix. Accept binary and text type, as long as it is empty. Fixes https://github.com/plone/plone.app.caching/issues/106 --- news/106.bugfix | 2 ++ .../tests/test_profile_with_caching_proxy.py | 15 ++++++++++----- .../tests/test_profile_without_caching_proxy.py | 15 ++++++++++----- 3 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 news/106.bugfix diff --git a/news/106.bugfix b/news/106.bugfix new file mode 100644 index 00000000..9c52366c --- /dev/null +++ b/news/106.bugfix @@ -0,0 +1,2 @@ +Fix tests to work with the Zope security fix. +[maurits] diff --git a/plone/app/caching/tests/test_profile_with_caching_proxy.py b/plone/app/caching/tests/test_profile_with_caching_proxy.py index 5cca9794..a8dab3cd 100644 --- a/plone/app/caching/tests/test_profile_with_caching_proxy.py +++ b/plone/app/caching/tests/test_profile_with_caching_proxy.py @@ -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? @@ -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() @@ -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' @@ -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() @@ -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() @@ -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. diff --git a/plone/app/caching/tests/test_profile_without_caching_proxy.py b/plone/app/caching/tests/test_profile_without_caching_proxy.py index 59d5a963..de07d9d5 100644 --- a/plone/app/caching/tests/test_profile_without_caching_proxy.py +++ b/plone/app/caching/tests/test_profile_without_caching_proxy.py @@ -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'] @@ -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() @@ -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' @@ -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() @@ -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() @@ -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.