0001-views-evaluation-context-error-will-success-55127.patch
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=True)
|
|
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"' in response |
|
84 |
assert len(caplog.records) == 0 |
|
84 | 85 | |
85 | 86 | |
86 | 87 |
def test_show_condition_service(db, app, settings): |
87 | 88 |
settings.AUTH_FRONTENDS_KWARGS = {'password': {'show_condition': 'service_slug == \'portal\''}} |
88 | 89 |
response = app.get('/login/', params={'service': 'portal'}) |
89 |
assert 'name="login-password-submit"' not in response
|
|
90 |
assert 'name="login-password-submit"' in response |
|
90 | 91 | |
91 | 92 |
# Create a service |
92 | 93 |
models.Service.objects.create(name='Service', slug='portal') |
93 | 94 |
response = app.get('/login/', params={'service': 'portal'}) |
94 | 95 |
assert 'name="login-password-submit"' in response |
95 | 96 | |
96 | 97 | |
97 | 98 |
def test_show_condition_with_headers(app, settings): |
98 |
- |