← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pelpsi/launchpad:typeerror-unmarshall-non-string-objects into launchpad:master

 

Simone Pelosi has proposed merging ~pelpsi/launchpad:typeerror-unmarshall-non-string-objects into launchpad:master.

Commit message:
Unmarshall calls `obfuscated_structure` instead of `obfuscated_email`
    
Calling `obfuscated_structure` gives more input control avoiding
TypeError exception caused by passing to `obfuscated_email` a non-string
value.
    
LP: #2033382



Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #2033382 in Launchpad itself: "TypeError when trying to access https://api.launchpad.net/devel/~ubuntu-core-service/+snap/core20/";
  https://bugs.launchpad.net/launchpad/+bug/2033382

For more details, see:
https://code.launchpad.net/~pelpsi/launchpad/+git/launchpad/+merge/450364
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pelpsi/launchpad:typeerror-unmarshall-non-string-objects into launchpad:master.
diff --git a/lib/lp/app/webservice/marshallers.py b/lib/lp/app/webservice/marshallers.py
index e7601d2..a1275b8 100644
--- a/lib/lp/app/webservice/marshallers.py
+++ b/lib/lp/app/webservice/marshallers.py
@@ -17,7 +17,7 @@ from zope.component import getMultiAdapter, getUtility
 from zope.interface.interfaces import ComponentLookupError
 from zope.schema.interfaces import IField, RequiredMissing
 
-from lp.services.utils import obfuscate_email
+from lp.services.utils import obfuscate_structure
 from lp.services.webapp.interfaces import ILaunchBag
 
 
@@ -31,7 +31,7 @@ class TextFieldMarshaller(LazrTextFieldMarshaller):
         """
 
         if value is not None and getUtility(ILaunchBag).user is None:
-            return obfuscate_email(value)
+            return obfuscate_structure(value)
         return value
 
 
diff --git a/lib/lp/app/webservice/tests/test_marshallers.py b/lib/lp/app/webservice/tests/test_marshallers.py
index 006a1bd..765f2c8 100644
--- a/lib/lp/app/webservice/tests/test_marshallers.py
+++ b/lib/lp/app/webservice/tests/test_marshallers.py
@@ -44,6 +44,16 @@ class TestTextFieldMarshaller(TestCaseWithFactory):
             result = marshaller.unmarshall(None, "foo@xxxxxxxxxxx")
         self.assertEqual("foo@xxxxxxxxxxx", result)
 
+    def test_unmarshall_obfuscated_int_value(self):
+        marshaller = TextFieldMarshaller(None, WebServiceTestRequest())
+        result = marshaller.unmarshall(None, 1)
+        self.assertEqual(1, result)
+
+    def test_unmarshall_obfuscated_dict_value(self):
+        marshaller = TextFieldMarshaller(None, WebServiceTestRequest())
+        result = marshaller.unmarshall(None, {"foo": (["a@xxxxxxxxxxx"],)})
+        self.assertEqual({"foo": [["<email address hidden>"]]}, result)
+
 
 class TestWebServiceObfuscation(TestCaseWithFactory):
     """Integration test for obfuscation marshaller.