Projet

Général

Profil

0001-python3-update-idp-login-redirection-40730.patch

Nicolas Roche, 13 mars 2020 17:31

Télécharger (4,17 ko)

Voir les différences:

Subject: [PATCH] python3: update idp login redirection (#40730)

 bijoe/views.py      |  4 ++--
 tests/test_views.py | 12 ++++++++++++
 tox.ini             |  1 +
 3 files changed, 15 insertions(+), 2 deletions(-)
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
26 27

  
27 28
from bijoe.visualization.models import Visualization
28 29
from bijoe.visualization.signature import sign_url
......
270 271
    assert resp.content_type == 'application/vnd.oasis.opendocument.spreadsheet'
271 272

  
272 273

  
273 274
def test_geojson_view(schema1, app, admin, visualization, settings):
274 275
    login(app, admin)
275 276
    resp = app.get('/visualization/%s/geojson/' % visualization.id)
276 277
    assert resp.content_type == 'application/json'
277 278
    assert len(resp.json) == 8
279

  
280

  
281
@mock.patch('bijoe.views.get_idps', return_value='foo')
282
@mock.patch('bijoe.views.resolve_url', return_value='foo-url')
283
def test_idp_redirections(mocked_resolv_url, mocked_get_idps, app):
284
    resp = app.get('/accounts/login/', status=302)
285
    assert resp.location == 'foo-url'
286
    resp = app.get('/accounts/login/?next=bar-url', status=302)
287
    assert resp.location == 'foo-url?next=bar-url'
288
    resp = app.get('/accounts/logout/', status=302)
289
    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
-