← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pappacena/turnip:py3-xmlrpc-avoid-binary into turnip:master

 

Thiago F. Pappacena has proposed merging ~pappacena/turnip:py3-xmlrpc-avoid-binary into turnip:master.

Commit message:
Avoid binary type when sending xml-rpc calls with string parameters/dicts

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~pappacena/turnip/+git/turnip/+merge/391078
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/turnip:py3-xmlrpc-avoid-binary into turnip:master.
diff --git a/turnip/pack/git.py b/turnip/pack/git.py
index 9be4e90..be1c956 100644
--- a/turnip/pack/git.py
+++ b/turnip/pack/git.py
@@ -222,10 +222,10 @@ class PackServerProtocol(PackProxyProtocol):
     def createAuthParams(self, params):
         auth_params = {}
         for key, value in params.items():
-            key = six.ensure_binary(key)
-            if key.startswith(b'turnip-authenticated-'):
-                decoded_key = key[len(b'turnip-authenticated-'):]
-                auth_params[decoded_key] = value
+            key = six.ensure_str(key)
+            if key.startswith('turnip-authenticated-'):
+                decoded_key = key[len('turnip-authenticated-'):]
+                auth_params[decoded_key] = six.ensure_str(value)
         if 'uid' in auth_params:
             auth_params['uid'] = int(auth_params['uid'])
         if params.get(b'turnip-can-authenticate') == b'yes':
diff --git a/turnip/pack/http.py b/turnip/pack/http.py
index 992f282..555d78e 100644
--- a/turnip/pack/http.py
+++ b/turnip/pack/http.py
@@ -305,8 +305,8 @@ class BaseSmartHTTPResource(resource.Resource):
             }
         authenticated_params = yield self.authenticateUser(request)
         for key, value in authenticated_params.items():
-            encoded_key = ('turnip-authenticated-' + key).encode('utf-8')
-            params[encoded_key] = unicode(value).encode('utf-8')
+            encoded_key = ('turnip-authenticated-' + six.ensure_str(key))
+            params[encoded_key] = six.ensure_str(value)
         params.update(self.extra_params)
         d = defer.Deferred()
         client_factory = factory(service, path, params, content, request, d)
@@ -802,7 +802,9 @@ class SmartHTTPFrontendResource(resource.Resource):
         proxy = xmlrpc.Proxy(self.virtinfo_endpoint)
         try:
             translated = yield proxy.callRemote(
-                'authenticateWithPassword', user, password)
+                'authenticateWithPassword',
+                six.ensure_str(user),
+                six.ensure_str(password))
         except xmlrpc.Fault as e:
             code = translate_xmlrpc_fault(e.faultCode)
             if code == TurnipFaultCode.UNAUTHORIZED:
diff --git a/turnip/pack/tests/test_functional.py b/turnip/pack/tests/test_functional.py
index 30124b0..820bb4d 100644
--- a/turnip/pack/tests/test_functional.py
+++ b/turnip/pack/tests/test_functional.py
@@ -797,7 +797,7 @@ class TestSmartHTTPFrontendFunctional(FrontendFunctionalTestMixin, TestCase):
             b'HEAD refs/heads/new-head')
         self.assertEqual(200, response.code)
         body = yield client.readBody(response)
-        self.assertEqual((b'ACK HEAD\n', ''), helpers.decode_packet(body))
+        self.assertEqual((b'ACK HEAD\n', b''), helpers.decode_packet(body))
         head_target = yield self.get_symbolic_ref(repo, b'HEAD')
         self.assertEqual(b'refs/heads/new-head', head_target)
         self.assertEqual(
@@ -814,7 +814,7 @@ class TestSmartHTTPFrontendFunctional(FrontendFunctionalTestMixin, TestCase):
         self.assertEqual(200, response.code)
         body = yield client.readBody(response)
         self.assertEqual(
-            (b'ERR Symbolic ref target may not start with "-"\n', ''),
+            (b'ERR Symbolic ref target may not start with "-"\n', b''),
             helpers.decode_packet(body))
         head_target = yield self.get_symbolic_ref(repo, b'HEAD')
         self.assertEqual(b'refs/heads/master', head_target)