diff --git a/src/authentic2/authenticators.py b/src/authentic2/authenticators.py index 0e8e46adb..c86092472 100644 --- a/src/authentic2/authenticators.py +++ b/src/authentic2/authenticators.py @@ -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 diff --git a/tests/test_login.py b/tests/test_login.py index 8fb274aa3..eaf9f1e7f 100644 --- a/tests/test_login.py +++ b/tests/test_login.py @@ -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