0001-views-pass-service-parameter-to-show-evaluation-cont.patch
src/authentic2/views.py | ||
---|---|---|
320 | 320 |
parameters = {'request': request, 'context': context} |
321 | 321 |
remote_addr = request.META.get('REMOTE_ADDR') |
322 | 322 |
login_hint = set(request.session.get('login-hint', [])) |
323 | 323 |
show_ctx = dict(remote_addr=remote_addr, login_hint=login_hint, headers=HTTPHeaders(request)) |
324 | 324 |
if service: |
325 | 325 |
show_ctx['service_ou_slug'] = service.ou and service.ou.slug |
326 | 326 |
show_ctx['service_slug'] = service.slug |
327 | 327 |
show_ctx['service'] = service |
328 |
else: |
|
329 |
show_ctx['service_ou_slug'] = None |
|
330 |
show_ctx['service_slug'] = None |
|
331 |
show_ctx['service'] = None |
|
328 | 332 |
# check if the authenticator has multiple instances |
329 | 333 |
if hasattr(authenticator, 'instances'): |
330 | 334 |
for instance_id, instance in authenticator.instances(**parameters): |
331 | 335 |
parameters['instance'] = instance |
332 | 336 |
parameters['instance_id'] = instance_id |
333 | 337 |
if not authenticator.shown(instance_id=instance_id, ctx=show_ctx): |
334 | 338 |
continue |
335 | 339 |
block = utils.get_authenticator_method(authenticator, 'login', parameters) |
tests/test_login.py | ||
---|---|---|
89 | 89 |
assert 'name="login-password-submit"' not in response |
90 | 90 | |
91 | 91 |
# Create a service |
92 | 92 |
models.Service.objects.create(name='Service', slug='portal') |
93 | 93 |
response = app.get('/login/', params={'service': 'portal'}) |
94 | 94 |
assert 'name="login-password-submit"' in response |
95 | 95 | |
96 | 96 | |
97 |
def test_show_condition_service_undefined_service_parameter(db, app, settings): |
|
98 |
settings.AUTH_FRONTENDS_KWARGS = {'password': {'show_condition': 'service_slug == None'}} |
|
99 |
response = app.get('/login/', params={}) |
|
100 |
assert 'name="login-password-submit"' in response |
|
101 | ||
102 | ||
97 | 103 |
def test_show_condition_with_headers(app, settings): |
98 | 104 |
settings.A2_AUTH_OIDC_ENABLE = False # prevent db access by OIDC frontend |
99 | 105 |
settings.AUTH_FRONTENDS_KWARGS = {'password': {'show_condition': '\'X-Entrouvert\' in headers'}} |
100 | 106 |
response = app.get('/login/') |
101 | 107 |
assert 'name="login-password-submit"' not in response |
102 | 108 |
response = app.get('/login/', headers={'x-entrouvert': '1'}) |
103 | 109 |
assert 'name="login-password-submit"' in response |
104 | 110 | |
105 |
- |