This repository has been archived by the owner on Oct 28, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix bug 1046671] Upgrade django browserid to version 0.11.
* Remove browserid from submodules. * Add browserid in requirements/prod.txt.
- Loading branch information
1 parent
661b127
commit 7f1746d
Showing
73 changed files
with
5,280 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from django.conf import settings | ||
from django.contrib.auth.models import Group, User | ||
|
||
from django_browserid.auth import BrowserIDBackend, default_username_algo | ||
|
||
from remo.base.mozillians import BadStatusCodeError, is_vouched | ||
|
||
|
||
USERNAME_ALGO = getattr(settings, 'BROWSERID_USERNAME_ALGO', | ||
default_username_algo) | ||
|
||
|
||
class RemoBrowserIDBackend(BrowserIDBackend): | ||
|
||
def create_user(self, email): | ||
try: | ||
data = is_vouched(email) | ||
except BadStatusCodeError: | ||
data = None | ||
|
||
# Add vouched mozillians to our db please. | ||
if data and data['is_vouched']: | ||
user = User.objects.create_user(username=USERNAME_ALGO(email), | ||
email=email) | ||
# Due to privacy settings, this might be missing | ||
if 'full_name' not in data: | ||
data['full_name'] = 'Anonymous Mozillian' | ||
else: | ||
user.userprofile.mozillian_username = data['username'] | ||
user.userprofile.save() | ||
|
||
first_name, last_name = (data['full_name'].split(' ', 1) | ||
if ' ' in data['full_name'] | ||
else ('', data['full_name'])) | ||
user.first_name = first_name | ||
user.last_name = last_name | ||
user.save() | ||
user.groups.add(Group.objects.get(name='Mozillians')) | ||
return user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from django.contrib.auth.models import User | ||
|
||
import mock | ||
from nose.tools import eq_ | ||
|
||
from remo.base.backend import RemoBrowserIDBackend | ||
from remo.base.tests import RemoTestCase | ||
|
||
|
||
class RemoBackendTests(RemoTestCase): | ||
|
||
@mock.patch('remo.base.backend.is_vouched') | ||
def test_create_mozillian_user_with_private_data(self, mocked_vouched): | ||
""" Test user creation for user with private data in Mozillians.""" | ||
|
||
email = 'mozillian@example.com' | ||
|
||
eq_(User.objects.filter(email=email).count(), 0) | ||
|
||
backend = RemoBrowserIDBackend() | ||
backend.User = mock.Mock() | ||
mocked_vouched.return_value = {'is_vouched': True, | ||
'email': email} | ||
backend.create_user(email) | ||
|
||
user = User.objects.get(email=email) | ||
eq_(user.get_full_name(), u'Anonymous Mozillian') | ||
|
||
@mock.patch('remo.base.backend.is_vouched') | ||
def test_create_mozillian_user_with_public_name(self, mocked_vouched): | ||
""" Test user creation for user with private data in Mozillians.""" | ||
|
||
email = 'mozillian@example.com' | ||
|
||
eq_(User.objects.filter(email=email).count(), 0) | ||
|
||
backend = RemoBrowserIDBackend() | ||
backend.User = mock.Mock() | ||
mocked_vouched.return_value = {'is_vouched': True, | ||
'email': email, | ||
'full_name': 'Awesome Mozillian', | ||
'username': 'remobot'} | ||
backend.create_user(email) | ||
|
||
user = User.objects.get(email=email) | ||
eq_(user.get_full_name(), u'Awesome Mozillian') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.