Projet

Général

Profil

0002-misc-auth-tryauth-forceauth-with-get-params-5895.patch

Lauréline Guérin, 10 septembre 2021 10:07

Télécharger (3,45 ko)

Voir les différences:

Subject: [PATCH 2/2] misc: auth/tryauth/forceauth with get params (#5895)

 tests/form_pages/test_auth.py | 26 ++++++++++++++++----------
 wcs/forms/root.py             |  6 +++---
 2 files changed, 19 insertions(+), 13 deletions(-)
tests/form_pages/test_auth.py
32 32
def test_form_auth(pub, formdef):
33 33
    create_user(pub)
34 34

  
35
    resp = get_app(pub).get('/test/auth')
36
    assert resp.location == 'http://example.net/login/?ReturnUrl=http%3A//example.net/test/'
35
    resp = get_app(pub).get('/test/auth?param1=foo&param2=bar')
36
    assert (
37
        resp.location
38
        == 'http://example.net/login/?ReturnUrl=http%3A//example.net/test/%3Fparam1%3Dfoo%26param2%3Dbar'
39
    )
37 40

  
38
    resp = login(get_app(pub), username='foo', password='foo').get('/test/auth')
39
    assert resp.location == 'http://example.net/test/'
41
    resp = login(get_app(pub), username='foo', password='foo').get('/test/auth?param1=foo&param2=bar')
42
    assert resp.location == 'http://example.net/test/?param1=foo&param2=bar'
40 43

  
41 44

  
42 45
def test_form_tryauth(pub, formdef):
43 46
    create_user(pub)
44 47

  
45
    resp = get_app(pub).get('/test/tryauth')
46
    assert resp.location == 'http://example.net/test/'
48
    resp = get_app(pub).get('/test/tryauth?param1=foo&param2=bar')
49
    assert resp.location == 'http://example.net/test/?param1=foo&param2=bar'
47 50

  
48 51
    app = login(get_app(pub), username='foo', password='foo')
49 52
    pub.cfg['identification'] = {'methods': ['idp']}
50 53
    pub.write_cfg()
51 54
    # if the user is logged in, the form should be presented
52
    resp = app.get('/test/tryauth')
53
    assert resp.location == 'http://example.net/test/'
55
    resp = app.get('/test/tryauth?param1=foo&param2=bar')
56
    assert resp.location == 'http://example.net/test/?param1=foo&param2=bar'
54 57

  
55 58
    # if the user is unlogged, there should be a passive redirection to SSO
56 59
    resp = get_app(pub).get('/test/tryauth')
......
63 66
def test_form_forceauth(pub, formdef):
64 67
    create_user(pub)
65 68

  
66
    resp = get_app(pub).get('/test/forceauth')
67
    assert resp.location == 'http://example.net/login/?ReturnUrl=http%3A//example.net/test/&forceAuthn=true'
69
    resp = get_app(pub).get('/test/forceauth?param1=foo&param2=bar')
70
    assert resp.location == (
71
        'http://example.net/login/'
72
        '?ReturnUrl=http%3A//example.net/test/%3Fparam1%3Dfoo%26param2%3Dbar&forceAuthn=true'
73
    )
wcs/forms/root.py
1610 1610
        )
1611 1611

  
1612 1612
    def tryauth(self):
1613
        return tryauth(self.formdef.get_url())
1613
        return tryauth(self.formdef.get_url() + '?' + get_request().get_query())
1614 1614

  
1615 1615
    def auth(self):
1616
        return auth(self.formdef.get_url())
1616
        return auth(self.formdef.get_url() + '?' + get_request().get_query())
1617 1617

  
1618 1618
    def forceauth(self):
1619
        return forceauth(self.formdef.get_url())
1619
        return forceauth(self.formdef.get_url() + '?' + get_request().get_query())
1620 1620

  
1621 1621
    def qrcode(self):
1622 1622
        img = qrcode.make(self.formdef.get_url())
1623
-