0001-python3-update-idp-login-redirection-40730.patch
bijoe/views.py | ||
---|---|---|
10 | 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | 12 |
# GNU Affero General Public License for more details. |
13 | 13 |
# |
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 | 17 |
import json |
18 |
import urllib |
|
19 | 18 | |
20 | 19 |
from django.conf import settings |
21 | 20 |
from django.shortcuts import resolve_url |
22 | 21 |
from django.core.urlresolvers import reverse |
23 | 22 |
from django.views.generic import ListView, View |
24 | 23 |
from django.http import HttpResponse, HttpResponseRedirect |
24 |
from django.utils.http import quote |
|
25 | 25 |
from django.utils.translation import ugettext as _ |
26 | 26 |
from django.contrib.auth import logout as auth_logout |
27 | 27 |
from django.contrib.auth import views as auth_views |
28 | 28 |
from django.contrib.auth.views import redirect_to_login |
29 | 29 |
from django.core.exceptions import PermissionDenied |
30 | 30 | |
31 | 31 |
try: |
32 | 32 |
from mellon.utils import get_idps |
... | ... | |
96 | 96 |
menu_json = MenuJSONView.as_view() |
97 | 97 | |
98 | 98 | |
99 | 99 |
def login(request, *args, **kwargs): |
100 | 100 |
if any(get_idps()): |
101 | 101 |
if not 'next' in request.GET: |
102 | 102 |
return HttpResponseRedirect(resolve_url('mellon_login')) |
103 | 103 |
return HttpResponseRedirect(resolve_url('mellon_login') + '?next=' |
104 |
+ urllib.quote(request.GET.get('next')))
|
|
104 |
+ quote(request.GET.get('next'))) |
|
105 | 105 |
return auth_views.login(request, template_name='bijoe/login.html') |
106 | 106 | |
107 | 107 | |
108 | 108 |
def logout(request, next_page=None): |
109 | 109 |
if any(get_idps()): |
110 | 110 |
return HttpResponseRedirect(resolve_url('mellon_logout')) |
111 | 111 |
auth_logout(request) |
112 | 112 |
if next_page is not None: |
tests/test_views.py | ||
---|---|---|
13 | 13 |
# |
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 | 17 |
import copy |
18 | 18 |
import hashlib |
19 | 19 |
import json |
20 | 20 | |
21 |
import mock |
|
21 | 22 |
import pytest |
22 | 23 |
from webtest import Upload |
23 | 24 | |
24 | 25 |
from django.urls import reverse |
25 | 26 |
from django.utils.encoding import force_bytes |
27 |
from django.utils.http import unquote |
|
26 | 28 | |
27 | 29 |
from bijoe.visualization.models import Visualization |
28 | 30 |
from bijoe.visualization.signature import sign_url |
29 | 31 | |
30 | 32 |
from utils import login |
31 | 33 | |
32 | 34 | |
33 | 35 |
@pytest.fixture |
... | ... | |
270 | 272 |
assert resp.content_type == 'application/vnd.oasis.opendocument.spreadsheet' |
271 | 273 | |
272 | 274 | |
273 | 275 |
def test_geojson_view(schema1, app, admin, visualization, settings): |
274 | 276 |
login(app, admin) |
275 | 277 |
resp = app.get('/visualization/%s/geojson/' % visualization.id) |
276 | 278 |
assert resp.content_type == 'application/json' |
277 | 279 |
assert len(resp.json) == 8 |
280 | ||
281 | ||
282 |
@mock.patch('bijoe.views.get_idps', return_value=[{'METADATA': '...'}]) |
|
283 |
@mock.patch('bijoe.views.resolve_url', return_value='foo-url') |
|
284 |
def test_mellon_idp_redirections(mocked_resolv_url, mocked_get_idps, app): |
|
285 |
resp = app.get('/accounts/login/', status=302) |
|
286 |
assert resp.location == 'foo-url' |
|
287 |
resp = app.get('/accounts/login/?next=http://foo/?bar', status=302) |
|
288 |
assert resp.location == 'foo-url?next=http%3A//foo/%3Fbar' |
|
289 |
assert unquote(resp.location) == 'foo-url?next=http://foo/?bar' |
|
290 |
resp = app.get('/accounts/logout/', status=302) |
|
291 |
assert resp.location == 'foo-url' |
tox.ini | ||
---|---|---|
18 | 18 |
dj111: django>=1.11,<1.12 |
19 | 19 |
coverage |
20 | 20 |
pytest |
21 | 21 |
pytest-cov |
22 | 22 |
pytest-django<3.4.6 |
23 | 23 |
pytest-freezegun |
24 | 24 |
WebTest |
25 | 25 |
django-webtest<1.9.3 |
26 |
mock |
|
26 | 27 |
pyquery |
27 | 28 |
tabulate |
28 | 29 |
http://git.entrouvert.org/hobo.git/snapshot/hobo-master.tar.gz |
29 | 30 |
commands = |
30 | 31 |
dj111: py.test {posargs: --junitxml=test_{envname}_results.xml --cov-report xml --cov-report html --cov=bijoe tests/} |
31 | 32 |
[pytest] |
32 | 33 |
filterwarnings = |
33 | 34 |
once:.* |
34 |
- |