Projet

Général

Profil

0001-views-do-not-log-on-evaluation-context-failure-55127.patch

Nicolas Roche, 24 juin 2021 10:26

Télécharger (2,78 ko)

Voir les différences:

Subject: [PATCH] views: do not log on evaluation context failure (#55127)

 src/authentic2/authenticators.py |  2 +-
 tests/test_login.py              | 14 ++++++++++----
 2 files changed, 11 insertions(+), 5 deletions(-)
src/authentic2/authenticators.py
46 46
            return self.show_condition
47 47

  
48 48
    def shown(self, instance_id=None, ctx=()):
49 49
        show_condition = self.get_show_condition(instance_id)
50 50
        if not show_condition:
51 51
            return True
52 52
        ctx = dict(ctx, id=instance_id)
53 53
        try:
54
            return evaluate_condition(show_condition, ctx)
54
            return evaluate_condition(show_condition, ctx, on_raise=False)
55 55
        except Exception as e:
56 56
            logger.error(e)
57 57
            return False
58 58

  
59 59

  
60 60
class LoginPasswordAuthenticator(BaseAuthenticator):
61 61
    id = 'password'
62 62
    submit_name = 'login-password-submit'
tests/test_login.py
72 72
    assert 'name="login-password-submit"' in response
73 73

  
74 74
    settings.AUTH_FRONTENDS_KWARGS = {'password': {'show_condition': 'False'}}
75 75
    response = app.get('/login/')
76 76
    # login form must not be displayed
77 77
    assert 'name="login-password-submit"' not in response
78 78
    assert len(caplog.records) == 0
79 79
    # set a condition with error
80
    with check_log(caplog, 'name \'unknown\' is not defined'):
81
        settings.AUTH_FRONTENDS_KWARGS = {'password': {'show_condition': '\'admin\' in unknown'}}
82
        response = app.get('/login/')
83
        assert 'name="login-password-submit"' not in response
80

  
81
    settings.AUTH_FRONTENDS_KWARGS = {'password': {'show_condition': '\'admin\' in unknown'}}
82
    response = app.get('/login/')
83
    assert 'name="login-password-submit"' not in response
84
    assert len(caplog.records) == 0
85

  
86
    settings.AUTH_FRONTENDS_KWARGS = {'password': {'show_condition': 'service_slug == \'portal\''}}
87
    response = app.get('/login/', params={})
88
    assert 'name="login-password-submit"' not in response
89
    assert len(caplog.records) == 0
84 90

  
85 91

  
86 92
def test_show_condition_service(db, app, settings):
87 93
    settings.AUTH_FRONTENDS_KWARGS = {'password': {'show_condition': 'service_slug == \'portal\''}}
88 94
    response = app.get('/login/', params={'service': 'portal'})
89 95
    assert 'name="login-password-submit"' not in response
90 96

  
91 97
    # Create a service
92
-