Projet

Général

Profil

0001-views-pass-service-parameter-to-show-evaluation-cont.patch

Serghei Mihai, 30 juin 2020 12:05

Télécharger (3,75 ko)

Voir les différences:

Subject: [PATCH] views: pass service parameter to show evaluation context
 (#42370)

 src/authentic2/views.py | 14 ++++++++++----
 tests/test_login.py     |  9 ++++++++-
 2 files changed, 18 insertions(+), 5 deletions(-)
src/authentic2/views.py
321 321
            parameters = {'request': request,
322 322
                          'context': context}
323 323
            remote_addr = request.META.get('REMOTE_ADDR')
324
            service = request.GET.get('service')
324 325
            login_hint = set(request.session.get('login-hint', []))
326
            show_ctx = dict(remote_addr=remote_addr, login_hint=login_hint)
327
            if service and '.' in service:
328
                ou_slug, service_slug = service.split('.')
329
                if models.Service.objects.filter(slug=service_slug).exists() and \
330
                   OU.objects.filter(slug=ou_slug).exists():
331
                    show_ctx['service_slug'] = service
325 332
            # check if the authenticator has multiple instances
326 333
            if hasattr(authenticator, 'instances'):
327 334
                for instance_id, instance in authenticator.instances(**parameters):
328 335
                    parameters['instance'] = instance
329 336
                    parameters['instance_id'] = instance_id
330
                    if not authenticator.shown(
331
                            instance_id=instance_id,
332
                            ctx=dict(remote_addr=remote_addr, login_hint=login_hint)):
337
                    if not authenticator.shown(instance_id=instance_id,
338
                                               ctx=show_ctx):
333 339
                        continue
334 340
                    block = utils.get_authenticator_method(authenticator, 'login', parameters)
335 341
                    # update block id in order to separate instances
336 342
                    block['id'] = '%s_%s' % (block['id'], instance_id)
337 343
                    auth_blocks.append(block)
338 344
            else:
339
                if authenticator.shown(ctx=dict(remote_addr=remote_addr, login_hint=login_hint)):
345
                if authenticator.shown(ctx=show_ctx):
340 346
                    auth_blocks.append(utils.get_authenticator_method(authenticator, 'login', parameters))
341 347
            # If a login frontend method returns an HttpResponse with a status code != 200
342 348
            # this response is returned.
tests/test_login.py
64 64
        settings.AUTH_FRONTENDS_KWARGS = {'password': {'show_condition': '\'admin\' in unknown'}}
65 65
        response = app.get('/login/')
66 66
        assert 'name="login-password-submit"' not in response
67
    settings.AUTH_FRONTENDS_KWARGS = {'password': {'show_condition': 'service_slug == \'default.portal\''}}
68
    response = app.get('/login/', params={'service': 'default.portal'})
69
    assert 'name="login-password-submit"' not in response
70

  
71
    # Create a service
72
    service = models.Service.objects.create(name='Service', slug='portal')
73
    response = app.get('/login/', params={'service': 'default.portal'})
74
    assert 'name="login-password-submit"' in response
67 75

  
68 76

  
69 77
def test_registration_url_on_login_page(db, app):
......
233 241
    resp = resp.form.submit(name='login-password-submit')
234 242
    # CSRF and test cookie checks failed
235 243
    assert 'Cookies are disabled' in resp
236

  
237
-