Change string formatting style

This commit is contained in:
Elie Michel 2017-09-01 11:29:52 +02:00
parent 803cff92c8
commit 435e14669b
2 changed files with 10 additions and 13 deletions

View file

@ -12,7 +12,7 @@ function ldapAuthCommon(user, bindDN, password, callback) {
}); });
ldapclient.on("error", function(err) { ldapclient.on("error", function(err) {
log.error("Unable to connect to LDAP server", err); log.error(`Unable to connect to LDAP server: ${err}`);
callback(!err); callback(!err);
}); });
@ -30,9 +30,9 @@ function simpleLdapAuth(user, password, callback) {
const config = Helper.config; const config = Helper.config;
const userDN = user.replace(/([,\\/#+<>;"= ])/g, "\\$1"); const userDN = user.replace(/([,\\/#+<>;"= ])/g, "\\$1");
const bindDN = config.ldap.primaryKey + "=" + userDN + "," + config.ldap.baseDN; const bindDN = `${config.ldap.primaryKey}=${userDN},${config.ldap.baseDN}`;
log.info("Auth against LDAP ", config.ldap.url, " with provided bindDN ", bindDN); log.info(`Auth against LDAP ${config.ldap.url} with provided bindDN ${bindDN}`);
ldapAuthCommon(user, bindDN, password, callback); ldapAuthCommon(user, bindDN, password, callback);
} }
@ -56,12 +56,12 @@ function advancedLdapAuth(user, password, callback) {
const base = config.ldap.searchDN.base; const base = config.ldap.searchDN.base;
const searchOptions = { const searchOptions = {
scope: config.ldap.searchDN.scope, scope: config.ldap.searchDN.scope,
filter: "(&(" + config.ldap.primaryKey + "=" + userDN + ")" + config.ldap.searchDN.filter + ")", filter: `(&(${config.ldap.primaryKey}=${userDN})${config.ldap.searchDN.filter})`,
attributes: ["dn"] attributes: ["dn"]
}; };
ldapclient.on("error", function(err) { ldapclient.on("error", function(err) {
log.error("Unable to connect to LDAP server", err); log.error(`Unable to connect to LDAP server: ${err}`);
callback(!err); callback(!err);
}); });
@ -73,7 +73,7 @@ function advancedLdapAuth(user, password, callback) {
} else { } else {
ldapclient.search(base, searchOptions, function(err2, res) { ldapclient.search(base, searchOptions, function(err2, res) {
if (err2) { if (err2) {
log.warning("User not found: ", userDN); log.warning(`User not found: ${userDN}`);
ldapclient.unbind(); ldapclient.unbind();
callback(false); callback(false);
} else { } else {
@ -81,13 +81,13 @@ function advancedLdapAuth(user, password, callback) {
res.on("searchEntry", function(entry) { res.on("searchEntry", function(entry) {
found = true; found = true;
const bindDN = entry.objectName; const bindDN = entry.objectName;
log.info("Auth against LDAP ", config.ldap.url, " with found bindDN ", bindDN); log.info(`Auth against LDAP ${config.ldap.url} with found bindDN ${bindDN}`);
ldapclient.unbind(); ldapclient.unbind();
ldapAuthCommon(user, bindDN, password, callback); ldapAuthCommon(user, bindDN, password, callback);
}); });
res.on("error", function(err3) { res.on("error", function(err3) {
log.error("LDAP error: ", err3); log.error(`LDAP error: ${err3}`);
callback(false); callback(false);
}); });
res.on("end", function() { res.on("end", function() {

View file

@ -75,11 +75,8 @@ function startLdapServer(callback) {
res.end(); res.end();
}); });
server.listen(serverPort, function() { server.listen(serverPort, callback);
console.log("LDAP server listening at %s", server.url);
callback();
});
return server; return server;
} }