diff --git a/bijoe/views.py b/bijoe/views.py index a811436..0b7839d 100644 --- a/bijoe/views.py +++ b/bijoe/views.py @@ -15,13 +15,13 @@ # along with this program. If not, see . import json -import urllib from django.conf import settings from django.shortcuts import resolve_url from django.core.urlresolvers import reverse from django.views.generic import ListView, View from django.http import HttpResponse, HttpResponseRedirect +from django.utils.http import quote from django.utils.translation import ugettext as _ from django.contrib.auth import logout as auth_logout from django.contrib.auth import views as auth_views @@ -101,7 +101,7 @@ def login(request, *args, **kwargs): if not 'next' in request.GET: return HttpResponseRedirect(resolve_url('mellon_login')) return HttpResponseRedirect(resolve_url('mellon_login') + '?next=' - + urllib.quote(request.GET.get('next'))) + + quote(request.GET.get('next'))) return auth_views.login(request, template_name='bijoe/login.html') diff --git a/tests/test_views.py b/tests/test_views.py index 000bbfc..9952823 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -18,6 +18,7 @@ import copy import hashlib import json +import mock import pytest from webtest import Upload @@ -275,3 +276,14 @@ def test_geojson_view(schema1, app, admin, visualization, settings): resp = app.get('/visualization/%s/geojson/' % visualization.id) assert resp.content_type == 'application/json' assert len(resp.json) == 8 + + +@mock.patch('bijoe.views.get_idps', return_value=[{'METADATA': '...'}]) +@mock.patch('bijoe.views.resolve_url', return_value='foo-url') +def test_mellon_idp_redirections(mocked_resolv_url, mocked_get_idps, app): + resp = app.get('/accounts/login/', status=302) + assert resp.location == 'foo-url' + resp = app.get('/accounts/login/?next=http://foo/?bar', status=302) + assert resp.location == 'foo-url?next=http%3A//foo/%3Fbar' + resp = app.get('/accounts/logout/', status=302) + assert resp.location == 'foo-url' diff --git a/tox.ini b/tox.ini index 4c67c3d..f39d44f 100644 --- a/tox.ini +++ b/tox.ini @@ -22,6 +22,7 @@ deps = pytest-freezegun WebTest django-webtest<1.9.3 + mock pyquery tabulate http://git.entrouvert.org/hobo.git/snapshot/hobo-master.tar.gz