← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wgrant/launchpad/gitfix into lp:launchpad

 

William Grant has proposed merging lp:~wgrant/launchpad/gitfix into lp:launchpad.

Commit message:
Fix GitAPI.translatePath to cope with bytestring paths, and add an instafail GitAPI.authenticateWithPassword. Git nearly works well.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~wgrant/launchpad/gitfix/+merge/254698

Fix GitAPI.translatePath to cope with bytestring paths, and add an instafail GitAPI.authenticateWithPassword. Git nearly works well.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/gitfix into lp:launchpad.
=== modified file 'lib/lp/code/interfaces/gitapi.py'
--- lib/lp/code/interfaces/gitapi.py	2015-03-16 12:12:35 +0000
+++ lib/lp/code/interfaces/gitapi.py	2015-03-31 05:57:27 +0000
@@ -60,3 +60,10 @@
         :returns: A `NotFound` fault if no repository can be found for
             'translated_path'; otherwise None.
         """
+
+    def authenticateWithPassword(username, password):
+        """Authenticate a user by username and password.
+
+        :returns: An `Unauthorized` fault, as password authentication is
+            not yet supported.
+        """

=== modified file 'lib/lp/code/xmlrpc/git.py'
--- lib/lp/code/xmlrpc/git.py	2015-03-30 09:46:03 +0000
+++ lib/lp/code/xmlrpc/git.py	2015-03-31 05:57:27 +0000
@@ -234,6 +234,8 @@
         """See `IGitAPI`."""
         if requester_id is None:
             requester_id = LAUNCHPAD_ANONYMOUS
+        if isinstance(path, str):
+            path = path.decode('utf-8')
         return run_with_login(
             requester_id, self._translatePath,
             path.strip("/"), permission, can_authenticate)
@@ -246,3 +248,8 @@
                 "No repository found for '%s'." % translated_path)
         job = getUtility(IGitRefScanJobSource).create(repository)
         job.celeryRunOnCommit()
+
+    def authenticateWithPassword(self, username, password):
+        """See `IGitAPI`."""
+        # Password authentication isn't supported yet.
+        return faults.Unauthorized()

=== modified file 'lib/lp/code/xmlrpc/tests/test_git.py'
--- lib/lp/code/xmlrpc/tests/test_git.py	2015-03-30 09:46:03 +0000
+++ lib/lp/code/xmlrpc/tests/test_git.py	2015-03-31 05:57:27 +0000
@@ -442,6 +442,14 @@
         team = self.factory.makeTeam(members=[requester])
         self.assertCreates(requester, u"/~%s/+git/random" % team.name)
 
+    def test_translatePath_create_bytestring(self):
+        # ASCII strings come in as bytestrings, not Unicode strings. They
+        # work fine too.
+        requester = self.factory.makePerson()
+        project = self.factory.makeProduct()
+        path = u"/~%s/%s/+git/random" % (requester.name, project.name)
+        self.assertCreates(requester, path.encode('ascii'))
+
     def test_translatePath_anonymous_cannot_create(self):
         # Anonymous users cannot create repositories.
         project = self.factory.makeProject()
@@ -644,6 +652,11 @@
         job_source = getUtility(IGitRefScanJobSource)
         self.assertEqual([], list(job_source.iterReady()))
 
+    def test_authenticateWithPassword(self):
+        self.assertIsInstance(
+            self.git_api.authenticateWithPassword('foo', 'bar'),
+            faults.Unauthorized)
+
 
 class TestGitAPISecurity(TestGitAPIMixin, TestCaseWithFactory):
     """Slow tests for `IGitAPI`.


Follow ups