Project

General

Profile

0001-views-show-debug-login-view-on-lasso-exception-68962.patch

Valentin Deniaud, 14 September 2022 01:54 PM

Download (2.75 KB)

View differences:

Subject: [PATCH] views: show debug login view on lasso exception (#68962)

 mellon/views.py       |  4 +++-
 tests/test_sso_slo.py | 17 +++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)
mellon/views.py
231 231
        ):
232 232
            self.show_message_status_is_not_success(login, 'SAML authentication failed')
233 233
        except lasso.Error as e:
234
            if self.debug_login:
235
                return self.render_debug_template(request, login)
234 236
            return HttpResponseBadRequest('error processing the authentication response: %r' % e)
235 237
        else:
236 238
            if 'RelayState' in request.POST and utils.is_nonnull(request.POST['RelayState']):
......
315 317

  
316 318
        return HttpResponseRedirect(next_url)
317 319

  
318
    def render_debug_template(self, request, login, attributes):
320
    def render_debug_template(self, request, login, attributes=None):
319 321
        request.session['mellon_debug_login'] = False
320 322
        context = {
321 323
            'logs': self.stream.getvalue(),
tests/test_sso_slo.py
21 21
import xml.etree.ElementTree as ET
22 22
import zlib
23 23
from html import unescape
24
from unittest import mock
24 25

  
25 26
import lasso
26 27
import pytest
......
776 777
    assert '<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"' in caplog.text
777 778

  
778 779

  
780
def test_debug_sso_on_exception(db, app, idp, caplog, sp_settings, settings):
781
    settings.DEBUG = True
782
    response = app.get(reverse('mellon_debug_login') + '?next=/whatever/')
783
    response = response.follow()
784
    url, body, relay_state = idp.process_authn_request_redirect(response['Location'])
785

  
786
    def lasso_error(*args, **kwargs):
787
        raise lasso.Error
788

  
789
    with mock.patch('lasso.Login.acceptSso', side_effect=lasso_error):
790
        response = app.post(reverse('mellon_login'), params={'SAMLResponse': body, 'RelayState': relay_state})
791

  
792
    response_text = unescape(response.text)
793
    assert '<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"' in response_text
794

  
795

  
779 796
def test_nonce(db, app, idp, caplog, sp_settings):
780 797
    response = app.get(reverse('mellon_login') + '?nonce=1234')
781 798
    url, body, relay_state = idp.process_authn_request_redirect(response['Location'])
782
-