Merge ~cjwatson/launchpad:python-openid2 into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: ac8b30ac3de0fcfc1f69b82926f76e77083655b5
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:python-openid2
Merge into: launchpad:master
Diff against target: 342 lines (+38/-53)
15 files modified
constraints.txt (+1/-4)
lib/launchpad_loggerhead/app.py (+1/-5)
lib/launchpad_loggerhead/wsgi.py (+0/-5)
lib/lp/scripts/utilities/test.py (+0/-18)
lib/lp/services/openid/browser/openiddiscovery.py (+4/-2)
lib/lp/services/openid/extensions/macaroon.py (+6/-2)
lib/lp/services/openid/extensions/tests/test_macaroon.py (+2/-0)
lib/lp/services/openid/fetcher.py (+13/-1)
lib/lp/services/webapp/login.py (+0/-4)
lib/lp/testopenid/browser/server.py (+1/-7)
lib/lp/testopenid/interfaces/server.py (+3/-1)
lib/lp/testopenid/stories/basics.txt (+1/-1)
lib/lp/testopenid/testing/helpers.py (+3/-2)
lib/lp_sitecustomize.py (+2/-0)
setup.py (+1/-1)
Reviewer Review Type Date Requested Status
Thiago F. Pappacena (community) Approve
Review via email: mp+387907@code.launchpad.net

Commit message

Upgrade to python-openid2 3.2

Description of the change

This adds Python 3 support.

Our fork is no longer needed, because as of e6d54f6311 we force the OpenID fetcher to Urllib2Fetcher in loggerhead as well as in lp.services.webapp.login, and the fork was only ever needed to fix CurlFetcher.

I've removed several patches for problems with python-openid that have been fixed in python-openid2.

Dependencies MP: https://code.launchpad.net/~cjwatson/lp-source-dependencies/+git/lp-source-dependencies/+merge/387906

To post a comment you must log in.
~cjwatson/launchpad:python-openid2 updated
ac8b30a... by Colin Watson

Upgrade to python-openid2 3.2

This adds Python 3 support.

Our fork is no longer needed, because as of e6d54f6311 we force the
OpenID fetcher to Urllib2Fetcher in loggerhead as well as in
lp.services.webapp.login, and the fork was only ever needed to fix
CurlFetcher.

I've removed several patches for problems with python-openid that have
been fixed in python-openid2.

