← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pappacena/turnip:http-auth-datatypes into turnip:master

 

Thiago F. Pappacena has proposed merging ~pappacena/turnip:http-auth-datatypes into turnip:master.

Commit message:
Fixing regression bug with missing string conversion of auth data on HTTP frontend

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~pappacena/turnip/+git/turnip/+merge/391369
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/turnip:http-auth-datatypes into turnip:master.
diff --git a/turnip/pack/http.py b/turnip/pack/http.py
index 555d78e..a441ddc 100644
--- a/turnip/pack/http.py
+++ b/turnip/pack/http.py
@@ -306,7 +306,7 @@ class BaseSmartHTTPResource(resource.Resource):
         authenticated_params = yield self.authenticateUser(request)
         for key, value in authenticated_params.items():
             encoded_key = ('turnip-authenticated-' + six.ensure_str(key))
-            params[encoded_key] = six.ensure_str(value)
+            params[encoded_key] = six.text_type(value)
         params.update(self.extra_params)
         d = defer.Deferred()
         client_factory = factory(service, path, params, content, request, d)
diff --git a/turnip/pack/tests/test_http.py b/turnip/pack/tests/test_http.py
index 3122ae6..0c743b4 100644
--- a/turnip/pack/tests/test_http.py
+++ b/turnip/pack/tests/test_http.py
@@ -57,6 +57,14 @@ class LessDummyRequest(requesthelper.DummyRequest):
         return None
 
 
+class AuthenticatedLessDummyRequest(LessDummyRequest):
+    def getUser(self):
+        return 'dummy-username'
+
+    def getPassword(self):
+        return 'dummy-password'
+
+
 def render_resource(resource, request):
     result = resource.render(request)
     if result is server.NOT_DONE_YET:
@@ -83,7 +91,15 @@ class FakeRoot(object):
         self.backend_connected = defer.Deferred()
 
     def authenticateWithPassword(self, user, password):
-        return {}
+        """Pretends to talk to Launchpad XML-RPC service to authenticate the user.
+
+        This method returns a dict with different data types to make sure
+        nothing breaks when forwarding this data across the layers.
+        """
+        return {
+            "lp-int-data": 1, "lp-text-data": "banana",
+            "lp-float-data": 1.23987, "lp-bool-data": True,
+            "lp-none-data": None, "lp-bytes-data": b"bytes"}
 
     def connectToBackend(self, client_factory):
         self.client_factory = client_factory
@@ -194,6 +210,19 @@ class TestSmartHTTPRefsResource(ErrorTestMixin, TestCase):
             self.request.value)
 
     @defer.inlineCallbacks
+    def test_good_authenticated(self):
+        self.request = AuthenticatedLessDummyRequest([b''])
+        yield self.performRequest(
+            helpers.encode_packet(b'I am git protocol data.') +
+            b'And I am raw, since we got a good packet to start with.')
+        self.assertEqual(200, self.request.responseCode)
+        self.assertEqual(
+            b'001e# service=git-upload-pack\n'
+            b'0000001bI am git protocol data.'
+            b'And I am raw, since we got a good packet to start with.',
+            self.request.value)
+
+    @defer.inlineCallbacks
     def test_good_v2_included_version_and_capabilities(self):
         self.request.requestHeaders.addRawHeader("Git-Protocol", "version=2")
         yield self.performRequest(