-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Branch: refs/heads/master Date: 2018-01-12T00:28:44+01:00 Author: Harald Friessnegger (frisi) <harald@webmeisterei.com> Commit: plone/plone.protect@bd39399 do not log a warning for empty responses if a text/html response does not contain any data (eg empty page for an ajax request) we do not log a warning that no csrf token could be added this fixes #15 Files changed: M CHANGES.rst M plone/protect/auto.py M plone/protect/tests/testAuto.py Repository: plone.protect Branch: refs/heads/master Date: 2018-01-15T14:56:38+01:00 Author: Harald Friessnegger (frisi) <harald@webmeisterei.com> Commit: plone/plone.protect@6c314bd simplify condition Files changed: M plone/protect/auto.py Repository: plone.protect Branch: refs/heads/master Date: 2018-01-15T18:35:37+01:00 Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org> Commit: plone/plone.protect@ad4456d Merge pull request #69 from plone/no-warning-when-empty do not log a warning for empty responses Files changed: M CHANGES.rst M plone/protect/auto.py M plone/protect/tests/testAuto.py
- Loading branch information
1 parent
5ef41aa
commit 84b4667
Showing
1 changed file
with
189 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,232 @@ | ||
Repository: plone.app.z3cform | ||
Repository: plone.protect | ||
|
||
|
||
Branch: refs/heads/master | ||
Date: 2018-01-10T15:29:33+01:00 | ||
Author: Johannes Raggam (thet) <thetetet@gmail.com> | ||
Commit: https://github.com/plone/plone.app.z3cform/commit/9f7c237cce35b3f8f4acf0ebf21c9a56e72201d3 | ||
Date: 2018-01-12T00:28:44+01:00 | ||
Author: Harald Friessnegger (frisi) <harald@webmeisterei.com> | ||
Commit: https://github.com/plone/plone.protect/commit/bd393995c78e5d74e69c7c1fa794a9cd30a66b2e | ||
|
||
Fix test failures from https://github.com/plone/plone.app.widgets/pull/177 | ||
do not log a warning for empty responses | ||
|
||
if a text/html response does not contain any data (eg empty page for an ajax request) | ||
we do not log a warning that no csrf token could be added | ||
|
||
this fixes #15 | ||
|
||
Files changed: | ||
M CHANGES.rst | ||
M plone/app/z3cform/tests/test_widgets.py | ||
M plone/protect/auto.py | ||
M plone/protect/tests/testAuto.py | ||
|
||
diff --git a/CHANGES.rst b/CHANGES.rst | ||
index 9a6832e..7b03697 100644 | ||
index 07a6237..cffa53c 100644 | ||
--- a/CHANGES.rst | ||
+++ b/CHANGES.rst | ||
@@ -14,7 +14,8 @@ New features: | ||
@@ -14,7 +14,9 @@ New features: | ||
|
||
Bug fixes: | ||
|
||
-- *add item here* | ||
+- Fix test failures from https://github.com/plone/plone.app.widgets/pull/177 | ||
+ [thet] | ||
+- Transform does not log a warning for empty responses | ||
+ (Fixes https://github.com/plone/plone.protect/issues/15) | ||
+ [fRiSi] | ||
|
||
|
||
3.1.1 (2017-08-27) | ||
diff --git a/plone/protect/auto.py b/plone/protect/auto.py | ||
index 2a37578..3324372 100644 | ||
--- a/plone/protect/auto.py | ||
+++ b/plone/protect/auto.py | ||
@@ -107,6 +107,12 @@ def parseTree(self, result, encoding): | ||
'compress',): | ||
return None | ||
|
||
3.0.3 (2017-11-24) | ||
diff --git a/plone/app/z3cform/tests/test_widgets.py b/plone/app/z3cform/tests/test_widgets.py | ||
index e518eeb..d166af9 100644 | ||
--- a/plone/app/z3cform/tests/test_widgets.py | ||
+++ b/plone/app/z3cform/tests/test_widgets.py | ||
@@ -1127,6 +1127,10 @@ class RelatedItemsWidgetTests(unittest.TestCase): | ||
def setUp(self): | ||
self.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'}) | ||
+ if isinstance(result, list): | ||
+ # do not parse empty strings to omit warning log message | ||
+ if len(result) == 1: | ||
+ if result[0].strip() == u'': | ||
+ return None | ||
+ | ||
try: | ||
result = getHTMLSerializer( | ||
result, pretty_print=False, encoding=encoding) | ||
diff --git a/plone/protect/tests/testAuto.py b/plone/protect/tests/testAuto.py | ||
index e3394a4..6ae1252 100644 | ||
--- a/plone/protect/tests/testAuto.py | ||
+++ b/plone/protect/tests/testAuto.py | ||
@@ -182,3 +182,26 @@ def test_safe_write_empty_returns_true(self): | ||
transform = ProtectTransform(self.portal, self.request) | ||
transform._registered_objects = lambda: [self.portal] | ||
self.assertTrue(transform._check()) | ||
+ | ||
+class TestAutoTransform(unittest.TestCase): | ||
+ layer = PROTECT_FUNCTIONAL_TESTING | ||
+ | ||
+ def setUp(self): | ||
+ self.portal = self.layer['portal'] | ||
+ self.request = self.layer['request'] | ||
+ self.request.response.setHeader('Content-Type', 'text/html') | ||
+ self.request.REQUEST_METHOD = 'POST' | ||
+ | ||
+ def test_empty_no_error(self): | ||
+ # empty pages (eg. tiles or ajax requests) should not lead to | ||
+ # transform errors or warnings | ||
+ transform = ProtectTransform(self.portal, self.request) | ||
+ result = transform.transform(['\n'], 'utf-8') | ||
+ self.assertEqual(result, None) | ||
+ | ||
+ def test_html(self): | ||
+ transform = ProtectTransform(self.portal, self.request) | ||
+ result = transform.transform([( | ||
+ '<html>\n<body><form action="http://nohost/myaction" method="POST">' | ||
+ '</form></body>\n</html>')], 'utf-8') | ||
+ self.failUnless('_authenticator' in result.serialize()) | ||
|
||
|
||
Repository: plone.protect | ||
|
||
|
||
Branch: refs/heads/master | ||
Date: 2018-01-15T14:56:38+01:00 | ||
Author: Harald Friessnegger (frisi) <harald@webmeisterei.com> | ||
Commit: https://github.com/plone/plone.protect/commit/6c314bd15e75c2b02c069c252f9b2e3ec916544f | ||
|
||
simplify condition | ||
|
||
Files changed: | ||
M plone/protect/auto.py | ||
|
||
diff --git a/plone/protect/auto.py b/plone/protect/auto.py | ||
index 3324372..f1bd0f9 100644 | ||
--- a/plone/protect/auto.py | ||
+++ b/plone/protect/auto.py | ||
@@ -107,12 +107,10 @@ def parseTree(self, result, encoding): | ||
'compress',): | ||
return None | ||
|
||
+ @mock.patch( | ||
+ 'plone.app.widgets.utils.getToolByName', | ||
+ new=Mock(return_value=Mock(return_value='testuser')) | ||
+ ) | ||
def test_single_selection(self): | ||
"""The pattern_options value for maximumSelectionSize should | ||
be 1 when the field only allows a single selection.""" | ||
@@ -1144,6 +1148,10 @@ def test_single_selection(self): | ||
pattern_options = base_args['pattern_options'] | ||
self.assertEqual(pattern_options.get('maximumSelectionSize', 0), 1) | ||
- if isinstance(result, list): | ||
+ if isinstance(result, list) and len(result) == 1: | ||
# do not parse empty strings to omit warning log message | ||
- if len(result) == 1: | ||
- if result[0].strip() == u'': | ||
- return None | ||
- | ||
+ if not result[0].strip(): | ||
+ return None | ||
try: | ||
result = getHTMLSerializer( | ||
result, pretty_print=False, encoding=encoding) | ||
@@ -139,7 +137,6 @@ def transformUnicode(self, result, encoding): | ||
def transformIterable(self, result, encoding): | ||
"""Apply the transform if required | ||
""" | ||
- | ||
# before anything, do the clickjacking protection | ||
if ( | ||
X_FRAME_OPTIONS and | ||
@@ -320,6 +317,7 @@ def isActionInSite(self, action, current_url): | ||
return True | ||
|
||
+ @mock.patch( | ||
+ 'plone.app.widgets.utils.getToolByName', | ||
+ new=Mock(return_value=Mock(return_value='testuser')) | ||
+ ) | ||
def test_multiple_selection(self): | ||
"""The pattern_options key maximumSelectionSize shouldn't be | ||
set when the field allows multiple selections""" | ||
def transform(self, result, encoding): | ||
+ | ||
result = self.parseTree(result, encoding) | ||
if result is None: | ||
return None | ||
|
||
|
||
Repository: plone.app.z3cform | ||
Repository: plone.protect | ||
|
||
|
||
Branch: refs/heads/master | ||
Date: 2018-01-12T02:18:41+01:00 | ||
Author: Jens W. Klein (jensens) <jk@kleinundpartner.at> | ||
Commit: https://github.com/plone/plone.app.z3cform/commit/41d374f9e0facedf50f3f77c0d14e23d4351e226 | ||
Date: 2018-01-15T18:35:37+01:00 | ||
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org> | ||
Commit: https://github.com/plone/plone.protect/commit/ad4456d6f9c41ee70efef8e252bd8f8508ded20d | ||
|
||
Merge pull request #84 from plone/thet-recentlyused | ||
Merge pull request #69 from plone/no-warning-when-empty | ||
|
||
Fix test failures from https://github.com/plone/plone.app.widgets/pull/177 | ||
do not log a warning for empty responses | ||
|
||
Files changed: | ||
M CHANGES.rst | ||
M plone/app/z3cform/tests/test_widgets.py | ||
M plone/protect/auto.py | ||
M plone/protect/tests/testAuto.py | ||
|
||
diff --git a/CHANGES.rst b/CHANGES.rst | ||
index 9a6832e..7b03697 100644 | ||
index 07a6237..cffa53c 100644 | ||
--- a/CHANGES.rst | ||
+++ b/CHANGES.rst | ||
@@ -14,7 +14,8 @@ New features: | ||
@@ -14,7 +14,9 @@ New features: | ||
|
||
Bug fixes: | ||
|
||
-- *add item here* | ||
+- Fix test failures from https://github.com/plone/plone.app.widgets/pull/177 | ||
+ [thet] | ||
+- Transform does not log a warning for empty responses | ||
+ (Fixes https://github.com/plone/plone.protect/issues/15) | ||
+ [fRiSi] | ||
|
||
|
||
3.0.3 (2017-11-24) | ||
diff --git a/plone/app/z3cform/tests/test_widgets.py b/plone/app/z3cform/tests/test_widgets.py | ||
index e518eeb..d166af9 100644 | ||
--- a/plone/app/z3cform/tests/test_widgets.py | ||
+++ b/plone/app/z3cform/tests/test_widgets.py | ||
@@ -1127,6 +1127,10 @@ class RelatedItemsWidgetTests(unittest.TestCase): | ||
def setUp(self): | ||
self.request = TestRequest(environ={'HTTP_ACCEPT_LANGUAGE': 'en'}) | ||
3.1.1 (2017-08-27) | ||
diff --git a/plone/protect/auto.py b/plone/protect/auto.py | ||
index 2a37578..f1bd0f9 100644 | ||
--- a/plone/protect/auto.py | ||
+++ b/plone/protect/auto.py | ||
@@ -107,6 +107,10 @@ def parseTree(self, result, encoding): | ||
'compress',): | ||
return None | ||
|
||
+ @mock.patch( | ||
+ 'plone.app.widgets.utils.getToolByName', | ||
+ new=Mock(return_value=Mock(return_value='testuser')) | ||
+ ) | ||
def test_single_selection(self): | ||
"""The pattern_options value for maximumSelectionSize should | ||
be 1 when the field only allows a single selection.""" | ||
@@ -1144,6 +1148,10 @@ def test_single_selection(self): | ||
pattern_options = base_args['pattern_options'] | ||
self.assertEqual(pattern_options.get('maximumSelectionSize', 0), 1) | ||
+ if isinstance(result, list) and len(result) == 1: | ||
+ # do not parse empty strings to omit warning log message | ||
+ if not result[0].strip(): | ||
+ return None | ||
try: | ||
result = getHTMLSerializer( | ||
result, pretty_print=False, encoding=encoding) | ||
@@ -133,7 +137,6 @@ def transformUnicode(self, result, encoding): | ||
def transformIterable(self, result, encoding): | ||
"""Apply the transform if required | ||
""" | ||
- | ||
# before anything, do the clickjacking protection | ||
if ( | ||
X_FRAME_OPTIONS and | ||
@@ -314,6 +317,7 @@ def isActionInSite(self, action, current_url): | ||
return True | ||
|
||
+ @mock.patch( | ||
+ 'plone.app.widgets.utils.getToolByName', | ||
+ new=Mock(return_value=Mock(return_value='testuser')) | ||
+ ) | ||
def test_multiple_selection(self): | ||
"""The pattern_options key maximumSelectionSize shouldn't be | ||
set when the field allows multiple selections""" | ||
def transform(self, result, encoding): | ||
+ | ||
result = self.parseTree(result, encoding) | ||
if result is None: | ||
return None | ||
diff --git a/plone/protect/tests/testAuto.py b/plone/protect/tests/testAuto.py | ||
index e3394a4..6ae1252 100644 | ||
--- a/plone/protect/tests/testAuto.py | ||
+++ b/plone/protect/tests/testAuto.py | ||
@@ -182,3 +182,26 @@ def test_safe_write_empty_returns_true(self): | ||
transform = ProtectTransform(self.portal, self.request) | ||
transform._registered_objects = lambda: [self.portal] | ||
self.assertTrue(transform._check()) | ||
+ | ||
+class TestAutoTransform(unittest.TestCase): | ||
+ layer = PROTECT_FUNCTIONAL_TESTING | ||
+ | ||
+ def setUp(self): | ||
+ self.portal = self.layer['portal'] | ||
+ self.request = self.layer['request'] | ||
+ self.request.response.setHeader('Content-Type', 'text/html') | ||
+ self.request.REQUEST_METHOD = 'POST' | ||
+ | ||
+ def test_empty_no_error(self): | ||
+ # empty pages (eg. tiles or ajax requests) should not lead to | ||
+ # transform errors or warnings | ||
+ transform = ProtectTransform(self.portal, self.request) | ||
+ result = transform.transform(['\n'], 'utf-8') | ||
+ self.assertEqual(result, None) | ||
+ | ||
+ def test_html(self): | ||
+ transform = ProtectTransform(self.portal, self.request) | ||
+ result = transform.transform([( | ||
+ '<html>\n<body><form action="http://nohost/myaction" method="POST">' | ||
+ '</form></body>\n</html>')], 'utf-8') | ||
+ self.failUnless('_authenticator' in result.serialize()) | ||
|
||
|