Merge lp:~fgallina/django-openid-auth/django16-compatibility into lp:~django-openid-auth/django-openid-auth/trunk

Proposed by Fabián Ezequiel Gallina
Status: Merged
Approved by: Ricardo Kirkner
Approved revision: 111
Merged at revision: 110
Proposed branch: lp:~fgallina/django-openid-auth/django16-compatibility
Merge into: lp:~django-openid-auth/django-openid-auth/trunk
Diff against target: 206 lines (+68/-9)
7 files modified
README.txt (+10/-5)
django_openid_auth/tests/__init__.py (+3/-2)
django_openid_auth/tests/helpers.py (+5/-0)
django_openid_auth/tests/test_auth.py (+3/-0)
django_openid_auth/tests/test_settings.py (+35/-0)
django_openid_auth/tests/test_views.py (+5/-1)
tox.ini (+7/-1)
To merge this branch: bzr merge lp:~fgallina/django-openid-auth/django16-compatibility
Reviewer Review Type Date Requested Status
Ricardo Kirkner Approve
Review via email: mp+216891@code.launchpad.net

Commit message

Django 1.6 compatibility

  + Added installation notes about the SESSION_SERIALIZER setting.
  + Included tox.ini section for Python 2.7 + Django 1.6.
  + New decorator override_session_serializer enforces pickle session
    serialization in tests.
  + Added test checking Django version defaults for
    SESSION_SERIALIZER.

To post a comment you must log in.
111. By Fabián Ezequiel Gallina

Add assertion to tests for clean OPENID_LAUNCHPAD_STAFF_TEAMS setting

