0001-views-pass-service-parameter-to-show-evaluation-cont.patch
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 models.Service.objects.filter(slug=service).exists(): |
|
328 |
show_ctx['service_slug'] = service |
|
325 | 329 |
# check if the authenticator has multiple instances |
326 | 330 |
if hasattr(authenticator, 'instances'): |
327 | 331 |
for instance_id, instance in authenticator.instances(**parameters): |
328 | 332 |
parameters['instance'] = instance |
329 | 333 |
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)): |
|
334 |
if not authenticator.shown(instance_id=instance_id, |
|
335 |
ctx=show_ctx): |
|
333 | 336 |
continue |
334 | 337 |
block = utils.get_authenticator_method(authenticator, 'login', parameters) |
335 | 338 |
# update block id in order to separate instances |
336 | 339 |
block['id'] = '%s_%s' % (block['id'], instance_id) |
337 | 340 |
auth_blocks.append(block) |
338 | 341 |
else: |
339 |
if authenticator.shown(ctx=dict(remote_addr=remote_addr, login_hint=login_hint)):
|
|
342 |
if authenticator.shown(ctx=show_ctx):
|
|
340 | 343 |
auth_blocks.append(utils.get_authenticator_method(authenticator, 'login', parameters)) |
341 | 344 |
# If a login frontend method returns an HttpResponse with a status code != 200 |
342 | 345 |
# 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 == \'portal\''}} |
|
68 |
response = app.get('/login/', params={'service': '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': '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 |
- |