← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/code-xmlrpc-openid into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/code-xmlrpc-openid into lp:launchpad.

Commit message:
Accept OpenID identifiers in run_with_login.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/code-xmlrpc-openid/+merge/255506

Accept OpenID identifiers in run_with_login.  This is more sensible than passing a (mutable) name, and will make it easier to implement OpenID authentication for cgit.  I've done this in the common run_with_login helper since that would make it possible to shift loggerhead over to this form as well in the future.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/code-xmlrpc-openid into lp:launchpad.
=== modified file 'lib/lp/code/xmlrpc/codehosting.py'
--- lib/lp/code/xmlrpc/codehosting.py	2015-03-03 01:48:18 +0000
+++ lib/lp/code/xmlrpc/codehosting.py	2015-04-08 13:09:29 +0000
@@ -110,7 +110,9 @@
         # and expect `function` to use `removeSecurityProxy` or similar.
         return function(login_id, *args, **kwargs)
     if isinstance(login_id, basestring):
-        requester = getUtility(IPersonSet).getByName(login_id)
+        requester = getUtility(IPersonSet).getByOpenIDIdentifier(login_id)
+        if requester is None:
+            requester = getUtility(IPersonSet).getByName(login_id)
     else:
         requester = getUtility(IPersonSet).get(login_id)
     if requester is None:

=== modified file 'lib/lp/code/xmlrpc/tests/test_codehosting.py'
--- lib/lp/code/xmlrpc/tests/test_codehosting.py	2012-12-10 13:43:47 +0000
+++ lib/lp/code/xmlrpc/tests/test_codehosting.py	2015-04-08 13:09:29 +0000
@@ -52,6 +52,7 @@
     ANONYMOUS,
     login,
     logout,
+    person_logged_in,
     TestCaseWithFactory,
     )
 from lp.testing.factory import LaunchpadObjectFactory
@@ -103,6 +104,18 @@
         self.assertEqual(self.person.name, username)
         logout()
 
+    def test_loginAsRequesterOpenID(self):
+        # run_with_login can take an OpenID identifier.
+        with person_logged_in(self.person):
+            identifier = (
+                self.person.account.openid_identifiers.one().identifier)
+        username = run_with_login(
+            u'http://testopenid.dev/+id/%s' % identifier,
+            get_logged_in_username)
+        login(ANONYMOUS)
+        self.assertEqual(self.person.name, username)
+        logout()
+
     def test_logoutAtEnd(self):
         # run_with_login logs out once the decorated method is
         # finished.


Follow ups