Revision history for this message
Ricardo Kirkner (ricardokirkner) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README.txt'
2--- README.txt 2013-05-16 23:10:23 +0000
3+++ README.txt 2014-04-23 14:34:39 +0000
4@@ -8,13 +8,18 @@
5
6 == Basic Installation ==
7
8- 1. Install the Jan Rain Python OpenID library. It can be found at:
9+ 0. Install the Jan Rain Python OpenID library. It can be found at:
10
11 http://openidenabled.com/python-openid/
12
13 It can also be found in most Linux distributions packaged as
14 "python-openid". You will need version 2.2.0 or later.
15
16+ 1. If you are using Django 1.6, configure your project to use the
17+ pickle based session serializer:
18+
19+ SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
20+
21 2. Add 'django_openid_auth' to INSTALLED_APPS for your application.
22 At a minimum, you'll need the following in there:
23
24@@ -143,8 +148,8 @@
25
26 OPENID_USE_AS_ADMIN_LOGIN = True
27
28-It is worth noting that a user needs to be be marked as a "staff user" to be able to access the admin interface. A new openid user will not normally be a "staff user".
29-The easiest way to resolve this is to use traditional authentication (OPENID_USE_AS_ADMIN_LOGIN = False) to sign in as your first user with a password and authorise your
30+It is worth noting that a user needs to be be marked as a "staff user" to be able to access the admin interface. A new openid user will not normally be a "staff user".
31+The easiest way to resolve this is to use traditional authentication (OPENID_USE_AS_ADMIN_LOGIN = False) to sign in as your first user with a password and authorise your
32 openid user to be staff.
33
34 == Change Django usernames if the nickname changes on the provider ==
35@@ -162,7 +167,7 @@
36 If you must have a valid, unique nickname in order to create a user accont, add the following setting:
37
38 OPENID_STRICT_USERNAMES = True
39-
40+
41 This will cause an OpenID login attempt to fail if the provider does not return a 'nickname' (username) for the user, or if the nickname conflicts with an existing user with a different openid identiy url.
42 Without this setting, logins without a nickname will be given the username 'openiduser', and upon conflicts with existing username, an incrementing number will be appended to the username until it is unique.
43
44@@ -171,7 +176,7 @@
45 If your users should use a physical multi-factor authentication method, such as RSA tokens or YubiKey, add the following setting:
46
47 OPENID_PHYSICAL_MULTIFACTOR_REQUIRED = True
48-
49+
50 If the user's OpenID provider supports the PAPE extension and provides the Physical Multifactor authentication policy, this will
51 cause the OpenID login to fail if the user does not provide valid physical authentication to the provider.
52
53
54=== modified file 'django_openid_auth/tests/__init__.py'
55--- django_openid_auth/tests/__init__.py 2013-05-24 23:33:30 +0000
56+++ django_openid_auth/tests/__init__.py 2014-04-23 14:34:39 +0000
57@@ -28,6 +28,7 @@
58
59 import unittest
60 from test_views import *
61+from test_settings import *
62 from test_store import *
63 from test_auth import *
64 from test_admin import *
65@@ -35,8 +36,8 @@
66
67 def suite():
68 suite = unittest.TestSuite()
69- for name in ['test_auth', 'test_models', 'test_store', 'test_views',
70- 'test_admin']:
71+ for name in ['test_auth', 'test_models', 'test_settings', 'test_store',
72+ 'test_views', 'test_admin']:
73 mod = __import__('%s.%s' % (__name__, name), {}, {}, ['suite'])
74 suite.addTest(mod.suite())
75 return suite
76
77=== added file 'django_openid_auth/tests/helpers.py'
78--- django_openid_auth/tests/helpers.py 1970-01-01 00:00:00 +0000
79+++ django_openid_auth/tests/helpers.py 2014-04-23 14:34:39 +0000
80@@ -0,0 +1,5 @@
81+from django.test.utils import override_settings
82+
83+
84+override_session_serializer = override_settings(
85+ SESSION_SERIALIZER='django.contrib.sessions.serializers.PickleSerializer')
86
87=== modified file 'django_openid_auth/tests/test_auth.py'
88--- django_openid_auth/tests/test_auth.py 2013-06-21 17:48:28 +0000
89+++ django_openid_auth/tests/test_auth.py 2014-04-23 14:34:39 +0000
90@@ -39,6 +39,7 @@
91 from django_openid_auth.auth import OpenIDBackend
92 from django_openid_auth.models import UserOpenID
93 from django_openid_auth.teams import ns_uri as TEAMS_NS
94+from django_openid_auth.tests.helpers import override_session_serializer
95 from openid.consumer.consumer import SuccessResponse
96 from openid.consumer.discover import OpenIDServiceEndpoint
97 from openid.message import Message, OPENID2_NS
98@@ -47,6 +48,8 @@
99 SREG_NS = "http://openid.net/sreg/1.0"
100 AX_NS = "http://openid.net/srv/ax/1.0"
101
102+
103+@override_session_serializer
104 class OpenIDBackendTests(TestCase):
105
106 def setUp(self):
107
108=== added file 'django_openid_auth/tests/test_settings.py'
109--- django_openid_auth/tests/test_settings.py 1970-01-01 00:00:00 +0000
110+++ django_openid_auth/tests/test_settings.py 2014-04-23 14:34:39 +0000
111@@ -0,0 +1,35 @@
112+from unittest import skipIf, TestLoader
113+
114+from django import VERSION
115+from django.conf import settings
116+from django.test import TestCase
117+
118+
119+class SessionSerializerTest(TestCase):
120+ """Django 1.6 changed the default session serializer to use JSON
121+ instead of pickle for security reasons[0]. Unfortunately the
122+ openid module on which we rely stores objects which are not JSON
123+ serializable[1], so until this is fixed upstream (or we decide to
124+ create a wrapper serializer) we are recommending Django 1.6 users
125+ to fallback to the PickleSerializer.
126+
127+ [0] https://bit.ly/1myzetd
128+ [1] https://github.com/openid/python-openid/issues/17
129+ """
130+ @skipIf(VERSION >= (1, 6, 0), "Old versions used the pickle serializer.")
131+ def test_not_using_json_session_serializer(self):
132+ # We use getattr because this setting did not exist in Django
133+ # 1.4 (pickle serialization was hard coded)
134+ serializer = getattr(settings, 'SESSION_SERIALIZER', '')
135+ self.assertNotEqual(
136+ serializer, 'django.contrib.sessions.serializers.JSONSerializer')
137+
138+ @skipIf(VERSION < (1, 6, 0), "Newer versions use JSON by default.")
139+ def test_using_json_session_serializer(self):
140+ serializer = getattr(settings, 'SESSION_SERIALIZER', '')
141+ self.assertEqual(
142+ serializer, 'django.contrib.sessions.serializers.JSONSerializer')
143+
144+
145+def suite():
146+ return TestLoader().loadTestsFromName(__name__)
147
148=== modified file 'django_openid_auth/tests/test_views.py'
149--- django_openid_auth/tests/test_views.py 2013-06-21 17:24:18 +0000
150+++ django_openid_auth/tests/test_views.py 2014-04-23 14:34:39 +0000
151@@ -47,6 +47,7 @@
152
153 from django_openid_auth import teams
154 from django_openid_auth.models import UserOpenID
155+from django_openid_auth.tests.helpers import override_session_serializer
156 from django_openid_auth.views import (
157 sanitise_redirect_url,
158 make_consumer,
159@@ -161,6 +162,8 @@
160 return request
161 REQUEST = property(_combined_request)
162
163+
164+@override_session_serializer
165 class RelyingPartyTests(TestCase):
166 urls = 'django_openid_auth.tests.urls'
167
168@@ -1354,7 +1357,7 @@
169 self.assertTrue(group3 not in user.groups.all())
170
171 def test_login_teams_staff_not_defined(self):
172- delattr(settings, 'OPENID_LAUNCHPAD_STAFF_TEAMS')
173+ assert getattr(settings, 'OPENID_LAUNCHPAD_STAFF_TEAMS', None) is None
174 user = User.objects.create_user('testuser', 'someone@example.com')
175 user.is_staff = True
176 user.save()
177@@ -1433,6 +1436,7 @@
178 openid_login_complete.disconnect(login_callback)
179
180
181+@override_session_serializer
182 class HelperFunctionsTest(TestCase):
183 def test_sanitise_redirect_url(self):
184 settings.ALLOWED_EXTERNAL_OPENID_REDIRECT_DOMAINS = [
185
186=== modified file 'tox.ini'
187--- tox.ini 2014-04-22 19:24:28 +0000
188+++ tox.ini 2014-04-23 14:34:39 +0000
189@@ -1,6 +1,6 @@
190 [tox]
191 envlist =
192- py2.7-django1.4, py2.7-django1.5
193+ py2.7-django1.4, py2.7-django1.5, py2.7-django1.6
194
195 [testenv]
196 commands = make check
197@@ -17,3 +17,9 @@
198 deps = django >= 1.5, < 1.6
199 python-openid
200 south
201+
202+[testenv:py2.7-django1.6]
203+basepython = python2.7
204+deps = django >= 1.6, < 1.7
205+ python-openid
206+ south

Subscribers

People subscribed via source and target branches