Skip to content

Commit

Permalink
Fixes bug 889025 - Made login redirect to the previous page. r=peterbe
Browse files Browse the repository at this point in the history
  • Loading branch information
adngdb committed Aug 7, 2013
1 parent 9fba44c commit 40d8f18
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
34 changes: 31 additions & 3 deletions webapp-django/crashstats/auth/tests/test_views.py
@@ -1,4 +1,5 @@
import mock
import urllib
from nose.tools import eq_, ok_

from django.conf import settings
Expand All @@ -25,10 +26,15 @@ def tearDown(self):
super(TestViews, self).tearDown()
self.ldap_patcher.stop()

def _login_attempt(self, email, assertion='fakeassertion123'):
def _login_attempt(self, email, assertion='fakeassertion123', goto=None):
with mock_browserid(email):
r = self.client.post(reverse('auth:mozilla_browserid_verify'),
{'assertion': assertion})
post_data = {'assertion': assertion}
if goto:
post_data['goto'] = urllib.quote(goto)
r = self.client.post(
reverse('auth:mozilla_browserid_verify'),
post_data
)
return r

@property
Expand Down Expand Up @@ -79,3 +85,25 @@ def search_s(base, scope, filterstr, *args, **kwargs):
response = self._login_attempt('peter@example.com')
eq_(response.status_code, 302)
ok_(self._home_url in response['Location'])

def test_redirect(self):
result = {
'abc123': {'uid': 'abc123', 'mail': 'peter@example.com'},
}

def search_s(base, scope, filterstr, *args, **kwargs):
if 'ou=groups' in base:
group_name = settings.LDAP_GROUP_NAMES[0]
if ('peter@example.com' in filterstr and
'cn=%s' % group_name in filterstr):
return result.items()
else:
# basic lookup
if 'peter@example.com' in filterstr:
return result.items()
return []

self.connection.search_s = mock.MagicMock(side_effect=search_s)
response = self._login_attempt('peter@example.com', goto='/query/')
eq_(response.status_code, 302)
ok_('/query/' in response['Location'])
3 changes: 2 additions & 1 deletion webapp-django/crashstats/auth/views.py
Expand Up @@ -100,6 +100,7 @@ def mozilla_browserid_verify(request):
"""Custom BrowserID verifier for mozilla addresses."""
home_url = reverse('crashstats.home',
args=(settings.DEFAULT_PRODUCT,))
goto_url = request.POST.get('goto', None) or home_url
form = BrowserIDForm(request.POST)
if form.is_valid():
assertion = form.cleaned_data['assertion']
Expand Down Expand Up @@ -148,4 +149,4 @@ def mozilla_browserid_verify(request):
request,
"Login failed"
)
return redirect(home_url)
return redirect(goto_url)
Expand Up @@ -137,6 +137,7 @@ <h1>Product Navigation</h1>
<form method="post" action="{{ url('auth:mozilla_browserid_verify') }}">
{{ csrf() }}
{{ browserid_form.as_p() }}
<input type="hidden" name="goto" value="{{ request.get_full_path() }}">
</form>
{% endif %}
</li>
Expand Down

0 comments on commit 40d8f18

Please sign in to comment.