misc: auth/tryauth/forceauth with get params (#5895)
gitea-wip/wcs/pipeline/head Build started...
Details
gitea-wip/wcs/pipeline/head Build started...
Details
This commit is contained in:
parent
7481ab86d3
commit
652a2c7a08
|
@ -34,9 +34,17 @@ def test_form_auth(pub, formdef):
|
|||
|
||||
resp = get_app(pub).get('/test/auth')
|
||||
assert resp.location == 'http://example.net/login/?ReturnUrl=http%3A//example.net/test/'
|
||||
resp = get_app(pub).get('/test/auth?param1=foo¶m2=bar')
|
||||
assert (
|
||||
resp.location
|
||||
== 'http://example.net/login/?ReturnUrl=http%3A//example.net/test/%3Fparam1%3Dfoo%26param2%3Dbar'
|
||||
)
|
||||
|
||||
resp = login(get_app(pub), username='foo', password='foo').get('/test/auth')
|
||||
app = login(get_app(pub), username='foo', password='foo')
|
||||
resp = app.get('/test/auth')
|
||||
assert resp.location == 'http://example.net/test/'
|
||||
resp = app.get('/test/auth?param1=foo¶m2=bar')
|
||||
assert resp.location == 'http://example.net/test/?param1=foo¶m2=bar'
|
||||
|
||||
|
||||
def test_form_tryauth(pub, formdef):
|
||||
|
@ -44,6 +52,8 @@ def test_form_tryauth(pub, formdef):
|
|||
|
||||
resp = get_app(pub).get('/test/tryauth')
|
||||
assert resp.location == 'http://example.net/test/'
|
||||
resp = get_app(pub).get('/test/tryauth?param1=foo¶m2=bar')
|
||||
assert resp.location == 'http://example.net/test/?param1=foo¶m2=bar'
|
||||
|
||||
app = login(get_app(pub), username='foo', password='foo')
|
||||
pub.cfg['identification'] = {'methods': ['idp']}
|
||||
|
@ -51,6 +61,8 @@ def test_form_tryauth(pub, formdef):
|
|||
# if the user is logged in, the form should be presented
|
||||
resp = app.get('/test/tryauth')
|
||||
assert resp.location == 'http://example.net/test/'
|
||||
resp = app.get('/test/tryauth?param1=foo¶m2=bar')
|
||||
assert resp.location == 'http://example.net/test/?param1=foo¶m2=bar'
|
||||
|
||||
# if the user is unlogged, there should be a passive redirection to SSO
|
||||
resp = get_app(pub).get('/test/tryauth')
|
||||
|
@ -64,4 +76,11 @@ def test_form_forceauth(pub, formdef):
|
|||
create_user(pub)
|
||||
|
||||
resp = get_app(pub).get('/test/forceauth')
|
||||
assert resp.location == 'http://example.net/login/?ReturnUrl=http%3A//example.net/test/&forceAuthn=true'
|
||||
assert resp.location == (
|
||||
'http://example.net/login/' '?ReturnUrl=http%3A//example.net/test/&forceAuthn=true'
|
||||
)
|
||||
resp = get_app(pub).get('/test/forceauth?param1=foo¶m2=bar')
|
||||
assert resp.location == (
|
||||
'http://example.net/login/'
|
||||
'?ReturnUrl=http%3A//example.net/test/%3Fparam1%3Dfoo%26param2%3Dbar&forceAuthn=true'
|
||||
)
|
||||
|
|
|
@ -1609,14 +1609,21 @@ class FormPage(Directory, FormTemplateMixin):
|
|||
templates=list(self.get_formdef_template_variants(self.validation_templates)), context=context
|
||||
)
|
||||
|
||||
def get_url_with_query(self):
|
||||
query = get_request().get_query()
|
||||
url = self.formdef.get_url()
|
||||
if query:
|
||||
url += '?' + query
|
||||
return url
|
||||
|
||||
def tryauth(self):
|
||||
return tryauth(self.formdef.get_url())
|
||||
return tryauth(self.get_url_with_query())
|
||||
|
||||
def auth(self):
|
||||
return auth(self.formdef.get_url())
|
||||
return auth(self.get_url_with_query())
|
||||
|
||||
def forceauth(self):
|
||||
return forceauth(self.formdef.get_url())
|
||||
return forceauth(self.get_url_with_query())
|
||||
|
||||
def qrcode(self):
|
||||
img = qrcode.make(self.formdef.get_url())
|
||||
|
|
Loading…
Reference in New Issue