Merge lp:~ricardokirkner/django-openid-auth/py35-support into lp:django-openid-auth
- py35-support
- Merge into trunk
Proposed by
Ricardo Kirkner
Status: | Merged |
---|---|
Approved by: | Ricardo Kirkner |
Approved revision: | 133 |
Merge reported by: | Otto Co-Pilot |
Merged at revision: | not available |
Proposed branch: | lp:~ricardokirkner/django-openid-auth/py35-support |
Merge into: | lp:django-openid-auth |
Diff against target: |
859 lines (+178/-92) 14 files modified
django_openid_auth/__init__.py (+3/-0) django_openid_auth/admin.py (+8/-2) django_openid_auth/auth.py (+2/-1) django_openid_auth/forms.py (+10/-2) django_openid_auth/store.py (+9/-3) django_openid_auth/teams.py (+4/-3) django_openid_auth/tests/test_auth.py (+6/-4) django_openid_auth/tests/test_store.py (+6/-3) django_openid_auth/tests/test_views.py (+78/-50) django_openid_auth/views.py (+14/-6) example_consumer/urls.py (+1/-1) setup.cfg (+0/-2) setup.py (+12/-5) tox.ini (+25/-10) |
To merge this branch: | bzr merge lp:~ricardokirkner/django-openid-auth/py35-support |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Matias Bordese (community) | Approve | ||
Review via email: mp+321603@code.launchpad.net |
Commit message
support python 2.7 and 3.5
Description of the change
To post a comment you must log in.
Revision history for this message
Otto Co-Pilot (otto-copilot) wrote : | # |
Running landing tests failed
https:/
Revision history for this message
Otto Co-Pilot (otto-copilot) wrote : | # |
Running landing tests failed
https:/
Revision history for this message
Otto Co-Pilot (otto-copilot) wrote : | # |
Running landing tests failed
https:/
Revision history for this message
Otto Co-Pilot (otto-copilot) wrote : | # |
Running landing tests failed
https:/
Revision history for this message
Otto Co-Pilot (otto-copilot) wrote : | # |
Running landing tests failed
https:/
- 133. By Ricardo Kirkner
-
fixed typo in env name
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'django_openid_auth/__init__.py' | |||
2 | --- django_openid_auth/__init__.py 2015-04-23 20:02:39 +0000 | |||
3 | +++ django_openid_auth/__init__.py 2017-04-03 12:33:16 +0000 | |||
4 | @@ -26,3 +26,6 @@ | |||
5 | 26 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | 26 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
6 | 27 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 27 | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
7 | 28 | # POSSIBILITY OF SUCH DAMAGE. | 28 | # POSSIBILITY OF SUCH DAMAGE. |
8 | 29 | import sys | ||
9 | 30 | |||
10 | 31 | PY3 = sys.version_info.major >= 3 | ||
11 | 29 | 32 | ||
12 | === modified file 'django_openid_auth/admin.py' | |||
13 | --- django_openid_auth/admin.py 2015-09-21 14:32:58 +0000 | |||
14 | +++ django_openid_auth/admin.py 2017-04-03 12:33:16 +0000 | |||
15 | @@ -29,8 +29,11 @@ | |||
16 | 29 | 29 | ||
17 | 30 | from __future__ import unicode_literals | 30 | from __future__ import unicode_literals |
18 | 31 | 31 | ||
21 | 32 | from urllib import urlencode | 32 | try: |
22 | 33 | from urlparse import parse_qsl, urlparse | 33 | from urllib.parse import parse_qsl, urlencode, urlparse |
23 | 34 | except ImportError: | ||
24 | 35 | from urllib import urlencode | ||
25 | 36 | from urlparse import parse_qsl, urlparse | ||
26 | 34 | 37 | ||
27 | 35 | from django.conf import settings | 38 | from django.conf import settings |
28 | 36 | from django.contrib import admin | 39 | from django.contrib import admin |
29 | @@ -50,6 +53,7 @@ | |||
30 | 50 | self.message_user(request, "%d expired nonces removed" % count) | 53 | self.message_user(request, "%d expired nonces removed" % count) |
31 | 51 | cleanup_nonces.short_description = "Clean up expired nonces" | 54 | cleanup_nonces.short_description = "Clean up expired nonces" |
32 | 52 | 55 | ||
33 | 56 | |||
34 | 53 | admin.site.register(Nonce, NonceAdmin) | 57 | admin.site.register(Nonce, NonceAdmin) |
35 | 54 | 58 | ||
36 | 55 | 59 | ||
37 | @@ -65,6 +69,7 @@ | |||
38 | 65 | self.message_user(request, "%d expired associations removed" % count) | 69 | self.message_user(request, "%d expired associations removed" % count) |
39 | 66 | cleanup_associations.short_description = "Clean up expired associations" | 70 | cleanup_associations.short_description = "Clean up expired associations" |
40 | 67 | 71 | ||
41 | 72 | |||
42 | 68 | admin.site.register(Association, AssociationAdmin) | 73 | admin.site.register(Association, AssociationAdmin) |
43 | 69 | 74 | ||
44 | 70 | 75 | ||
45 | @@ -73,6 +78,7 @@ | |||
46 | 73 | list_display = ('user', 'claimed_id') | 78 | list_display = ('user', 'claimed_id') |
47 | 74 | search_fields = ('claimed_id',) | 79 | search_fields = ('claimed_id',) |
48 | 75 | 80 | ||
49 | 81 | |||
50 | 76 | admin.site.register(UserOpenID, UserOpenIDAdmin) | 82 | admin.site.register(UserOpenID, UserOpenIDAdmin) |
51 | 77 | 83 | ||
52 | 78 | 84 | ||
53 | 79 | 85 | ||
54 | === modified file 'django_openid_auth/auth.py' | |||
55 | --- django_openid_auth/auth.py 2017-01-23 14:26:49 +0000 | |||
56 | +++ django_openid_auth/auth.py 2017-04-03 12:33:16 +0000 | |||
57 | @@ -408,7 +408,8 @@ | |||
58 | 408 | teams_mapping[lp_team] for lp_team in teams_response.is_member | 408 | teams_mapping[lp_team] for lp_team in teams_response.is_member |
59 | 409 | if lp_team in teams_mapping] | 409 | if lp_team in teams_mapping] |
60 | 410 | user_groups = UserGroup.objects.filter(user=user) | 410 | user_groups = UserGroup.objects.filter(user=user) |
62 | 411 | matching_groups = user_groups.filter(group__name__in=teams_mapping.values()) | 411 | matching_groups = user_groups.filter( |
63 | 412 | group__name__in=teams_mapping.values()) | ||
64 | 412 | current_groups = set( | 413 | current_groups = set( |
65 | 413 | user_group.group for user_group in matching_groups) | 414 | user_group.group for user_group in matching_groups) |
66 | 414 | desired_groups = set(Group.objects.filter(name__in=mapping)) | 415 | desired_groups = set(Group.objects.filter(name__in=mapping)) |
67 | 415 | 416 | ||
68 | === modified file 'django_openid_auth/forms.py' | |||
69 | --- django_openid_auth/forms.py 2015-04-23 20:39:02 +0000 | |||
70 | +++ django_openid_auth/forms.py 2017-04-03 12:33:16 +0000 | |||
71 | @@ -38,6 +38,8 @@ | |||
72 | 38 | 38 | ||
73 | 39 | from openid.yadis import xri | 39 | from openid.yadis import xri |
74 | 40 | 40 | ||
75 | 41 | from django_openid_auth import PY3 | ||
76 | 42 | |||
77 | 41 | 43 | ||
78 | 42 | def teams_new_unicode(self): | 44 | def teams_new_unicode(self): |
79 | 43 | """ | 45 | """ |
80 | @@ -52,8 +54,13 @@ | |||
81 | 52 | else: | 54 | else: |
82 | 53 | return name | 55 | return name |
83 | 54 | 56 | ||
86 | 55 | Group.unicode_before_teams = Group.__unicode__ | 57 | |
87 | 56 | Group.__unicode__ = teams_new_unicode | 58 | if PY3: |
88 | 59 | Group.unicode_before_teams = Group.__str__ | ||
89 | 60 | Group.__str__ = teams_new_unicode | ||
90 | 61 | else: | ||
91 | 62 | Group.unicode_before_teams = Group.__unicode__ | ||
92 | 63 | Group.__unicode__ = teams_new_unicode | ||
93 | 57 | 64 | ||
94 | 58 | 65 | ||
95 | 59 | class UserChangeFormWithTeamRestriction(UserChangeForm): | 66 | class UserChangeFormWithTeamRestriction(UserChangeForm): |
96 | @@ -72,6 +79,7 @@ | |||
97 | 72 | "You cannot assign it manually." % group.name) | 79 | "You cannot assign it manually." % group.name) |
98 | 73 | return data | 80 | return data |
99 | 74 | 81 | ||
100 | 82 | |||
101 | 75 | UserAdmin.form = UserChangeFormWithTeamRestriction | 83 | UserAdmin.form = UserChangeFormWithTeamRestriction |
102 | 76 | 84 | ||
103 | 77 | 85 | ||
104 | 78 | 86 | ||
105 | === modified file 'django_openid_auth/store.py' | |||
106 | --- django_openid_auth/store.py 2015-04-23 20:39:02 +0000 | |||
107 | +++ django_openid_auth/store.py 2017-04-03 12:33:16 +0000 | |||
108 | @@ -36,6 +36,7 @@ | |||
109 | 36 | from openid.store.interface import OpenIDStore | 36 | from openid.store.interface import OpenIDStore |
110 | 37 | from openid.store.nonce import SKEW | 37 | from openid.store.nonce import SKEW |
111 | 38 | 38 | ||
112 | 39 | from django_openid_auth import PY3 | ||
113 | 39 | from django_openid_auth.models import Association, Nonce | 40 | from django_openid_auth.models import Association, Nonce |
114 | 40 | 41 | ||
115 | 41 | 42 | ||
116 | @@ -75,10 +76,15 @@ | |||
117 | 75 | expired = [] | 76 | expired = [] |
118 | 76 | for assoc in assocs: | 77 | for assoc in assocs: |
119 | 77 | association = OIDAssociation( | 78 | association = OIDAssociation( |
122 | 78 | assoc.handle, base64.decodestring(assoc.secret), assoc.issued, | 79 | assoc.handle, |
123 | 79 | assoc.lifetime, assoc.assoc_type | 80 | base64.decodestring(assoc.secret.encode('utf-8')), |
124 | 81 | assoc.issued, assoc.lifetime, assoc.assoc_type | ||
125 | 80 | ) | 82 | ) |
127 | 81 | if association.getExpiresIn() == 0: | 83 | if PY3: |
128 | 84 | expires_in = association.expiresIn | ||
129 | 85 | else: | ||
130 | 86 | expires_in = association.getExpiresIn() | ||
131 | 87 | if expires_in == 0: | ||
132 | 82 | expired.append(assoc) | 88 | expired.append(assoc) |
133 | 83 | else: | 89 | else: |
134 | 84 | associations.append((association.issued, association)) | 90 | associations.append((association.issued, association)) |
135 | 85 | 91 | ||
136 | === modified file 'django_openid_auth/teams.py' | |||
137 | --- django_openid_auth/teams.py 2015-04-23 20:39:02 +0000 | |||
138 | +++ django_openid_auth/teams.py 2017-04-03 12:33:16 +0000 | |||
139 | @@ -72,6 +72,7 @@ | |||
140 | 72 | registerNamespaceAlias, | 72 | registerNamespaceAlias, |
141 | 73 | NamespaceAliasRegistrationError, | 73 | NamespaceAliasRegistrationError, |
142 | 74 | ) | 74 | ) |
143 | 75 | from six import string_types | ||
144 | 75 | 76 | ||
145 | 76 | __all__ = [ | 77 | __all__ = [ |
146 | 77 | 'TeamsRequest', | 78 | 'TeamsRequest', |
147 | @@ -84,7 +85,7 @@ | |||
148 | 84 | 85 | ||
149 | 85 | try: | 86 | try: |
150 | 86 | registerNamespaceAlias(ns_uri, 'lp') | 87 | registerNamespaceAlias(ns_uri, 'lp') |
152 | 87 | except NamespaceAliasRegistrationError, e: | 88 | except NamespaceAliasRegistrationError as e: |
153 | 88 | oidutil.log( | 89 | oidutil.log( |
154 | 89 | 'registerNamespaceAlias(%r, %r) failed: %s' % (ns_uri, 'lp', str(e))) | 90 | 'registerNamespaceAlias(%r, %r) failed: %s' % (ns_uri, 'lp', str(e))) |
155 | 90 | 91 | ||
156 | @@ -139,7 +140,7 @@ | |||
157 | 139 | # There is no alias, so try to add one. (OpenID version 1) | 140 | # There is no alias, so try to add one. (OpenID version 1) |
158 | 140 | try: | 141 | try: |
159 | 141 | message.namespaces.addAlias(ns_uri, 'lp') | 142 | message.namespaces.addAlias(ns_uri, 'lp') |
161 | 142 | except KeyError, why: | 143 | except KeyError as why: |
162 | 143 | # An alias for the string 'lp' already exists, but it's | 144 | # An alias for the string 'lp' already exists, but it's |
163 | 144 | # defined for something other than Launchpad teams | 145 | # defined for something other than Launchpad teams |
164 | 145 | raise TeamsNamespaceError(why[0]) | 146 | raise TeamsNamespaceError(why[0]) |
165 | @@ -287,7 +288,7 @@ | |||
166 | 287 | @raise ValueError: when a team requested is not a string | 288 | @raise ValueError: when a team requested is not a string |
167 | 288 | or strict is set and a team was requested more than once | 289 | or strict is set and a team was requested more than once |
168 | 289 | """ | 290 | """ |
170 | 290 | if isinstance(query_membership, basestring): | 291 | if isinstance(query_membership, string_types): |
171 | 291 | raise TypeError('Teams should be passed as a list of ' | 292 | raise TypeError('Teams should be passed as a list of ' |
172 | 292 | 'strings (not %r)' % (type(query_membership),)) | 293 | 'strings (not %r)' % (type(query_membership),)) |
173 | 293 | 294 | ||
174 | 294 | 295 | ||
175 | === modified file 'django_openid_auth/tests/test_auth.py' | |||
176 | --- django_openid_auth/tests/test_auth.py 2017-01-20 14:28:12 +0000 | |||
177 | +++ django_openid_auth/tests/test_auth.py 2017-04-03 12:33:16 +0000 | |||
178 | @@ -29,15 +29,16 @@ | |||
179 | 29 | from __future__ import unicode_literals | 29 | from __future__ import unicode_literals |
180 | 30 | 30 | ||
181 | 31 | import re | 31 | import re |
183 | 32 | from urlparse import urljoin | 32 | try: |
184 | 33 | from urllib.parse import urljoin | ||
185 | 34 | except ImportError: | ||
186 | 35 | from urlparse import urljoin | ||
187 | 33 | 36 | ||
188 | 34 | from django.conf import settings | 37 | from django.conf import settings |
189 | 35 | from django.contrib.auth.models import Group, Permission, User | 38 | from django.contrib.auth.models import Group, Permission, User |
190 | 36 | from django.core.exceptions import ImproperlyConfigured | 39 | from django.core.exceptions import ImproperlyConfigured |
191 | 37 | from django.db import models | ||
192 | 38 | from django.test import TestCase | 40 | from django.test import TestCase |
193 | 39 | from django.test.utils import override_settings | 41 | from django.test.utils import override_settings |
194 | 40 | from mock import patch | ||
195 | 41 | from openid.consumer.consumer import ( | 42 | from openid.consumer.consumer import ( |
196 | 42 | CancelResponse, | 43 | CancelResponse, |
197 | 43 | FailureResponse, | 44 | FailureResponse, |
198 | @@ -160,7 +161,8 @@ | |||
199 | 160 | perm_label = '%s.%s' % (permission.content_type.app_label, | 161 | perm_label = '%s.%s' % (permission.content_type.app_label, |
200 | 161 | permission.codename) | 162 | permission.codename) |
201 | 162 | # Always invalidate the per-request perm cache | 163 | # Always invalidate the per-request perm cache |
203 | 163 | for attr in user.__dict__.keys(): | 164 | attrs = list(user.__dict__.keys()) |
204 | 165 | for attr in attrs: | ||
205 | 164 | if attr.endswith('_perm_cache'): | 166 | if attr.endswith('_perm_cache'): |
206 | 165 | delattr(user, attr) | 167 | delattr(user, attr) |
207 | 166 | 168 | ||
208 | 167 | 169 | ||
209 | === modified file 'django_openid_auth/tests/test_store.py' | |||
210 | --- django_openid_auth/tests/test_store.py 2015-04-23 20:39:02 +0000 | |||
211 | +++ django_openid_auth/tests/test_store.py 2017-04-03 12:33:16 +0000 | |||
212 | @@ -28,6 +28,7 @@ | |||
213 | 28 | 28 | ||
214 | 29 | from __future__ import unicode_literals | 29 | from __future__ import unicode_literals |
215 | 30 | 30 | ||
216 | 31 | import base64 | ||
217 | 31 | import time | 32 | import time |
218 | 32 | 33 | ||
219 | 33 | from django.test import TestCase | 34 | from django.test import TestCase |
220 | @@ -52,7 +53,8 @@ | |||
221 | 52 | server_url='server-url', handle='handle') | 53 | server_url='server-url', handle='handle') |
222 | 53 | self.assertEquals(dbassoc.server_url, 'server-url') | 54 | self.assertEquals(dbassoc.server_url, 'server-url') |
223 | 54 | self.assertEquals(dbassoc.handle, 'handle') | 55 | self.assertEquals(dbassoc.handle, 'handle') |
225 | 55 | self.assertEquals(dbassoc.secret, 'secret'.encode('base-64')) | 56 | self.assertEquals( |
226 | 57 | dbassoc.secret, base64.encodestring(b'secret').decode('utf-8')) | ||
227 | 56 | self.assertEquals(dbassoc.issued, 42) | 58 | self.assertEquals(dbassoc.issued, 42) |
228 | 57 | self.assertEquals(dbassoc.lifetime, 600) | 59 | self.assertEquals(dbassoc.lifetime, 600) |
229 | 58 | self.assertEquals(dbassoc.assoc_type, 'HMAC-SHA1') | 60 | self.assertEquals(dbassoc.assoc_type, 'HMAC-SHA1') |
230 | @@ -66,7 +68,8 @@ | |||
231 | 66 | self.store.storeAssociation('server-url', assoc) | 68 | self.store.storeAssociation('server-url', assoc) |
232 | 67 | dbassoc = Association.objects.get( | 69 | dbassoc = Association.objects.get( |
233 | 68 | server_url='server-url', handle='handle') | 70 | server_url='server-url', handle='handle') |
235 | 69 | self.assertEqual(dbassoc.secret, 'secret2'.encode('base-64')) | 71 | self.assertEqual( |
236 | 72 | dbassoc.secret, base64.encodestring(b'secret2').decode('utf-8')) | ||
237 | 70 | self.assertEqual(dbassoc.issued, 420) | 73 | self.assertEqual(dbassoc.issued, 420) |
238 | 71 | self.assertEqual(dbassoc.lifetime, 900) | 74 | self.assertEqual(dbassoc.lifetime, 900) |
239 | 72 | self.assertEqual(dbassoc.assoc_type, 'HMAC-SHA256') | 75 | self.assertEqual(dbassoc.assoc_type, 'HMAC-SHA256') |
240 | @@ -80,7 +83,7 @@ | |||
241 | 80 | self.assertTrue(isinstance(assoc, OIDAssociation)) | 83 | self.assertTrue(isinstance(assoc, OIDAssociation)) |
242 | 81 | 84 | ||
243 | 82 | self.assertEquals(assoc.handle, 'handle') | 85 | self.assertEquals(assoc.handle, 'handle') |
245 | 83 | self.assertEquals(assoc.secret, 'secret') | 86 | self.assertEquals(assoc.secret, b'secret') |
246 | 84 | self.assertEquals(assoc.issued, timestamp) | 87 | self.assertEquals(assoc.issued, timestamp) |
247 | 85 | self.assertEquals(assoc.lifetime, 600) | 88 | self.assertEquals(assoc.lifetime, 600) |
248 | 86 | self.assertEquals(assoc.assoc_type, 'HMAC-SHA1') | 89 | self.assertEquals(assoc.assoc_type, 'HMAC-SHA1') |
249 | 87 | 90 | ||
250 | === modified file 'django_openid_auth/tests/test_views.py' | |||
251 | --- django_openid_auth/tests/test_views.py 2017-01-16 15:05:26 +0000 | |||
252 | +++ django_openid_auth/tests/test_views.py 2017-04-03 12:33:16 +0000 | |||
253 | @@ -31,7 +31,10 @@ | |||
254 | 31 | 31 | ||
255 | 32 | import cgi | 32 | import cgi |
256 | 33 | 33 | ||
258 | 34 | from urlparse import parse_qs | 34 | try: |
259 | 35 | from urllib.parse import parse_qs | ||
260 | 36 | except ImportError: | ||
261 | 37 | from urlparse import parse_qs | ||
262 | 35 | 38 | ||
263 | 36 | from django.conf import settings | 39 | from django.conf import settings |
264 | 37 | from django.contrib.auth.models import User, Group, Permission | 40 | from django.contrib.auth.models import User, Group, Permission |
265 | @@ -125,8 +128,8 @@ | |||
266 | 125 | def parseFormPost(self, content): | 128 | def parseFormPost(self, content): |
267 | 126 | """Parse an HTML form post to create an OpenID request.""" | 129 | """Parse an HTML form post to create an OpenID request.""" |
268 | 127 | # Hack to make the javascript XML compliant ... | 130 | # Hack to make the javascript XML compliant ... |
271 | 128 | content = content.replace('i < elements.length', | 131 | content = content.replace( |
272 | 129 | 'i < elements.length') | 132 | 'i < elements.length', 'i < elements.length') |
273 | 130 | tree = ET.XML(content) | 133 | tree = ET.XML(content) |
274 | 131 | form = tree.find('.//form') | 134 | form = tree.find('.//form') |
275 | 132 | assert form is not None, 'No form in document' | 135 | assert form is not None, 'No form in document' |
276 | @@ -137,8 +140,7 @@ | |||
277 | 137 | for input in form.findall('input'): | 140 | for input in form.findall('input'): |
278 | 138 | if input.get('type') != 'hidden': | 141 | if input.get('type') != 'hidden': |
279 | 139 | continue | 142 | continue |
282 | 140 | query[input.get('name').encode('UTF-8')] = \ | 143 | query[input.get('name')] = input.get('value') |
281 | 141 | input.get('value').encode('UTF-8') | ||
283 | 142 | self.last_request = self.server.decodeRequest(query) | 144 | self.last_request = self.server.decodeRequest(query) |
284 | 143 | return self.last_request | 145 | return self.last_request |
285 | 144 | 146 | ||
286 | @@ -236,7 +238,8 @@ | |||
287 | 236 | response = self.client.post(self.login_url, self.openid_req) | 238 | response = self.client.post(self.login_url, self.openid_req) |
288 | 237 | self.assertContains(response, 'OpenID transaction in progress') | 239 | self.assertContains(response, 'OpenID transaction in progress') |
289 | 238 | 240 | ||
291 | 239 | openid_request = self.provider.parseFormPost(response.content) | 241 | openid_request = self.provider.parseFormPost( |
292 | 242 | response.content.decode('utf-8')) | ||
293 | 240 | self.assertEqual(openid_request.mode, 'checkid_setup') | 243 | self.assertEqual(openid_request.mode, 'checkid_setup') |
294 | 241 | self.assertTrue(openid_request.return_to.startswith( | 244 | self.assertTrue(openid_request.return_to.startswith( |
295 | 242 | 'http://testserver/openid/complete/')) | 245 | 'http://testserver/openid/complete/')) |
296 | @@ -248,7 +251,7 @@ | |||
297 | 248 | 251 | ||
298 | 249 | # And they are now logged in: | 252 | # And they are now logged in: |
299 | 250 | response = self.client.get('/getuser/') | 253 | response = self.client.get('/getuser/') |
301 | 251 | self.assertEqual(response.content, 'someuser') | 254 | self.assertEqual(response.content.decode('utf-8'), 'someuser') |
302 | 252 | 255 | ||
303 | 253 | def test_login_with_nonascii_return_to(self): | 256 | def test_login_with_nonascii_return_to(self): |
304 | 254 | """Ensure non-ascii characters can be used for the 'next' arg.""" | 257 | """Ensure non-ascii characters can be used for the 'next' arg.""" |
305 | @@ -270,7 +273,8 @@ | |||
306 | 270 | 273 | ||
307 | 271 | self.assertContains(response, 'OpenID transaction in progress') | 274 | self.assertContains(response, 'OpenID transaction in progress') |
308 | 272 | 275 | ||
310 | 273 | openid_request = self.provider.parseFormPost(response.content) | 276 | openid_request = self.provider.parseFormPost( |
311 | 277 | response.content.decode('utf-8')) | ||
312 | 274 | self.assertEqual(openid_request.mode, 'checkid_setup') | 278 | self.assertEqual(openid_request.mode, 'checkid_setup') |
313 | 275 | self.assertTrue(openid_request.return_to.startswith( | 279 | self.assertTrue(openid_request.return_to.startswith( |
314 | 276 | 'http://testserver/openid/complete/')) | 280 | 'http://testserver/openid/complete/')) |
315 | @@ -297,7 +301,8 @@ | |||
316 | 297 | self.assertEqual(response.status_code, 200) | 301 | self.assertEqual(response.status_code, 200) |
317 | 298 | self.assertContains(response, 'OpenID transaction in progress') | 302 | self.assertContains(response, 'OpenID transaction in progress') |
318 | 299 | 303 | ||
320 | 300 | openid_request = self.provider.parseFormPost(response.content) | 304 | openid_request = self.provider.parseFormPost( |
321 | 305 | response.content.decode('utf-8')) | ||
322 | 301 | self.assertEqual(openid_request.mode, 'checkid_setup') | 306 | self.assertEqual(openid_request.mode, 'checkid_setup') |
323 | 302 | self.assertTrue(openid_request.return_to.startswith( | 307 | self.assertTrue(openid_request.return_to.startswith( |
324 | 303 | 'http://testserver/openid/complete/')) | 308 | 'http://testserver/openid/complete/')) |
325 | @@ -309,7 +314,7 @@ | |||
326 | 309 | 314 | ||
327 | 310 | # And they are now logged in: | 315 | # And they are now logged in: |
328 | 311 | response = self.client.get('/getuser/') | 316 | response = self.client.get('/getuser/') |
330 | 312 | self.assertEqual(response.content, 'someuser') | 317 | self.assertEqual(response.content.decode('utf-8'), 'someuser') |
331 | 313 | 318 | ||
332 | 314 | def test_login_create_users(self): | 319 | def test_login_create_users(self): |
333 | 315 | # Create a user with the same name as we'll pass back via sreg. | 320 | # Create a user with the same name as we'll pass back via sreg. |
334 | @@ -321,7 +326,8 @@ | |||
335 | 321 | 326 | ||
336 | 322 | # Complete the request, passing back some simple registration | 327 | # Complete the request, passing back some simple registration |
337 | 323 | # data. The user is redirected to the next URL. | 328 | # data. The user is redirected to the next URL. |
339 | 324 | openid_request = self.provider.parseFormPost(response.content) | 329 | openid_request = self.provider.parseFormPost( |
340 | 330 | response.content.decode('utf-8')) | ||
341 | 325 | sreg_request = sreg.SRegRequest.fromOpenIDRequest(openid_request) | 331 | sreg_request = sreg.SRegRequest.fromOpenIDRequest(openid_request) |
342 | 326 | openid_response = openid_request.answer(True) | 332 | openid_response = openid_request.answer(True) |
343 | 327 | sreg_response = sreg.SRegResponse.extractResponse( | 333 | sreg_response = sreg.SRegResponse.extractResponse( |
344 | @@ -335,7 +341,7 @@ | |||
345 | 335 | # And they are now logged in as a new user (they haven't taken | 341 | # And they are now logged in as a new user (they haven't taken |
346 | 336 | # over the existing "someuser" user). | 342 | # over the existing "someuser" user). |
347 | 337 | response = self.client.get('/getuser/') | 343 | response = self.client.get('/getuser/') |
349 | 338 | self.assertEqual(response.content, 'someuser2') | 344 | self.assertEqual(response.content.decode('utf-8'), 'someuser2') |
350 | 339 | 345 | ||
351 | 340 | # Check the details of the new user. | 346 | # Check the details of the new user. |
352 | 341 | user = User.objects.get(username='someuser2') | 347 | user = User.objects.get(username='someuser2') |
353 | @@ -359,7 +365,8 @@ | |||
354 | 359 | 365 | ||
355 | 360 | # Complete the request, passing back some simple registration | 366 | # Complete the request, passing back some simple registration |
356 | 361 | # data. The user is redirected to the next URL. | 367 | # data. The user is redirected to the next URL. |
358 | 362 | openid_request = self.provider.parseFormPost(response.content) | 368 | openid_request = self.provider.parseFormPost( |
359 | 369 | response.content.decode('utf-8')) | ||
360 | 363 | return openid_request | 370 | return openid_request |
361 | 364 | 371 | ||
362 | 365 | def _get_login_response(self, openid_request, resp_data, use_sreg, | 372 | def _get_login_response(self, openid_request, resp_data, use_sreg, |
363 | @@ -383,7 +390,8 @@ | |||
364 | 383 | self.provider.type_uris.append(pape.ns_uri) | 390 | self.provider.type_uris.append(pape.ns_uri) |
365 | 384 | 391 | ||
366 | 385 | response = self.client.post(self.login_url, self.openid_req) | 392 | response = self.client.post(self.login_url, self.openid_req) |
368 | 386 | openid_request = self.provider.parseFormPost(response.content) | 393 | openid_request = self.provider.parseFormPost( |
369 | 394 | response.content.decode('utf-8')) | ||
370 | 387 | 395 | ||
371 | 388 | request_auth = openid_request.message.getArg( | 396 | request_auth = openid_request.message.getArg( |
372 | 389 | 'http://specs.openid.net/extensions/pape/1.0', | 397 | 'http://specs.openid.net/extensions/pape/1.0', |
373 | @@ -431,7 +439,7 @@ | |||
374 | 431 | query['openid.pape.auth_policies'], [preferred_auth]) | 439 | query['openid.pape.auth_policies'], [preferred_auth]) |
375 | 432 | 440 | ||
376 | 433 | response = self.client.get('/getuser/') | 441 | response = self.client.get('/getuser/') |
378 | 434 | self.assertEqual(response.content, 'testuser') | 442 | self.assertEqual(response.content.decode('utf-8'), 'testuser') |
379 | 435 | 443 | ||
380 | 436 | @override_settings(OPENID_PHYSICAL_MULTIFACTOR_REQUIRED=True) | 444 | @override_settings(OPENID_PHYSICAL_MULTIFACTOR_REQUIRED=True) |
381 | 437 | def test_login_physical_multifactor_not_provided(self): | 445 | def test_login_physical_multifactor_not_provided(self): |
382 | @@ -547,10 +555,11 @@ | |||
383 | 547 | response = self.client.get('/getuser/') | 555 | response = self.client.get('/getuser/') |
384 | 548 | 556 | ||
385 | 549 | # username defaults to 'openiduser' | 557 | # username defaults to 'openiduser' |
387 | 550 | self.assertEqual(response.content, 'openiduser') | 558 | username = response.content.decode('utf-8') |
388 | 559 | self.assertEqual(username, 'openiduser') | ||
389 | 551 | 560 | ||
390 | 552 | # The user's full name and email have been updated. | 561 | # The user's full name and email have been updated. |
392 | 553 | user = User.objects.get(username=response.content) | 562 | user = User.objects.get(username=username) |
393 | 554 | self.assertEqual(user.first_name, 'Openid') | 563 | self.assertEqual(user.first_name, 'Openid') |
394 | 555 | self.assertEqual(user.last_name, 'User') | 564 | self.assertEqual(user.last_name, 'User') |
395 | 556 | self.assertEqual(user.email, 'foo@example.com') | 565 | self.assertEqual(user.email, 'foo@example.com') |
396 | @@ -565,7 +574,7 @@ | |||
397 | 565 | response = self.client.get('/getuser/') | 574 | response = self.client.get('/getuser/') |
398 | 566 | 575 | ||
399 | 567 | # username defaults to a munged version of the email | 576 | # username defaults to a munged version of the email |
401 | 568 | self.assertEqual(response.content, 'fooexamplecom') | 577 | self.assertEqual(response.content.decode('utf-8'), 'fooexamplecom') |
402 | 569 | 578 | ||
403 | 570 | def test_login_duplicate_username_numbering(self): | 579 | def test_login_duplicate_username_numbering(self): |
404 | 571 | # Setup existing user who's name we're going to conflict with | 580 | # Setup existing user who's name we're going to conflict with |
405 | @@ -582,7 +591,7 @@ | |||
406 | 582 | 591 | ||
407 | 583 | # Since this username is already taken by someone else, we go through | 592 | # Since this username is already taken by someone else, we go through |
408 | 584 | # the process of adding +i to it, and get testuser2. | 593 | # the process of adding +i to it, and get testuser2. |
410 | 585 | self.assertEqual(response.content, 'testuser2') | 594 | self.assertEqual(response.content.decode('utf-8'), 'testuser2') |
411 | 586 | 595 | ||
412 | 587 | def test_login_duplicate_username_numbering_with_conflicts(self): | 596 | def test_login_duplicate_username_numbering_with_conflicts(self): |
413 | 588 | # Setup existing user who's name we're going to conflict with | 597 | # Setup existing user who's name we're going to conflict with |
414 | @@ -602,7 +611,7 @@ | |||
415 | 602 | # the process of adding +i to it starting with the count of users with | 611 | # the process of adding +i to it starting with the count of users with |
416 | 603 | # username starting with 'testuser', of which there are 2. i should | 612 | # username starting with 'testuser', of which there are 2. i should |
417 | 604 | # start at 3, which already exists, so it should skip to 4. | 613 | # start at 3, which already exists, so it should skip to 4. |
419 | 605 | self.assertEqual(response.content, 'testuser4') | 614 | self.assertEqual(response.content.decode('utf-8'), 'testuser4') |
420 | 606 | 615 | ||
421 | 607 | def test_login_duplicate_username_numbering_with_holes(self): | 616 | def test_login_duplicate_username_numbering_with_holes(self): |
422 | 608 | # Setup existing user who's name we're going to conflict with | 617 | # Setup existing user who's name we're going to conflict with |
423 | @@ -625,7 +634,7 @@ | |||
424 | 625 | # the process of adding +i to it starting with the count of users with | 634 | # the process of adding +i to it starting with the count of users with |
425 | 626 | # username starting with 'testuser', of which there are 5. i should | 635 | # username starting with 'testuser', of which there are 5. i should |
426 | 627 | # start at 6, and increment until it reaches 9. | 636 | # start at 6, and increment until it reaches 9. |
428 | 628 | self.assertEqual(response.content, 'testuser9') | 637 | self.assertEqual(response.content.decode('utf-8'), 'testuser9') |
429 | 629 | 638 | ||
430 | 630 | def test_login_duplicate_username_numbering_with_nonsequential_matches( | 639 | def test_login_duplicate_username_numbering_with_nonsequential_matches( |
431 | 631 | self): | 640 | self): |
432 | @@ -646,7 +655,7 @@ | |||
433 | 646 | # the process of adding +i to it starting with the count of users with | 655 | # the process of adding +i to it starting with the count of users with |
434 | 647 | # username starting with 'testuser', of which there are 2. i should | 656 | # username starting with 'testuser', of which there are 2. i should |
435 | 648 | # start at 3, which will be available. | 657 | # start at 3, which will be available. |
437 | 649 | self.assertEqual(response.content, 'testuser3') | 658 | self.assertEqual(response.content.decode('utf-8'), 'testuser3') |
438 | 650 | 659 | ||
439 | 651 | def test_login_follow_rename(self): | 660 | def test_login_follow_rename(self): |
440 | 652 | user = User.objects.create_user('testuser', 'someone@example.com') | 661 | user = User.objects.create_user('testuser', 'someone@example.com') |
441 | @@ -666,10 +675,11 @@ | |||
442 | 666 | 675 | ||
443 | 667 | # If OPENID_FOLLOW_RENAMES, they are logged in as | 676 | # If OPENID_FOLLOW_RENAMES, they are logged in as |
444 | 668 | # someuser (the passed in nickname has changed the username) | 677 | # someuser (the passed in nickname has changed the username) |
446 | 669 | self.assertEqual(response.content, 'someuser') | 678 | username = response.content.decode('utf-8') |
447 | 679 | self.assertEqual(username, 'someuser') | ||
448 | 670 | 680 | ||
449 | 671 | # The user's full name and email have been updated. | 681 | # The user's full name and email have been updated. |
451 | 672 | user = User.objects.get(username=response.content) | 682 | user = User.objects.get(username=username) |
452 | 673 | self.assertEqual(user.first_name, 'Some') | 683 | self.assertEqual(user.first_name, 'Some') |
453 | 674 | self.assertEqual(user.last_name, 'User') | 684 | self.assertEqual(user.last_name, 'User') |
454 | 675 | self.assertEqual(user.email, 'foo@example.com') | 685 | self.assertEqual(user.email, 'foo@example.com') |
455 | @@ -691,10 +701,11 @@ | |||
456 | 691 | response = self.client.get('/getuser/') | 701 | response = self.client.get('/getuser/') |
457 | 692 | 702 | ||
458 | 693 | # Username should not have changed | 703 | # Username should not have changed |
460 | 694 | self.assertEqual(response.content, 'testuser') | 704 | username = response.content.decode('utf-8') |
461 | 705 | self.assertEqual(username, 'testuser') | ||
462 | 695 | 706 | ||
463 | 696 | # The user's full name and email have been updated. | 707 | # The user's full name and email have been updated. |
465 | 697 | user = User.objects.get(username=response.content) | 708 | user = User.objects.get(username=username) |
466 | 698 | self.assertEqual(user.first_name, 'Some') | 709 | self.assertEqual(user.first_name, 'Some') |
467 | 699 | self.assertEqual(user.last_name, 'User') | 710 | self.assertEqual(user.last_name, 'User') |
468 | 700 | self.assertEqual(user.email, 'foo@example.com') | 711 | self.assertEqual(user.email, 'foo@example.com') |
469 | @@ -730,10 +741,11 @@ | |||
470 | 730 | # If OPENID_FOLLOW_RENAMES, attempt to change username to 'testuser' | 741 | # If OPENID_FOLLOW_RENAMES, attempt to change username to 'testuser' |
471 | 731 | # but since that username is already taken by someone else, we go | 742 | # but since that username is already taken by someone else, we go |
472 | 732 | # through the process of adding +i to it, and get testuser2. | 743 | # through the process of adding +i to it, and get testuser2. |
474 | 733 | self.assertEqual(response.content, 'testuser2') | 744 | username = response.content.decode('utf-8') |
475 | 745 | self.assertEqual(username, 'testuser2') | ||
476 | 734 | 746 | ||
477 | 735 | # The user's full name and email have been updated. | 747 | # The user's full name and email have been updated. |
479 | 736 | user = User.objects.get(username=response.content) | 748 | user = User.objects.get(username=username) |
480 | 737 | self.assertEqual(user.first_name, 'Rename') | 749 | self.assertEqual(user.first_name, 'Rename') |
481 | 738 | self.assertEqual(user.last_name, 'User') | 750 | self.assertEqual(user.last_name, 'User') |
482 | 739 | self.assertEqual(user.email, 'rename@example.com') | 751 | self.assertEqual(user.email, 'rename@example.com') |
483 | @@ -772,10 +784,11 @@ | |||
484 | 772 | # the username follows the nickname+i scheme, it has non-numbers in the | 784 | # the username follows the nickname+i scheme, it has non-numbers in the |
485 | 773 | # suffix, so it's not an auto-generated one. The regular process of | 785 | # suffix, so it's not an auto-generated one. The regular process of |
486 | 774 | # renaming to 'testuser' has a conflict, so we get +2 at the end. | 786 | # renaming to 'testuser' has a conflict, so we get +2 at the end. |
488 | 775 | self.assertEqual(response.content, 'testuser2') | 787 | username = response.content.decode('utf-8') |
489 | 788 | self.assertEqual(username, 'testuser2') | ||
490 | 776 | 789 | ||
491 | 777 | # The user's full name and email have been updated. | 790 | # The user's full name and email have been updated. |
493 | 778 | user = User.objects.get(username=response.content) | 791 | user = User.objects.get(username=username) |
494 | 779 | self.assertEqual(user.first_name, 'Rename') | 792 | self.assertEqual(user.first_name, 'Rename') |
495 | 780 | self.assertEqual(user.last_name, 'User') | 793 | self.assertEqual(user.last_name, 'User') |
496 | 781 | self.assertEqual(user.email, 'rename@example.com') | 794 | self.assertEqual(user.email, 'rename@example.com') |
497 | @@ -812,10 +825,11 @@ | |||
498 | 812 | # but since that username is already taken by someone else, we go | 825 | # but since that username is already taken by someone else, we go |
499 | 813 | # through the process of adding +i to it. Since the user for this | 826 | # through the process of adding +i to it. Since the user for this |
500 | 814 | # identity url already has a name matching that pattern, check if first | 827 | # identity url already has a name matching that pattern, check if first |
502 | 815 | self.assertEqual(response.content, 'testuser2000') | 828 | username = response.content.decode('utf-8') |
503 | 829 | self.assertEqual(username, 'testuser2000') | ||
504 | 816 | 830 | ||
505 | 817 | # The user's full name and email have been updated. | 831 | # The user's full name and email have been updated. |
507 | 818 | user = User.objects.get(username=response.content) | 832 | user = User.objects.get(username=username) |
508 | 819 | self.assertEqual(user.first_name, 'Rename') | 833 | self.assertEqual(user.first_name, 'Rename') |
509 | 820 | self.assertEqual(user.last_name, 'User') | 834 | self.assertEqual(user.last_name, 'User') |
510 | 821 | self.assertEqual(user.email, 'rename@example.com') | 835 | self.assertEqual(user.email, 'rename@example.com') |
511 | @@ -842,10 +856,11 @@ | |||
512 | 842 | 856 | ||
513 | 843 | # If OPENID_FOLLOW_RENAMES, username should be changed to 'testuser' | 857 | # If OPENID_FOLLOW_RENAMES, username should be changed to 'testuser' |
514 | 844 | # because it wasn't currently taken | 858 | # because it wasn't currently taken |
516 | 845 | self.assertEqual(response.content, 'testuser') | 859 | username = response.content.decode('utf-8') |
517 | 860 | self.assertEqual(username, 'testuser') | ||
518 | 846 | 861 | ||
519 | 847 | # The user's full name and email have been updated. | 862 | # The user's full name and email have been updated. |
521 | 848 | user = User.objects.get(username=response.content) | 863 | user = User.objects.get(username=username) |
522 | 849 | self.assertEqual(user.first_name, 'Same') | 864 | self.assertEqual(user.first_name, 'Same') |
523 | 850 | self.assertEqual(user.last_name, 'User') | 865 | self.assertEqual(user.last_name, 'User') |
524 | 851 | self.assertEqual(user.email, 'same@example.com') | 866 | self.assertEqual(user.email, 'same@example.com') |
525 | @@ -860,7 +875,8 @@ | |||
526 | 860 | 875 | ||
527 | 861 | # Complete the request, passing back some simple registration | 876 | # Complete the request, passing back some simple registration |
528 | 862 | # data. The user is redirected to the next URL. | 877 | # data. The user is redirected to the next URL. |
530 | 863 | openid_request = self.provider.parseFormPost(response.content) | 878 | openid_request = self.provider.parseFormPost( |
531 | 879 | response.content.decode('utf-8')) | ||
532 | 864 | sreg_request = sreg.SRegRequest.fromOpenIDRequest(openid_request) | 880 | sreg_request = sreg.SRegRequest.fromOpenIDRequest(openid_request) |
533 | 865 | openid_response = openid_request.answer(True) | 881 | openid_response = openid_request.answer(True) |
534 | 866 | sreg_response = sreg.SRegResponse.extractResponse( | 882 | sreg_response = sreg.SRegResponse.extractResponse( |
535 | @@ -898,7 +914,8 @@ | |||
536 | 898 | 914 | ||
537 | 899 | # Complete the request, passing back some simple registration | 915 | # Complete the request, passing back some simple registration |
538 | 900 | # data. The user is redirected to the next URL. | 916 | # data. The user is redirected to the next URL. |
540 | 901 | openid_request = self.provider.parseFormPost(response.content) | 917 | openid_request = self.provider.parseFormPost( |
541 | 918 | response.content.decode('utf-8')) | ||
542 | 902 | sreg_request = sreg.SRegRequest.fromOpenIDRequest(openid_request) | 919 | sreg_request = sreg.SRegRequest.fromOpenIDRequest(openid_request) |
543 | 903 | openid_response = openid_request.answer(True) | 920 | openid_response = openid_request.answer(True) |
544 | 904 | sreg_response = sreg.SRegResponse.extractResponse( | 921 | sreg_response = sreg.SRegResponse.extractResponse( |
545 | @@ -927,7 +944,8 @@ | |||
546 | 927 | 944 | ||
547 | 928 | # Complete the request, passing back some simple registration | 945 | # Complete the request, passing back some simple registration |
548 | 929 | # data. The user is redirected to the next URL. | 946 | # data. The user is redirected to the next URL. |
550 | 930 | openid_request = self.provider.parseFormPost(response.content) | 947 | openid_request = self.provider.parseFormPost( |
551 | 948 | response.content.decode('utf-8')) | ||
552 | 931 | sreg_request = sreg.SRegRequest.fromOpenIDRequest(openid_request) | 949 | sreg_request = sreg.SRegRequest.fromOpenIDRequest(openid_request) |
553 | 932 | openid_response = openid_request.answer(True) | 950 | openid_response = openid_request.answer(True) |
554 | 933 | sreg_response = sreg.SRegResponse.extractResponse( | 951 | sreg_response = sreg.SRegResponse.extractResponse( |
555 | @@ -969,7 +987,8 @@ | |||
556 | 969 | 987 | ||
557 | 970 | # Complete the request, passing back some simple registration | 988 | # Complete the request, passing back some simple registration |
558 | 971 | # data. The user is redirected to the next URL. | 989 | # data. The user is redirected to the next URL. |
560 | 972 | openid_request = self.provider.parseFormPost(response.content) | 990 | openid_request = self.provider.parseFormPost( |
561 | 991 | response.content.decode('utf-8')) | ||
562 | 973 | sreg_request = sreg.SRegRequest.fromOpenIDRequest(openid_request) | 992 | sreg_request = sreg.SRegRequest.fromOpenIDRequest(openid_request) |
563 | 974 | openid_response = openid_request.answer(True) | 993 | openid_response = openid_request.answer(True) |
564 | 975 | sreg_response = sreg.SRegResponse.extractResponse( | 994 | sreg_response = sreg.SRegResponse.extractResponse( |
565 | @@ -992,7 +1011,8 @@ | |||
566 | 992 | 1011 | ||
567 | 993 | # Complete the request, passing back some simple registration | 1012 | # Complete the request, passing back some simple registration |
568 | 994 | # data. The user is redirected to the next URL. | 1013 | # data. The user is redirected to the next URL. |
570 | 995 | openid_request = self.provider.parseFormPost(response.content) | 1014 | openid_request = self.provider.parseFormPost( |
571 | 1015 | response.content.decode('utf-8')) | ||
572 | 996 | sreg_request = sreg.SRegRequest.fromOpenIDRequest(openid_request) | 1016 | sreg_request = sreg.SRegRequest.fromOpenIDRequest(openid_request) |
573 | 997 | openid_response = openid_request.answer(True) | 1017 | openid_response = openid_request.answer(True) |
574 | 998 | sreg_response = sreg.SRegResponse.extractResponse( | 1018 | sreg_response = sreg.SRegResponse.extractResponse( |
575 | @@ -1028,10 +1048,11 @@ | |||
576 | 1028 | self._do_user_login(self.openid_req, self.openid_resp) | 1048 | self._do_user_login(self.openid_req, self.openid_resp) |
577 | 1029 | response = self.client.get('/getuser/') | 1049 | response = self.client.get('/getuser/') |
578 | 1030 | 1050 | ||
580 | 1031 | self.assertEqual(response.content, 'testuser') | 1051 | username = response.content.decode('utf-8') |
581 | 1052 | self.assertEqual(username, 'testuser') | ||
582 | 1032 | 1053 | ||
583 | 1033 | # The user's full name and email have been updated. | 1054 | # The user's full name and email have been updated. |
585 | 1034 | user = User.objects.get(username=response.content) | 1055 | user = User.objects.get(username=username) |
586 | 1035 | self.assertEqual(user.first_name, 'Some') | 1056 | self.assertEqual(user.first_name, 'Some') |
587 | 1036 | self.assertEqual(user.last_name, 'User') | 1057 | self.assertEqual(user.last_name, 'User') |
588 | 1037 | self.assertEqual(user.email, 'foo@example.com') | 1058 | self.assertEqual(user.email, 'foo@example.com') |
589 | @@ -1047,7 +1068,8 @@ | |||
590 | 1047 | with self.settings(OPENID_SREG_EXTRA_FIELDS=('language',)): | 1068 | with self.settings(OPENID_SREG_EXTRA_FIELDS=('language',)): |
591 | 1048 | response = self.client.post(self.login_url, self.openid_req) | 1069 | response = self.client.post(self.login_url, self.openid_req) |
592 | 1049 | 1070 | ||
594 | 1050 | openid_request = self.provider.parseFormPost(response.content) | 1071 | openid_request = self.provider.parseFormPost( |
595 | 1072 | response.content.decode('utf-8')) | ||
596 | 1051 | sreg_request = sreg.SRegRequest.fromOpenIDRequest(openid_request) | 1073 | sreg_request = sreg.SRegRequest.fromOpenIDRequest(openid_request) |
597 | 1052 | for field in ('email', 'fullname', 'nickname', 'language'): | 1074 | for field in ('email', 'fullname', 'nickname', 'language'): |
598 | 1053 | self.assertTrue(field in sreg_request) | 1075 | self.assertTrue(field in sreg_request) |
599 | @@ -1064,7 +1086,8 @@ | |||
600 | 1064 | with self.settings(OPENID_SREG_REQUIRED_FIELDS=('email', 'language')): | 1086 | with self.settings(OPENID_SREG_REQUIRED_FIELDS=('email', 'language')): |
601 | 1065 | response = self.client.post(self.login_url, self.openid_req) | 1087 | response = self.client.post(self.login_url, self.openid_req) |
602 | 1066 | 1088 | ||
604 | 1067 | openid_request = self.provider.parseFormPost(response.content) | 1089 | openid_request = self.provider.parseFormPost( |
605 | 1090 | response.content.decode('utf-8')) | ||
606 | 1068 | sreg_request = sreg.SRegRequest.fromOpenIDRequest(openid_request) | 1091 | sreg_request = sreg.SRegRequest.fromOpenIDRequest(openid_request) |
607 | 1069 | 1092 | ||
608 | 1070 | self.assertEqual(['email', 'language'], sreg_request.required) | 1093 | self.assertEqual(['email', 'language'], sreg_request.required) |
609 | @@ -1086,7 +1109,8 @@ | |||
610 | 1086 | 1109 | ||
611 | 1087 | # The resulting OpenID request uses the Attribute Exchange | 1110 | # The resulting OpenID request uses the Attribute Exchange |
612 | 1088 | # extension rather than the Simple Registration extension. | 1111 | # extension rather than the Simple Registration extension. |
614 | 1089 | openid_request = self.provider.parseFormPost(response.content) | 1112 | openid_request = self.provider.parseFormPost( |
615 | 1113 | response.content.decode('utf-8')) | ||
616 | 1090 | sreg_request = sreg.SRegRequest.fromOpenIDRequest(openid_request) | 1114 | sreg_request = sreg.SRegRequest.fromOpenIDRequest(openid_request) |
617 | 1091 | self.assertEqual(sreg_request.required, []) | 1115 | self.assertEqual(sreg_request.required, []) |
618 | 1092 | self.assertEqual(sreg_request.optional, []) | 1116 | self.assertEqual(sreg_request.optional, []) |
619 | @@ -1132,7 +1156,7 @@ | |||
620 | 1132 | assert not settings.OPENID_FOLLOW_RENAMES, ( | 1156 | assert not settings.OPENID_FOLLOW_RENAMES, ( |
621 | 1133 | 'OPENID_FOLLOW_RENAMES must be False') | 1157 | 'OPENID_FOLLOW_RENAMES must be False') |
622 | 1134 | response = self.client.get('/getuser/') | 1158 | response = self.client.get('/getuser/') |
624 | 1135 | self.assertEqual(response.content, 'testuser') | 1159 | self.assertEqual(response.content.decode('utf-8'), 'testuser') |
625 | 1136 | 1160 | ||
626 | 1137 | # The user's full name and email have been updated. | 1161 | # The user's full name and email have been updated. |
627 | 1138 | user = User.objects.get(username='testuser') | 1162 | user = User.objects.get(username='testuser') |
628 | @@ -1216,7 +1240,8 @@ | |||
629 | 1216 | self.assertContains(response, 'OpenID transaction in progress') | 1240 | self.assertContains(response, 'OpenID transaction in progress') |
630 | 1217 | 1241 | ||
631 | 1218 | # Complete the request | 1242 | # Complete the request |
633 | 1219 | openid_request = self.provider.parseFormPost(response.content) | 1243 | openid_request = self.provider.parseFormPost( |
634 | 1244 | response.content.decode('utf-8')) | ||
635 | 1220 | openid_response = openid_request.answer(True) | 1245 | openid_response = openid_request.answer(True) |
636 | 1221 | teams_request = teams.TeamsRequest.fromOpenIDRequest(openid_request) | 1246 | teams_request = teams.TeamsRequest.fromOpenIDRequest(openid_request) |
637 | 1222 | teams_response = teams.TeamsResponse.extractResponse( | 1247 | teams_response = teams.TeamsResponse.extractResponse( |
638 | @@ -1231,7 +1256,7 @@ | |||
639 | 1231 | 1256 | ||
640 | 1232 | # And they are now logged in as testuser | 1257 | # And they are now logged in as testuser |
641 | 1233 | response = self.client.get('/getuser/') | 1258 | response = self.client.get('/getuser/') |
643 | 1234 | self.assertEqual(response.content, 'testuser') | 1259 | self.assertEqual(response.content.decode('utf-8'), 'testuser') |
644 | 1235 | 1260 | ||
645 | 1236 | # The user's groups have been updated. | 1261 | # The user's groups have been updated. |
646 | 1237 | User.objects.get(username='testuser') | 1262 | User.objects.get(username='testuser') |
647 | @@ -1263,7 +1288,8 @@ | |||
648 | 1263 | OPENID_LAUNCHPAD_TEAMS_MAPPING=mapping, | 1288 | OPENID_LAUNCHPAD_TEAMS_MAPPING=mapping, |
649 | 1264 | OPENID_LAUNCHPAD_TEAMS_MAPPING_AUTO=True, | 1289 | OPENID_LAUNCHPAD_TEAMS_MAPPING_AUTO=True, |
650 | 1265 | OPENID_LAUNCHPAD_TEAMS_MAPPING_AUTO_BLACKLIST=blacklist): | 1290 | OPENID_LAUNCHPAD_TEAMS_MAPPING_AUTO_BLACKLIST=blacklist): |
652 | 1266 | openid_request = self.provider.parseFormPost(response.content) | 1291 | openid_request = self.provider.parseFormPost( |
653 | 1292 | response.content.decode('utf-8')) | ||
654 | 1267 | openid_request.answer(True) | 1293 | openid_request.answer(True) |
655 | 1268 | teams.TeamsRequest.fromOpenIDRequest(openid_request) | 1294 | teams.TeamsRequest.fromOpenIDRequest(openid_request) |
656 | 1269 | 1295 | ||
657 | @@ -1316,7 +1342,8 @@ | |||
658 | 1316 | response = self.client.post(self.login_url, self.openid_req_no_next) | 1342 | response = self.client.post(self.login_url, self.openid_req_no_next) |
659 | 1317 | 1343 | ||
660 | 1318 | # Complete the request | 1344 | # Complete the request |
662 | 1319 | openid_request = self.provider.parseFormPost(response.content) | 1345 | openid_request = self.provider.parseFormPost( |
663 | 1346 | response.content.decode('utf-8')) | ||
664 | 1320 | openid_response = openid_request.answer(True) | 1347 | openid_response = openid_request.answer(True) |
665 | 1321 | teams_request = teams.TeamsRequest.fromOpenIDRequest(openid_request) | 1348 | teams_request = teams.TeamsRequest.fromOpenIDRequest(openid_request) |
666 | 1322 | teams_response = teams.TeamsResponse.extractResponse( | 1349 | teams_response = teams.TeamsResponse.extractResponse( |
667 | @@ -1335,7 +1362,8 @@ | |||
668 | 1335 | display_id='http://example.com/identity') | 1362 | display_id='http://example.com/identity') |
669 | 1336 | 1363 | ||
670 | 1337 | response = self.client.post(self.login_url, self.openid_req_no_next) | 1364 | response = self.client.post(self.login_url, self.openid_req_no_next) |
672 | 1338 | openid_request = self.provider.parseFormPost(response.content) | 1365 | openid_request = self.provider.parseFormPost( |
673 | 1366 | response.content.decode('utf-8')) | ||
674 | 1339 | openid_response = openid_request.answer(True) | 1367 | openid_response = openid_request.answer(True) |
675 | 1340 | # Use a closure to test whether the signal handler was called. | 1368 | # Use a closure to test whether the signal handler was called. |
676 | 1341 | self.signal_handler_called = False | 1369 | self.signal_handler_called = False |
677 | 1342 | 1370 | ||
678 | === modified file 'django_openid_auth/views.py' | |||
679 | --- django_openid_auth/views.py 2017-01-16 14:34:06 +0000 | |||
680 | +++ django_openid_auth/views.py 2017-04-03 12:33:16 +0000 | |||
681 | @@ -30,8 +30,11 @@ | |||
682 | 30 | from __future__ import unicode_literals | 30 | from __future__ import unicode_literals |
683 | 31 | 31 | ||
684 | 32 | import re | 32 | import re |
687 | 33 | import urllib | 33 | try: |
688 | 34 | from urlparse import urlsplit | 34 | from urllib.parse import urlencode, urlsplit |
689 | 35 | except ImportError: | ||
690 | 36 | from urllib import urlencode | ||
691 | 37 | from urlparse import urlsplit | ||
692 | 35 | 38 | ||
693 | 36 | from django.conf import settings | 39 | from django.conf import settings |
694 | 37 | from django.contrib.auth import ( | 40 | from django.contrib.auth import ( |
695 | @@ -177,7 +180,10 @@ | |||
696 | 177 | # Invalid or no form data: | 180 | # Invalid or no form data: |
697 | 178 | if openid_url is None: | 181 | if openid_url is None: |
698 | 179 | context = RequestContext(request) | 182 | context = RequestContext(request) |
700 | 180 | context.update({'form': login_form, redirect_field_name: redirect_to}) | 183 | context.update({ |
701 | 184 | 'form': login_form, | ||
702 | 185 | redirect_field_name: redirect_to, | ||
703 | 186 | }) | ||
704 | 181 | return render_to_response(template_name, context) | 187 | return render_to_response(template_name, context) |
705 | 182 | 188 | ||
706 | 183 | consumer = make_consumer(request) | 189 | consumer = make_consumer(request) |
707 | @@ -274,7 +280,7 @@ | |||
708 | 274 | # Django gives us Unicode, which is great. We must encode URI. | 280 | # Django gives us Unicode, which is great. We must encode URI. |
709 | 275 | # urllib enforces str. We can't trust anything about the default | 281 | # urllib enforces str. We can't trust anything about the default |
710 | 276 | # encoding inside str(foo) , so we must explicitly make foo a str. | 282 | # encoding inside str(foo) , so we must explicitly make foo a str. |
712 | 277 | return_to += urllib.urlencode( | 283 | return_to += urlencode( |
713 | 278 | {redirect_field_name: redirect_to.encode("UTF-8")}) | 284 | {redirect_field_name: redirect_to.encode("UTF-8")}) |
714 | 279 | 285 | ||
715 | 280 | return render_openid_request(request, openid_request, return_to) | 286 | return render_openid_request(request, openid_request, return_to) |
716 | @@ -297,8 +303,9 @@ | |||
717 | 297 | if openid_response.status == SUCCESS: | 303 | if openid_response.status == SUCCESS: |
718 | 298 | try: | 304 | try: |
719 | 299 | user = authenticate(openid_response=openid_response) | 305 | user = authenticate(openid_response=openid_response) |
722 | 300 | except DjangoOpenIDException, e: | 306 | except DjangoOpenIDException as e: |
723 | 301 | return render_failure(request, e.message, exception=e) | 307 | return render_failure( |
724 | 308 | request, getattr(e, 'message', str(e)), exception=e) | ||
725 | 302 | 309 | ||
726 | 303 | if user is not None: | 310 | if user is not None: |
727 | 304 | if user.is_active: | 311 | if user.is_active: |
728 | @@ -332,6 +339,7 @@ | |||
729 | 332 | OPENID_LOGO_BASE_64.decode('base64'), mimetype='image/gif' | 339 | OPENID_LOGO_BASE_64.decode('base64'), mimetype='image/gif' |
730 | 333 | ) | 340 | ) |
731 | 334 | 341 | ||
732 | 342 | |||
733 | 335 | # Logo from http://openid.net/login-bg.gif | 343 | # Logo from http://openid.net/login-bg.gif |
734 | 336 | # Embedded here for convenience; you should serve this as a static file | 344 | # Embedded here for convenience; you should serve this as a static file |
735 | 337 | OPENID_LOGO_BASE_64 = """ | 345 | OPENID_LOGO_BASE_64 = """ |
736 | 338 | 346 | ||
737 | === modified file 'example_consumer/urls.py' | |||
738 | --- example_consumer/urls.py 2017-01-16 12:22:28 +0000 | |||
739 | +++ example_consumer/urls.py 2017-04-03 12:33:16 +0000 | |||
740 | @@ -31,7 +31,7 @@ | |||
741 | 31 | from django.contrib import admin | 31 | from django.contrib import admin |
742 | 32 | from django.contrib.auth import views as auth_views | 32 | from django.contrib.auth import views as auth_views |
743 | 33 | 33 | ||
745 | 34 | import views | 34 | from example_consumer import views |
746 | 35 | 35 | ||
747 | 36 | 36 | ||
748 | 37 | admin.autodiscover() | 37 | admin.autodiscover() |
749 | 38 | 38 | ||
750 | === removed file 'setup.cfg' | |||
751 | --- setup.cfg 2017-01-23 15:23:51 +0000 | |||
752 | +++ setup.cfg 1970-01-01 00:00:00 +0000 | |||
753 | @@ -1,2 +0,0 @@ | |||
754 | 1 | [wheel] | ||
755 | 2 | universal = True | ||
756 | 3 | 0 | ||
757 | === modified file 'setup.py' | |||
758 | --- setup.py 2017-01-20 20:25:07 +0000 | |||
759 | +++ setup.py 2017-04-03 12:33:16 +0000 | |||
760 | @@ -39,21 +39,28 @@ | |||
761 | 39 | info. | 39 | info. |
762 | 40 | """ | 40 | """ |
763 | 41 | 41 | ||
764 | 42 | import sys | ||
765 | 43 | |||
766 | 42 | from setuptools import find_packages, setup | 44 | from setuptools import find_packages, setup |
767 | 43 | 45 | ||
768 | 46 | PY3 = sys.version_info.major >= 3 | ||
769 | 47 | |||
770 | 44 | 48 | ||
771 | 45 | description, long_description = __doc__.split('\n\n', 1) | 49 | description, long_description = __doc__.split('\n\n', 1) |
773 | 46 | VERSION = '0.13' | 50 | VERSION = '0.14' |
774 | 51 | |||
775 | 52 | install_requires = ['django>=1.6', 'six'] | ||
776 | 53 | if PY3: | ||
777 | 54 | install_requires.append('python3-openid') | ||
778 | 55 | else: | ||
779 | 56 | install_requires.append('python-openid>=2.2.0') | ||
780 | 47 | 57 | ||
781 | 48 | setup( | 58 | setup( |
782 | 49 | name='django-openid-auth', | 59 | name='django-openid-auth', |
783 | 50 | version=VERSION, | 60 | version=VERSION, |
784 | 51 | 61 | ||
785 | 52 | packages=find_packages(), | 62 | packages=find_packages(), |
790 | 53 | install_requires=[ | 63 | install_requires=install_requires, |
787 | 54 | 'django>=1.6', | ||
788 | 55 | 'python-openid>=2.2.0', | ||
789 | 56 | ], | ||
791 | 57 | package_data={ | 64 | package_data={ |
792 | 58 | 'django_openid_auth': ['templates/openid/*.html'], | 65 | 'django_openid_auth': ['templates/openid/*.html'], |
793 | 59 | }, | 66 | }, |
794 | 60 | 67 | ||
795 | === modified file 'tox.ini' | |||
796 | --- tox.ini 2017-01-20 20:31:51 +0000 | |||
797 | +++ tox.ini 2017-04-03 12:33:16 +0000 | |||
798 | @@ -1,36 +1,51 @@ | |||
799 | 1 | [tox] | 1 | [tox] |
801 | 2 | envlist = py27-django1.6,py27-django1.7,py27-django1.8,py27-django1.9,py27-django1.10 | 2 | envlist = |
802 | 3 | py27-django1.6,py27-django1.7,py27-django1.8,py27-django1.9,py27-django1.10,py3-django1.10 | ||
803 | 3 | 4 | ||
804 | 4 | [testenv] | 5 | [testenv] |
805 | 5 | commands = python manage.py test django_openid_auth | 6 | commands = python manage.py test django_openid_auth |
809 | 6 | basepython = | 7 | deps = |
807 | 7 | python2.7 | ||
808 | 8 | deps= | ||
810 | 9 | mock | 8 | mock |
811 | 9 | |||
812 | 10 | [testenv:py27] | ||
813 | 11 | basepython = python2.7 | ||
814 | 12 | deps = | ||
815 | 10 | python-openid | 13 | python-openid |
816 | 14 | {[testenv]deps} | ||
817 | 15 | |||
818 | 16 | [testenv:py3] | ||
819 | 17 | basepython = python3 | ||
820 | 18 | deps = | ||
821 | 19 | python3-openid | ||
822 | 20 | {[testenv]deps} | ||
823 | 11 | 21 | ||
824 | 12 | [testenv:py27-django1.6] | 22 | [testenv:py27-django1.6] |
825 | 13 | deps = | 23 | deps = |
826 | 14 | django == 1.6.11 | 24 | django == 1.6.11 |
827 | 15 | south | 25 | south |
829 | 16 | {[testenv]deps} | 26 | {[testenv:py27]deps} |
830 | 17 | 27 | ||
831 | 18 | [testenv:py27-django1.7] | 28 | [testenv:py27-django1.7] |
832 | 19 | deps = | 29 | deps = |
833 | 20 | django == 1.7.11 | 30 | django == 1.7.11 |
835 | 21 | {[testenv]deps} | 31 | {[testenv:py27]deps} |
836 | 22 | 32 | ||
837 | 23 | [testenv:py27-django1.8] | 33 | [testenv:py27-django1.8] |
838 | 24 | deps = | 34 | deps = |
839 | 25 | django == 1.8.17 | 35 | django == 1.8.17 |
841 | 26 | {[testenv]deps} | 36 | {[testenv:py27]deps} |
842 | 27 | 37 | ||
843 | 28 | [testenv:py27-django1.9] | 38 | [testenv:py27-django1.9] |
844 | 29 | deps = | 39 | deps = |
845 | 30 | django == 1.9.12 | 40 | django == 1.9.12 |
847 | 31 | {[testenv]deps} | 41 | {[testenv:py27]deps} |
848 | 32 | 42 | ||
849 | 33 | [testenv:py27-django1.10] | 43 | [testenv:py27-django1.10] |
850 | 34 | deps = | 44 | deps = |
853 | 35 | django == 1.10.5 | 45 | django == 1.10.6 |
854 | 36 | {[testenv]deps} | 46 | {[testenv:py27]deps} |
855 | 47 | |||
856 | 48 | [testenv:py3-django1.10] | ||
857 | 49 | deps = | ||
858 | 50 | django == 1.10.6 | ||
859 | 51 | {[testenv:py3]deps} |
LGTM, nice.