Skip to content
This repository was archived by the owner on Mar 15, 2018. It is now read-only.

Commit 3b86471

Browse files
author
jrconlin
committed
Bug 740256 - Correct password check for BID sourced credentials
1 parent 422f24c commit 3b86471

File tree

5 files changed

+28
-6
lines changed

5 files changed

+28
-6
lines changed

apps/constants/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,3 +430,7 @@
430430

431431
# Percentage of what developers earn after Marketplace's cut.
432432
MKT_CUT = .70
433+
434+
# Login credential source
435+
LOGIN_SOURCE_UNKNOWN = 0
436+
LOGIN_SOURCE_BROWSERID = 1

apps/users/models.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ class UserProfile(amo.models.OnChangeMixin, amo.models.ModelBase):
130130
editable=False)
131131
failed_login_attempts = models.PositiveIntegerField(default=0,
132132
editable=False)
133-
133+
source = models.PositiveIntegerField(default=amo.LOGIN_SOURCE_UNKNOWN,
134+
editable=False)
134135
user = models.ForeignKey(DjangoUser, null=True, editable=False, blank=True)
135136

136137
class Meta:
@@ -221,6 +222,8 @@ def is_artist(self):
221222

222223
@amo.cached_property
223224
def needs_tougher_password(user):
225+
if user.source == amo.LOGIN_SOURCE_BROWSERID:
226+
return False
224227
from access import acl
225228
return (acl.action_allowed_user(user, 'Admin', '%') or
226229
acl.action_allowed_user(user, 'Addons', 'Edit') or
@@ -303,6 +306,9 @@ def save(self, force_insert=False, force_update=False, using=None):
303306
delete_user.delete()
304307

305308
def check_password(self, raw_password):
309+
# BrowserID does not store a password.
310+
if self.source == amo.LOGIN_SOURCE_BROWSERID:
311+
return True
306312
if '$' not in self.password:
307313
valid = (get_hexdigest('md5', '', raw_password) == self.password)
308314
if valid:

apps/users/tests/test_forms.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,10 @@ def test_already_logged_in(self):
481481
self.assertNotContains(r, '<button type="submit">Register</button>')
482482

483483
def test_browserid_registered(self):
484-
u = UserProfile.objects.get(email='jbalogh@mozilla.com')
485-
u.password = ''
486-
u.save()
487-
data = {'email': 'jbalogh@mozilla.com'}
484+
u = UserProfile.objects.create(email='bid_test@mozilla.com',
485+
source=amo.LOGIN_SOURCE_BROWSERID,
486+
password='')
487+
data = {'email': u.email}
488488
r = self.client.post('/en-US/firefox/users/register', data)
489489
self.assertContains(r, 'already have an account')
490490

apps/users/views.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ def edit(request):
235235
'resubmit.'))
236236
else:
237237
form = forms.UserEditForm(instance=amouser, webapp=webapp)
238-
239238
return jingo.render(request, 'users/edit.html',
240239
{'form': form, 'amouser': amouser, 'webapp': webapp})
241240

@@ -339,7 +338,9 @@ def browserid_authenticate(request, assertion):
339338
'Learn more</a>')
340339
return (None, _m)
341340
profile = UserProfile.objects.create(username=username, email=email,
341+
source=amo.LOGIN_SOURCE_BROWSERID,
342342
display_name=username)
343+
343344
profile.create_django_user()
344345
profile.user.backend = 'django_browserid.auth.BrowserIDBackend'
345346
if settings.APP_PREVIEW:
@@ -652,6 +653,12 @@ def register(request):
652653
return http.HttpResponseRedirect(reverse('users.login'))
653654

654655
elif mkt_user.exists():
656+
# Handle BrowserID
657+
if (mkt_user.count() == 1 and
658+
mkt_user[0].source == amo.LOGIN_SOURCE_BROWSERID):
659+
messages.info(request, _('You already have an account.'))
660+
form = None
661+
else:
655662
f = PasswordResetForm()
656663
f.users_cache = [mkt_user[0]]
657664
f.save(use_https=request.is_secure(),
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ALTER TABLE `users` ADD COLUMN `source` integer(11) NOT NULL DEFAULT 0;
2+
3+
-- apps/constant/base LOGIN_SOURCE_*
4+
5+
UPDATE `users` SET `source`=1 WHERE `password`='' and `notes`='__market__';

0 commit comments

Comments
 (0)