python3: update idp login redirection (#40730)

This commit is contained in:
Nicolas Roche 2020-03-13 17:18:50 +01:00
parent 26dd217655
commit 8c16da984d
3 changed files with 15 additions and 2 deletions

View File

@ -15,13 +15,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import json import json
import urllib
from django.conf import settings from django.conf import settings
from django.shortcuts import resolve_url from django.shortcuts import resolve_url
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.views.generic import ListView, View from django.views.generic import ListView, View
from django.http import HttpResponse, HttpResponseRedirect from django.http import HttpResponse, HttpResponseRedirect
from django.utils.http import quote
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.contrib.auth import logout as auth_logout from django.contrib.auth import logout as auth_logout
from django.contrib.auth import views as auth_views from django.contrib.auth import views as auth_views
@ -101,7 +101,7 @@ def login(request, *args, **kwargs):
if not 'next' in request.GET: if not 'next' in request.GET:
return HttpResponseRedirect(resolve_url('mellon_login')) return HttpResponseRedirect(resolve_url('mellon_login'))
return HttpResponseRedirect(resolve_url('mellon_login') + '?next=' 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') return auth_views.login(request, template_name='bijoe/login.html')

View File

@ -18,6 +18,7 @@ import copy
import hashlib import hashlib
import json import json
import mock
import pytest import pytest
from webtest import Upload 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) resp = app.get('/visualization/%s/geojson/' % visualization.id)
assert resp.content_type == 'application/json' assert resp.content_type == 'application/json'
assert len(resp.json) == 8 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'

View File

@ -22,6 +22,7 @@ deps =
pytest-freezegun pytest-freezegun
WebTest WebTest
django-webtest<1.9.3 django-webtest<1.9.3
mock
pyquery pyquery
tabulate tabulate
http://git.entrouvert.org/hobo.git/snapshot/hobo-master.tar.gz http://git.entrouvert.org/hobo.git/snapshot/hobo-master.tar.gz