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 |
|
|
97 |
models.Service.objects.create(name='Service', slug='service')
|
|
98 |
response = app.get('/login/', params={'service': 'service'})
|
|
99 |
assert 'name="login-password-submit"' not in response
|
|
100 |
|
96 |
101 |
|
97 |
102 |
def test_show_condition_with_headers(app, settings):
|
98 |
103 |
settings.A2_AUTH_OIDC_ENABLE = False # prevent db access by OIDC frontend
|
99 |
104 |
settings.AUTH_FRONTENDS_KWARGS = {'password': {'show_condition': '\'X-Entrouvert\' in headers'}}
|
100 |
105 |
response = app.get('/login/')
|
101 |
106 |
assert 'name="login-password-submit"' not in response
|
102 |
107 |
response = app.get('/login/', headers={'x-entrouvert': '1'})
|
103 |
108 |
assert 'name="login-password-submit"' in response
|
104 |
|
-
|