Merge ~cjwatson/launchpad:testopenid-file-store into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 6e53d62261ddd24e7f0b8d6c394f00c16ea87410
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:testopenid-file-store
Merge into: launchpad:master
Diff against target: 74 lines (+17/-3)
3 files modified
configs/development/launchpad-lazr.conf (+1/-0)
lib/lp/services/config/schema-lazr.conf (+4/-0)
lib/lp/testopenid/browser/server.py (+12/-3)
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+399125@code.launchpad.net

Commit message

testopenid: Use a filesystem-based store

Description of the change

Now that we normally use gunicorn for development setups, there are multiple worker processes serving requests, and they won't have access to the same MemoryStore instance for testopenid requests; this can cause OpenID exchanges to fail depending on which workers serve the relevant requests. Use a filesystem-based store instead so that live nonces and associations can be shared between processes.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)
Revision history for this message
Colin Watson (cjwatson) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/configs/development/launchpad-lazr.conf b/configs/development/launchpad-lazr.conf
2index 5c0f74a..4f34d76 100644
3--- a/configs/development/launchpad-lazr.conf
4+++ b/configs/development/launchpad-lazr.conf
5@@ -93,6 +93,7 @@ public_https: False
6 devmode: true
7 use_gunicorn: true
8 enable_test_openid_provider: True
9+test_openid_provider_store: /var/tmp/testopenid
10 openid_canonical_root: https://testopenid.test/
11 openid_provider_root: https://testopenid.test/
12 ca_certificates_path: /etc/ssl/certs/ca-certificates.crt
13diff --git a/lib/lp/services/config/schema-lazr.conf b/lib/lp/services/config/schema-lazr.conf
14index 7b35f3a..fe28a8c 100644
15--- a/lib/lp/services/config/schema-lazr.conf
16+++ b/lib/lp/services/config/schema-lazr.conf
17@@ -868,6 +868,10 @@ dbuser: launchpad_main
18 # datatype: boolean
19 enable_test_openid_provider: False
20
21+# Directory to use as a store for the test OpenID provider.
22+# datatype: string
23+test_openid_provider_store:
24+
25 # The password to accept for all users for HTTP basic auth.
26 # If None, HTTP basic auth is disabled
27 # Obviously this should never be set in anything even vaguely
28diff --git a/lib/lp/testopenid/browser/server.py b/lib/lp/testopenid/browser/server.py
29index f2ce757..f58022c 100644
30--- a/lib/lp/testopenid/browser/server.py
31+++ b/lib/lp/testopenid/browser/server.py
32@@ -24,7 +24,7 @@ from openid.server.server import (
33 ENCODE_HTML_FORM,
34 Server,
35 )
36-from openid.store.memstore import MemoryStore
37+from openid.store.filestore import FileOpenIDStore
38 from zope.authentication.interfaces import IUnauthenticatedPrincipal
39 from zope.browserpage import ViewPageTemplateFile
40 from zope.component import getUtility
41@@ -39,6 +39,7 @@ from lp.app.browser.launchpadform import (
42 )
43 from lp.app.errors import UnexpectedFormData
44 from lp.registry.interfaces.person import IPerson
45+from lp.services.config import config
46 from lp.services.identity.interfaces.account import (
47 AccountStatus,
48 IAccountSet,
49@@ -74,7 +75,15 @@ from lp.testopenid.interfaces.server import (
50
51 OPENID_REQUEST_SESSION_KEY = 'testopenid.request'
52 SESSION_PKG_KEY = 'TestOpenID'
53-openid_store = MemoryStore()
54+openid_store = None
55+
56+
57+def get_openid_store():
58+ global openid_store
59+ if openid_store is None:
60+ openid_store = FileOpenIDStore(
61+ config.launchpad.test_openid_provider_store)
62+ return openid_store
63
64
65 @implementer(ICanonicalUrlData)
66@@ -128,7 +137,7 @@ class OpenIDMixin:
67 def __init__(self, context, request):
68 super(OpenIDMixin, self).__init__(context, request)
69 self.server_url = get_server_url()
70- self.openid_server = Server(openid_store, self.server_url)
71+ self.openid_server = Server(get_openid_store(), self.server_url)
72
73 @property
74 def user_identity_url(self):

Subscribers

People subscribed via source and target branches

to status/vote changes: