Projet

Général

Profil

0010-tests-add-auth_saml-logout-test-69720.patch

Benjamin Dauvergne, 18 octobre 2022 20:36

Télécharger (2,31 ko)

Voir les différences:

Subject: [PATCH 10/10] tests: add auth_saml logout test (#69720)

 tests/auth_saml/test_logout.py | 48 ++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 tests/auth_saml/test_logout.py
tests/auth_saml/test_logout.py
1
# authentic2 - versatile identity manager
2
# Copyright (C) 2010-2022 Entr'ouvert
3
#
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU Affero General Public License as published
6
# by the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU Affero General Public License for more details.
13
#
14
# You should have received a copy of the GNU Affero General Public License
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16

  
17
import lasso
18
import pytest
19
from mellon.models import SessionIndex, UserSAMLIdentifier
20
from mellon.models_utils import get_issuer
21

  
22
from ..utils import login
23

  
24
ISSUER = 'http://idp5/metadata'
25

  
26

  
27
def test_redirect_logout(app, idp, simple_user):
28
    response = login(app, simple_user, '/accounts/')
29

  
30
    session = app.session
31

  
32
    # simulate mellon state after login
33
    session['mellon_session'] = {'issuer': ISSUER}
34
    session.save()
35

  
36
    issuer = get_issuer(ISSUER)
37
    usi = UserSAMLIdentifier.objects.create(
38
        user=simple_user,
39
        issuer=issuer,
40
        name_id='1234',
41
        nid_format=lasso.SAML2_NAME_IDENTIFIER_FORMAT_PERSISTENT,
42
    )
43
    SessionIndex.objects.create(saml_identifier=usi, session_key=session.session_key, session_index='abcd')
44

  
45
    response = response.click('Logout')
46
    assert response.location.startswith('/accounts/saml/logout/?token')
47
    response = app.get('/accounts/saml/logout/?SAMLResponse=coin')
48
    assert response.location == '/logout/'
0
-