Projet

Général

Profil

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

Lauréline Guérin, 14 septembre 2021 16:54

Télécharger (3,81 ko)

Voir les différences:

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

 tests/form_pages/test_auth.py | 23 +++++++++++++++++++++--
 wcs/forms/root.py             | 13 ++++++++++---
 2 files changed, 31 insertions(+), 5 deletions(-)
tests/form_pages/test_auth.py
34 34

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

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

  
41 49

  
42 50
def test_form_tryauth(pub, formdef):
......
44 52

  
45 53
    resp = get_app(pub).get('/test/tryauth')
46 54
    assert resp.location == 'http://example.net/test/'
55
    resp = get_app(pub).get('/test/tryauth?param1=foo&param2=bar')
56
    assert resp.location == 'http://example.net/test/?param1=foo&param2=bar'
47 57

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

  
55 67
    # if the user is unlogged, there should be a passive redirection to SSO
56 68
    resp = get_app(pub).get('/test/tryauth')
......
64 76
    create_user(pub)
65 77

  
66 78
    resp = get_app(pub).get('/test/forceauth')
67
    assert resp.location == 'http://example.net/login/?ReturnUrl=http%3A//example.net/test/&forceAuthn=true'
79
    assert resp.location == (
80
        'http://example.net/login/' '?ReturnUrl=http%3A//example.net/test/&forceAuthn=true'
81
    )
82
    resp = get_app(pub).get('/test/forceauth?param1=foo&param2=bar')
83
    assert resp.location == (
84
        'http://example.net/login/'
85
        '?ReturnUrl=http%3A//example.net/test/%3Fparam1%3Dfoo%26param2%3Dbar&forceAuthn=true'
86
    )
wcs/forms/root.py
1609 1609
            templates=list(self.get_formdef_template_variants(self.validation_templates)), context=context
1610 1610
        )
1611 1611

  
1612
    def get_url_with_query(self):
1613
        query = get_request().get_query()
1614
        url = self.formdef.get_url()
1615
        if query:
1616
            url += '?' + query
1617
        return url
1618

  
1612 1619
    def tryauth(self):
1613
        return tryauth(self.formdef.get_url())
1620
        return tryauth(self.get_url_with_query())
1614 1621

  
1615 1622
    def auth(self):
1616
        return auth(self.formdef.get_url())
1623
        return auth(self.get_url_with_query())
1617 1624

  
1618 1625
    def forceauth(self):
1619
        return forceauth(self.formdef.get_url())
1626
        return forceauth(self.get_url_with_query())
1620 1627

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