0002-ldap-display-server-error-on-technical-info-backoffi.patch
src/authentic2/manager/templates/authentic2/manager/ldap_details.html | ||
---|---|---|
1 | 1 |
{% load i18n %} |
2 | 2 |
<h4>{% trans "Realm:" %} {{ ldap.realm }}</h4> |
3 | 3 |
<div class="a2-manager-ldap-{{ ldap.realm }}"> |
4 |
{% if not error %} |
|
4 |
{% if not ldap.error %}
|
|
5 | 5 |
<h5>{% blocktrans %}Base ldapsearch command:{% endblocktrans %}</h5> |
6 | 6 |
<pre>ldapsearch -v -H {{ ldap.ldap_uri }} -D "{{ ldap.binddn }}" -w "{{ ldap.bindpw }}" -b "{{ ldap.basedn }}"{% if ldap.user_filter or ldap.sync_ldap_users_filter %} "{% firstof ldap.sync_ldap_users_filter ldap.user_filter %}"{% endif %}</pre> |
7 | 7 |
{% else %} |
8 | 8 |
<div class="error"> |
9 |
{% blocktrans %}Error while attempting to connect to LDAP server, base ldapsearch command won't be displayed.{% endblocktrans %} |
|
9 |
<p>{% blocktrans %}Error while attempting to connect to LDAP server, base ldapsearch command won't be displayed.{% endblocktrans %}</p> |
|
10 |
{% if ldap.errmsg %} |
|
11 |
<p>{% blocktrans with errmsg=ldap.errmsg %}Server error: {{ errmsg }}{% endblocktrans %}</p> |
|
12 |
{% endif %} |
|
10 | 13 |
</div> |
11 | 14 |
{% endif %} |
12 | 15 |
<h5>{% trans "Configuration:" %}</h5> |
src/authentic2/manager/views.py | ||
---|---|---|
676 | 676 |
kwargs['ldap_list'] = [] |
677 | 677 |
for block in backend.get_config(): |
678 | 678 |
config = block.copy() |
679 |
conn = backend.get_connection(config) |
|
680 |
if not conn: |
|
681 |
kwargs['error'] = True |
|
679 |
try: |
|
680 |
conn = backend.get_connection(config, raises=True) |
|
681 |
except ldap.LDAPError as e: |
|
682 |
config['error'] = True |
|
683 |
config['errmsg'] = str(e) |
|
682 | 684 |
else: |
683 | 685 |
# retrieve ldap uri, not directly visible in configuration block |
684 | 686 |
config['ldap_uri'] = conn.get_option(ldap.OPT_URI) |
tests/test_ldap.py | ||
---|---|---|
2287 | 2287 |
]: |
2288 | 2288 |
assert opt in ldap_config_text |
2289 | 2289 | |
2290 |
def buggy_get_connections(config, credentials, raises): |
|
2291 |
raise ldap.LDAPError('some buggy connection error message') |
|
2292 | ||
2290 | 2293 |
# mock a buggy connection |
2291 |
monkeypatch.setattr(ldap_backend.LDAPBackend, 'get_connection', lambda x: None)
|
|
2294 |
monkeypatch.setattr(ldap_backend.LDAPBackend, 'get_connections', buggy_get_connections)
|
|
2292 | 2295 |
resp = app.get(reverse('a2-manager-tech-info')) |
2293 | 2296 |
ldap_config_text = resp.pyquery('div#a2-manager-tech-info-ldap-list').text() |
2294 | 2297 | |
2295 | 2298 |
assert 'Base ldapsearch command' not in ldap_config_text |
2296 | 2299 |
assert 'Error while attempting to connect to LDAP server' in ldap_config_text |
2300 |
assert 'Server error: some buggy connection error message' in ldap_config_text |
|
2297 | 2301 | |
2298 | 2302 | |
2299 | 2303 |
class TestLookup: |
2300 |
- |