Revision history for this message
Thiago F. Pappacena (pappacena) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/constraints.txt b/constraints.txt
index 706f7da..00eecfa 100644
--- a/constraints.txt
+++ b/constraints.txt
@@ -278,10 +278,7 @@ python-dateutil==2.8.1
278python-debian==0.1.32278python-debian==0.1.32
279python-keystoneclient==0.7.1279python-keystoneclient==0.7.1
280python-memcached==1.58280python-memcached==1.58
281# XXX: deryck 2012-08-10281python-openid2==3.2
282# See lp:~deryck/python-openid/python-openid-fix1034376 which
283# reapplied a patch from wgrant to get codehosting going again.
284python-openid==2.2.5-fix1034376
285python-swiftclient==2.0.3282python-swiftclient==2.0.3
286PyYAML==3.10283PyYAML==3.10
287rabbitfixture==0.4.2284rabbitfixture==0.4.2
diff --git a/lib/launchpad_loggerhead/app.py b/lib/launchpad_loggerhead/app.py
index a671d73..d6a653b 100644
--- a/lib/launchpad_loggerhead/app.py
+++ b/lib/launchpad_loggerhead/app.py
@@ -53,7 +53,6 @@ from lp.code.interfaces.codehosting import (
53from lp.codehosting.vfs import get_lp_server53from lp.codehosting.vfs import get_lp_server
54from lp.services.config import config54from lp.services.config import config
55from lp.services.webapp.errorlog import ErrorReportingUtility55from lp.services.webapp.errorlog import ErrorReportingUtility
56from lp.services.webapp.openid import set_default_openid_fetcher
57from lp.services.webapp.vhosts import allvhosts56from lp.services.webapp.vhosts import allvhosts
58from lp.xmlrpc import faults57from lp.xmlrpc import faults
5958
@@ -69,9 +68,6 @@ robots_app = DataApp(robots_txt, content_type='text/plain')
69thread_locals = threading.local()68thread_locals = threading.local()
7069
7170
72set_default_openid_fetcher()
73
74
75def check_fault(fault, *fault_classes):71def check_fault(fault, *fault_classes):
76 """Check if 'fault's faultCode matches any of 'fault_classes'.72 """Check if 'fault's faultCode matches any of 'fault_classes'.
7773
@@ -124,7 +120,7 @@ class RootApp:
124 openid_request = self._make_consumer(environ).begin(120 openid_request = self._make_consumer(environ).begin(
125 config.launchpad.openid_provider_root)121 config.launchpad.openid_provider_root)
126 openid_request.addExtension(122 openid_request.addExtension(
127 SRegRequest(required=['nickname']))123 SRegRequest(required=[u'nickname']))
128 back_to = construct_url(environ)124 back_to = construct_url(environ)
129 raise HTTPMovedPermanently(openid_request.redirectURL(125 raise HTTPMovedPermanently(openid_request.redirectURL(
130 config.codehosting.secure_codebrowse_root,126 config.codehosting.secure_codebrowse_root,
diff --git a/lib/launchpad_loggerhead/wsgi.py b/lib/launchpad_loggerhead/wsgi.py
index 6002448..be5601b 100644
--- a/lib/launchpad_loggerhead/wsgi.py
+++ b/lib/launchpad_loggerhead/wsgi.py
@@ -19,7 +19,6 @@ import traceback
1919
20from gunicorn.app.base import Application20from gunicorn.app.base import Application
21from gunicorn.glogging import Logger21from gunicorn.glogging import Logger
22from openid import oidutil
23from paste.deploy.config import PrefixMiddleware22from paste.deploy.config import PrefixMiddleware
24from paste.httpexceptions import HTTPExceptionHandler23from paste.httpexceptions import HTTPExceptionHandler
25from paste.request import construct_url24from paste.request import construct_url
@@ -89,10 +88,6 @@ class LoggerheadLogger(Logger):
89 ['-q', '--ms', '--log-file=DEBUG:%s' % cfg.errorlog])88 ['-q', '--ms', '--log-file=DEBUG:%s' % cfg.errorlog])
90 logger(log_options)89 logger(log_options)
9190
92 # Make the OpenID library use proper logging rather than writing to
93 # stderr.
94 oidutil.log = lambda message, level=0: log.debug(message)
95
9691
97def _on_starting_hook(arbiter):92def _on_starting_hook(arbiter):
98 # Normally lp.services.pidfile.make_pidfile does this, but in this case93 # Normally lp.services.pidfile.make_pidfile does this, but in this case
diff --git a/lib/lp/scripts/utilities/test.py b/lib/lp/scripts/utilities/test.py
index 208c764..167d5c4 100755
--- a/lib/lp/scripts/utilities/test.py
+++ b/lib/lp/scripts/utilities/test.py
@@ -106,24 +106,6 @@ def filter_warnings():
106 warnings.filterwarnings(106 warnings.filterwarnings(
107 'ignore', 'bzrlib.*was deprecated', DeprecationWarning,107 'ignore', 'bzrlib.*was deprecated', DeprecationWarning,
108 )108 )
109 # The next one is caused by an infelicity in python-openid. The
110 # following change to openid/server/server.py would make the warning
111 # filter unnecessary:
112 # 978c974,974
113 # > try:
114 # > namespace = request.message.getOpenIDNamespace()
115 # > except AttributeError:
116 # > namespace = request.namespace
117 # > self.fields = Message(namespace)
118 # ---
119 # < self.fields = Message(request.namespace)
120 warnings.filterwarnings(
121 'ignore',
122 (r'The \"namespace\" attribute of CheckIDRequest objects is '
123 r'deprecated.\s+'
124 r'Use \"message.getOpenIDNamespace\(\)\" instead'),
125 DeprecationWarning
126 )
127 # XXX cjwatson 2019-10-18: This can be dropped once the port to Breezy109 # XXX cjwatson 2019-10-18: This can be dropped once the port to Breezy
128 # is complete.110 # is complete.
129 warnings.filterwarnings(111 warnings.filterwarnings(
diff --git a/lib/lp/services/openid/browser/openiddiscovery.py b/lib/lp/services/openid/browser/openiddiscovery.py
index 260f57c..2fe7023 100644
--- a/lib/lp/services/openid/browser/openiddiscovery.py
+++ b/lib/lp/services/openid/browser/openiddiscovery.py
@@ -13,6 +13,7 @@ from openid.yadis.constants import (
13 YADIS_CONTENT_TYPE,13 YADIS_CONTENT_TYPE,
14 YADIS_HEADER_NAME,14 YADIS_HEADER_NAME,
15 )15 )
16import six
1617
17from lp.services.openid.adapters.openid import CurrentOpenIDEndPoint18from lp.services.openid.adapters.openid import CurrentOpenIDEndPoint
18from lp.services.propertycache import cachedproperty19from lp.services.propertycache import cachedproperty
@@ -55,9 +56,10 @@ class XRDSContentNegotiationMixin:
55 # the value of the "Accept" header.56 # the value of the "Accept" header.
56 self.request.response.setHeader('Vary', 'Accept')57 self.request.response.setHeader('Vary', 'Accept')
5758
58 accept_content = self.request.get('HTTP_ACCEPT', '')59 accept_content = six.ensure_text(
60 self.request.get('HTTP_ACCEPT', ''), encoding='ISO-8859-1')
59 acceptable = getAcceptable(accept_content,61 acceptable = getAcceptable(accept_content,
60 ['text/html', YADIS_CONTENT_TYPE])62 [u'text/html', YADIS_CONTENT_TYPE])
61 # Return the XRDS document if it is preferred to text/html.63 # Return the XRDS document if it is preferred to text/html.
62 for mtype in acceptable:64 for mtype in acceptable:
63 if mtype == 'text/html':65 if mtype == 'text/html':
diff --git a/lib/lp/services/openid/extensions/macaroon.py b/lib/lp/services/openid/extensions/macaroon.py
index 30e1680..97a1731 100644
--- a/lib/lp/services/openid/extensions/macaroon.py
+++ b/lib/lp/services/openid/extensions/macaroon.py
@@ -39,7 +39,8 @@ __all__ = [
39 'MacaroonResponse',39 'MacaroonResponse',
40 ]40 ]
4141
42from openid import oidutil42import logging
43
43from openid.extension import Extension44from openid.extension import Extension
44from openid.message import (45from openid.message import (
45 NamespaceAliasRegistrationError,46 NamespaceAliasRegistrationError,
@@ -50,10 +51,13 @@ from openid.message import (
50MACAROON_NS = 'http://ns.login.ubuntu.com/2016/openid-macaroon'51MACAROON_NS = 'http://ns.login.ubuntu.com/2016/openid-macaroon'
5152
5253
54logger = logging.getLogger(__name__)
55
56
53try:57try:
54 registerNamespaceAlias(MACAROON_NS, 'macaroon')58 registerNamespaceAlias(MACAROON_NS, 'macaroon')
55except NamespaceAliasRegistrationError as e:59except NamespaceAliasRegistrationError as e:
56 oidutil.log(60 logger.exception(
57 'registerNamespaceAlias(%r, %r) failed: %s' % (61 'registerNamespaceAlias(%r, %r) failed: %s' % (
58 MACAROON_NS, 'macaroon', e))62 MACAROON_NS, 'macaroon', e))
5963
diff --git a/lib/lp/services/openid/extensions/tests/test_macaroon.py b/lib/lp/services/openid/extensions/tests/test_macaroon.py
index bcbc8a8..c87f6cc 100644
--- a/lib/lp/services/openid/extensions/tests/test_macaroon.py
+++ b/lib/lp/services/openid/extensions/tests/test_macaroon.py
@@ -1,6 +1,8 @@
1# Copyright 2016 Canonical Ltd. This software is licensed under the1# Copyright 2016 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4from __future__ import absolute_import, print_function, unicode_literals
5
4__metaclass__ = type6__metaclass__ = type
57
6from openid.consumer.consumer import SuccessResponse8from openid.consumer.consumer import SuccessResponse
diff --git a/lib/lp/services/webapp/openid.py b/lib/lp/services/openid/fetcher.py
7similarity index 84%9similarity index 84%
8rename from lib/lp/services/webapp/openid.py10rename from lib/lp/services/webapp/openid.py
9rename to lib/lp/services/openid/fetcher.py11rename to lib/lp/services/openid/fetcher.py
index 5e3f34e..3575124 100644
--- a/lib/lp/services/webapp/openid.py
+++ b/lib/lp/services/openid/fetcher.py
@@ -21,12 +21,24 @@ from openid.fetchers import (
21from six.moves.urllib.request import urlopen21from six.moves.urllib.request import urlopen
2222
23from lp.services.config import config23from lp.services.config import config
24from lp.services.encoding import wsgi_native_string
25
26
27class WSGIFriendlyUrllib2Fetcher(Urllib2Fetcher):
28
29 def fetch(self, url, body=None, headers=None):
30 if headers is not None:
31 headers = {
32 wsgi_native_string(key): wsgi_native_string(value)
33 for key, value in headers.items()}
34 return super(WSGIFriendlyUrllib2Fetcher, self).fetch(
35 url, body=body, headers=headers)
2436
2537
26def set_default_openid_fetcher():38def set_default_openid_fetcher():
27 # Make sure we're using the same fetcher that we use in production, even39 # Make sure we're using the same fetcher that we use in production, even
28 # if pycurl is installed.40 # if pycurl is installed.
29 fetcher = Urllib2Fetcher()41 fetcher = WSGIFriendlyUrllib2Fetcher()
30 if config.launchpad.enable_test_openid_provider:42 if config.launchpad.enable_test_openid_provider:
31 # Tests have an instance name that looks like 'testrunner-appserver'43 # Tests have an instance name that looks like 'testrunner-appserver'
32 # or similar. We're in 'development' there, so just use that config.44 # or similar. We're in 'development' there, so just use that config.
diff --git a/lib/lp/services/webapp/login.py b/lib/lp/services/webapp/login.py
index fdbd079..5367047 100644
--- a/lib/lp/services/webapp/login.py
+++ b/lib/lp/services/webapp/login.py
@@ -66,7 +66,6 @@ from lp.services.webapp.interfaces import (
66 IPlacelessLoginSource,66 IPlacelessLoginSource,
67 LoggedOutEvent,67 LoggedOutEvent,
68 )68 )
69from lp.services.webapp.openid import set_default_openid_fetcher
70from lp.services.webapp.publisher import LaunchpadView69from lp.services.webapp.publisher import LaunchpadView
71from lp.services.webapp.url import urlappend70from lp.services.webapp.url import urlappend
72from lp.services.webapp.vhosts import allvhosts71from lp.services.webapp.vhosts import allvhosts
@@ -160,9 +159,6 @@ def register_basiclogin(event):
160 name='+basiclogin')159 name='+basiclogin')
161160
162161
163set_default_openid_fetcher()
164
165
166class OpenIDLogin(LaunchpadView):162class OpenIDLogin(LaunchpadView):
167 """A view which initiates the OpenID handshake with our provider."""163 """A view which initiates the OpenID handshake with our provider."""
168 _openid_session_ns = 'OPENID'164 _openid_session_ns = 'OPENID'
diff --git a/lib/lp/testopenid/browser/server.py b/lib/lp/testopenid/browser/server.py
index c3d540a..f2ce757 100644
--- a/lib/lp/testopenid/browser/server.py
+++ b/lib/lp/testopenid/browser/server.py
@@ -15,7 +15,6 @@ __all__ = [
1515
16from datetime import timedelta16from datetime import timedelta
1717
18from openid import oidutil
19from openid.extensions.sreg import (18from openid.extensions.sreg import (
20 SRegRequest,19 SRegRequest,
21 SRegResponse,20 SRegResponse,
@@ -78,10 +77,6 @@ SESSION_PKG_KEY = 'TestOpenID'
78openid_store = MemoryStore()77openid_store = MemoryStore()
7978
8079
81# Shut up noisy OpenID library
82oidutil.log = lambda message, level=0: None
83
84
85@implementer(ICanonicalUrlData)80@implementer(ICanonicalUrlData)
86class TestOpenIDRootUrlData:81class TestOpenIDRootUrlData:
87 """`ICanonicalUrlData` for the test OpenID provider."""82 """`ICanonicalUrlData` for the test OpenID provider."""
@@ -151,8 +146,7 @@ class OpenIDMixin:
151 query = {}146 query = {}
152 for key, value in self.request.form.items():147 for key, value in self.request.form.items():
153 if key.startswith('openid.'):148 if key.startswith('openid.'):
154 # All OpenID query args are supposed to be ASCII.149 query[key] = value
155 query[key.encode('US-ASCII')] = value.encode('US-ASCII')
156 return query150 return query
157151
158 def getSession(self):152 def getSession(self):
diff --git a/lib/lp/testopenid/interfaces/server.py b/lib/lp/testopenid/interfaces/server.py
index 434fee3..669476f 100644
--- a/lib/lp/testopenid/interfaces/server.py
+++ b/lib/lp/testopenid/interfaces/server.py
@@ -9,6 +9,7 @@ __all__ = [
9 'ITestOpenIDPersistentIdentity',9 'ITestOpenIDPersistentIdentity',
10 ]10 ]
1111
12import six
12from zope.interface import Interface13from zope.interface import Interface
13from zope.schema import TextLine14from zope.schema import TextLine
1415
@@ -36,4 +37,5 @@ def get_server_url():
36 This is wrapped in a function (instead of a constant) to make sure the37 This is wrapped in a function (instead of a constant) to make sure the
37 vhost.testopenid section is not required in production configs.38 vhost.testopenid section is not required in production configs.
38 """39 """
39 return urlappend(allvhosts.configs['testopenid'].rooturl, '+openid')40 return six.ensure_text(
41 urlappend(allvhosts.configs['testopenid'].rooturl, '+openid'))
diff --git a/lib/lp/testopenid/stories/basics.txt b/lib/lp/testopenid/stories/basics.txt
index 56c6f4e..6672e40 100644
--- a/lib/lp/testopenid/stories/basics.txt
+++ b/lib/lp/testopenid/stories/basics.txt
@@ -37,7 +37,7 @@ POST request.
37 >>> print anon_browser.headers37 >>> print anon_browser.headers
38 Status: 200 Ok38 Status: 200 Ok
39 ...39 ...
40 Content-Type: text/plain40 Content-Type: text/plain;charset=utf-8
41 ...41 ...
42 >>> print anon_browser.contents42 >>> print anon_browser.contents
43 assoc_handle:{HMAC-SHA1}{...}{...}43 assoc_handle:{HMAC-SHA1}{...}{...}
diff --git a/lib/lp/testopenid/testing/helpers.py b/lib/lp/testopenid/testing/helpers.py
index 27f9855..99cd52d 100644
--- a/lib/lp/testopenid/testing/helpers.py
+++ b/lib/lp/testopenid/testing/helpers.py
@@ -21,6 +21,7 @@ from openid.consumer.discover import (
21from six.moves.urllib.error import HTTPError21from six.moves.urllib.error import HTTPError
22from zope.testbrowser.wsgi import Browser22from zope.testbrowser.wsgi import Browser
2323
24from lp.services.encoding import wsgi_native_string
24from lp.services.webapp import LaunchpadView25from lp.services.webapp import LaunchpadView
25from lp.testopenid.interfaces.server import get_server_url26from lp.testopenid.interfaces.server import get_server_url
2627
@@ -44,8 +45,8 @@ class ZopeFetcher(fetchers.HTTPFetcher):
44 browser = Browser()45 browser = Browser()
45 if headers is not None:46 if headers is not None:
46 for key, value in headers.items():47 for key, value in headers.items():
47 browser.addHeader(key, value)48 browser.addHeader(key, wsgi_native_string(value))
48 browser.addHeader('X-Zope-Handle-Errors', 'True')49 browser.addHeader('X-Zope-Handle-Errors', wsgi_native_string('True'))
49 try:50 try:
50 browser.open(url, data=body)51 browser.open(url, data=body)
51 except HTTPError as e:52 except HTTPError as e:
diff --git a/lib/lp_sitecustomize.py b/lib/lp_sitecustomize.py
index d23cd74..26085c0 100644
--- a/lib/lp_sitecustomize.py
+++ b/lib/lp_sitecustomize.py
@@ -21,6 +21,7 @@ from lp.services.log import loglevels
21from lp.services.log.logger import LaunchpadLogger21from lp.services.log.logger import LaunchpadLogger
22from lp.services.log.mappingfilter import MappingFilter22from lp.services.log.mappingfilter import MappingFilter
23from lp.services.mime import customizeMimetypes23from lp.services.mime import customizeMimetypes
24from lp.services.openid.fetcher import set_default_openid_fetcher
2425
2526
26def add_custom_loglevels():27def add_custom_loglevels():
@@ -178,6 +179,7 @@ def main(instance_name=None):
178 customizeMimetypes()179 customizeMimetypes()
179 silence_warnings()180 silence_warnings()
180 customize_logger()181 customize_logger()
182 set_default_openid_fetcher()
181 checker.BasicTypes.update({defaultdict: checker.NoProxy})183 checker.BasicTypes.update({defaultdict: checker.NoProxy})
182 checker.BasicTypes.update({Deferred: checker.NoProxy})184 checker.BasicTypes.update({Deferred: checker.NoProxy})
183 checker.BasicTypes.update({DeferredList: checker.NoProxy})185 checker.BasicTypes.update({DeferredList: checker.NoProxy})
diff --git a/setup.py b/setup.py
index b724650..db7963e 100644
--- a/setup.py
+++ b/setup.py
@@ -216,7 +216,7 @@ setup(
216 'python-keystoneclient',216 'python-keystoneclient',
217 'python-memcached',217 'python-memcached',
218 'python-mimeparse',218 'python-mimeparse',
219 'python-openid',219 'python-openid2',
220 'python-subunit',220 'python-subunit',
221 'python-swiftclient',221 'python-swiftclient',
222 'pytz',222 'pytz',

Subscribers

People subscribed via source and target branches

to status/vote changes: