diff test/test_actions.py @ 4880:ca692423e401

Different approach to fix XSS in issue2550817 Encapsulate the error/ok message append method as add_ok_message and add_error_message. The new approach escapes the messages when appending -- at a point in the code where we still know where the message comes from. Escaping is the default but can bei turned off. This also fixes issue2550836 where certain messages may contain links. Another advantage of the new fix is that users don't need to change installed trackers and are secure by default.
author Ralf Schlatterbeck <rsc@runtux.com>
date Mon, 31 Mar 2014 18:19:23 +0200
parents 9cc6d463cfbe
children b562df8a5056
line wrap: on
line diff
--- a/test/test_actions.py	Sat Mar 29 11:59:37 2014 +0100
+++ b/test/test_actions.py	Mon Mar 31 18:19:23 2014 +0200
@@ -4,6 +4,7 @@
 from roundup import hyperdb
 from roundup.date import Date, Interval
 from roundup.cgi.actions import *
+from roundup.cgi.client import add_message
 from roundup.cgi.exceptions import Redirect, Unauthorised, SeriousError
 
 from mocknull import MockNull
@@ -15,6 +16,12 @@
     def setUp(self):
         self.form = FieldStorage()
         self.client = MockNull()
+        self.client._ok_message = []
+        self.client._error_message = []
+        self.client.add_error_message = lambda x : add_message(
+            self.client._error_message, x)
+        self.client.add_ok_message = lambda x : add_message(
+            self.client._ok_message, x)
         self.client.form = self.form
         class TemplatingUtils:
             pass
@@ -60,9 +67,9 @@
 class RetireActionTestCase(ActionTestCase):
     def testRetireAction(self):
         self.client.db.security.hasPermission = true
-        self.client.ok_message = []
+        self.client._ok_message = []
         RetireAction(self.client).handle()
-        self.assert_(len(self.client.ok_message) == 1)
+        self.assert_(len(self.client._ok_message) == 1)
 
     def testNoPermission(self):
         self.assertRaises(Unauthorised, RetireAction(self.client).execute)
@@ -179,7 +186,7 @@
 class LoginTestCase(ActionTestCase):
     def setUp(self):
         ActionTestCase.setUp(self)
-        self.client.error_message = []
+        self.client._error_message = []
 
         # set the db password to 'right'
         self.client.db.user.get = lambda a,b: 'right'
@@ -196,7 +203,7 @@
                 MiniFieldStorage('__login_password', password))
 
         LoginAction(self.client).handle()
-        self.assertEqual(self.client.error_message, messages)
+        self.assertEqual(self.client._error_message, messages)
 
     def testNoUsername(self):
         self.assertLoginLeavesMessages(['Username required'])

Roundup Issue Tracker: http://roundup-tracker.org/