From 0dc1ad1e9c47aa7b04b944e88b071ea1a646ae91 Mon Sep 17 00:00:00 2001 From: gengjh Date: Tue, 9 Apr 2013 22:13:31 +0800 Subject: Replace password to "***" in the debug message Use regex pattern to replace password to "***" for both env vars and request body output Fix bug 1166697 Change-Id: I671ea25cca78b4dea1fbf2e63c89b82912279f2d --- tests/test_wsgi.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests') diff --git a/tests/test_wsgi.py b/tests/test_wsgi.py index 9bc26017..87d9929d 100644 --- a/tests/test_wsgi.py +++ b/tests/test_wsgi.py @@ -38,6 +38,37 @@ class BaseWSGITest(test.TestCase): req.environ['wsgiorg.routing_args'] = [None, args] return req + def test_mask_password(self): + message = ("test = 'password': 'aaaaaa', 'param1': 'value1', " + "\"new_password\": 'bbbbbb'") + self.assertEqual(wsgi.mask_password(message, True), + u"test = 'password': '***', 'param1': 'value1', " + "\"new_password\": '***'") + + message = "test = 'password' : 'aaaaaa'" + self.assertEqual(wsgi.mask_password(message, False, '111'), + "test = 'password' : '111'") + + message = u"test = u'password' : u'aaaaaa'" + self.assertEqual(wsgi.mask_password(message, True), + u"test = u'password' : u'***'") + + message = 'test = "password" : "aaaaaaaaa"' + self.assertEqual(wsgi.mask_password(message), + 'test = "password" : "***"') + + message = 'test = "original_password" : "aaaaaaaaa"' + self.assertEqual(wsgi.mask_password(message), + 'test = "original_password" : "***"') + + message = 'test = "original_password" : ""' + self.assertEqual(wsgi.mask_password(message), + 'test = "original_password" : "***"') + + message = 'test = "param1" : "value"' + self.assertEqual(wsgi.mask_password(message), + 'test = "param1" : "value"') + class ApplicationTest(BaseWSGITest): def test_response_content_type(self): -- cgit