Catch basic protocol errors

This commit is contained in:
Johannes Zellner
2019-08-29 13:07:34 +02:00
parent 567d92ce00
commit f61e9c7f27

View File

@@ -47,7 +47,13 @@ function getClientAndConfig(callback) {
settings.getExternalLdapConfig(function (error, externalLdapConfig) {
if (error) return callback(new ExternalLdapError(ExternalLdapError.INTERNAL_ERROR, error));
var client = ldap.createClient({ url: externalLdapConfig.url });
var client;
try {
client = ldap.createClient({ url: externalLdapConfig.url });
} catch (e) {
if (e instanceof ldap.ProtocolError) return callback(new ExternalLdapError(ExternalLdapError.BAD_FIELD, 'url protocol is invalid'));
return callback(new ExternalLdapError(ExternalLdapError.INTERNAL_ERROR, e));
}
if (!externalLdapConfig.bindDn) return callback(null, client);
@@ -72,7 +78,13 @@ function testConfig(config, callback) {
if (!config.baseDn) return callback(new ExternalLdapError(ExternalLdapError.BAD_FIELD, 'basedn must not be empty'));
if (!config.filter) return callback(new ExternalLdapError(ExternalLdapError.BAD_FIELD, 'filter must not be empty'));
var client = ldap.createClient({ url: config.url });
var client;
try {
client = ldap.createClient({ url: config.url });
} catch (e) {
if (e instanceof ldap.ProtocolError) return callback(new ExternalLdapError(ExternalLdapError.BAD_FIELD, 'url protocol is invalid'));
return callback(new ExternalLdapError(ExternalLdapError.INTERNAL_ERROR, e));
}
if (!config.bindDn) return callback(null, client);