views: evaluation context error will success (#55127)
This commit is contained in:
parent
5a02e20860
commit
da6013b67b
|
@ -51,7 +51,7 @@ class BaseAuthenticator(object):
|
|||
return True
|
||||
ctx = dict(ctx, id=instance_id)
|
||||
try:
|
||||
return evaluate_condition(show_condition, ctx)
|
||||
return evaluate_condition(show_condition, ctx, on_raise=True)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
return False
|
||||
|
|
|
@ -77,22 +77,27 @@ def test_show_condition(db, app, settings, caplog):
|
|||
assert 'name="login-password-submit"' not in response
|
||||
assert len(caplog.records) == 0
|
||||
# set a condition with error
|
||||
with check_log(caplog, 'name \'unknown\' is not defined'):
|
||||
settings.AUTH_FRONTENDS_KWARGS = {'password': {'show_condition': '\'admin\' in unknown'}}
|
||||
response = app.get('/login/')
|
||||
assert 'name="login-password-submit"' not in response
|
||||
|
||||
settings.AUTH_FRONTENDS_KWARGS = {'password': {'show_condition': '\'admin\' in unknown'}}
|
||||
response = app.get('/login/')
|
||||
assert 'name="login-password-submit"' in response
|
||||
assert len(caplog.records) == 0
|
||||
|
||||
|
||||
def test_show_condition_service(db, app, settings):
|
||||
settings.AUTH_FRONTENDS_KWARGS = {'password': {'show_condition': 'service_slug == \'portal\''}}
|
||||
response = app.get('/login/', params={'service': 'portal'})
|
||||
assert 'name="login-password-submit"' not in response
|
||||
assert 'name="login-password-submit"' in response
|
||||
|
||||
# Create a service
|
||||
models.Service.objects.create(name='Service', slug='portal')
|
||||
response = app.get('/login/', params={'service': 'portal'})
|
||||
assert 'name="login-password-submit"' in response
|
||||
|
||||
models.Service.objects.create(name='Service', slug='service')
|
||||
response = app.get('/login/', params={'service': 'service'})
|
||||
assert 'name="login-password-submit"' not in response
|
||||
|
||||
|
||||
def test_show_condition_with_headers(app, settings):
|
||||
settings.A2_AUTH_OIDC_ENABLE = False # prevent db access by OIDC frontend
|
||||
|
|
Loading…
Reference in New Issue