From c3aa53f323246573d4b3aed95f66fe8ef5509bb2 Mon Sep 17 00:00:00 2001 From: Aribasoiu Date: Thu, 22 Feb 2018 13:15:05 +0200 Subject: [PATCH 1/2] added checkURI static method + renamed scoped const that had the same name as a global. --- libs/ldap_async_wrap.js | 11 ++++++++--- libs/utils/check_variable_format.js | 12 ++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/libs/ldap_async_wrap.js b/libs/ldap_async_wrap.js index d61ed60..061e9b1 100644 --- a/libs/ldap_async_wrap.js +++ b/libs/ldap_async_wrap.js @@ -62,6 +62,9 @@ class LDAPAsyncWrap { initialize() { return new Promise((resolve, reject) => { if (this._stateClient === E_STATES.CREATED) { + if (!checkParameters.checkURI(this._hostAddress)) { + return reject(new Error(`Could not parse LDAP URI(S): ${this._hostAddress}`)); + } this._binding.initialize(this._hostAddress, (err, result) => { if (err) { const CustomError = errorHandler(err); @@ -90,8 +93,8 @@ class LDAPAsyncWrap { startTLS(pathToCertFile) { return new Promise((resolve, reject) => { if (this._stateClient === E_STATES.INITIALIZED) { - const path = pathToCertFile === undefined ? '' : pathToCertFile; - this._binding.startTls(path, (err, res) => { + const certificatePath = pathToCertFile === undefined ? '' : pathToCertFile; + this._binding.startTls(certificatePath, (err, res) => { if (err) { const CustomError = errorHandler(err); reject(new CustomError(errorMessages.ldapStartTlsErrorMessage)); @@ -265,7 +268,9 @@ class LDAPAsyncWrap { this._searchID += 1; const timeValue = timeVal === undefined ? this._timeVal : timeVal; - resolve(new SearchStream(searchBase, scopeObject[scope], searchFilter, pageSize, this._searchID, this._binding, timeValue)); + + resolve(new SearchStream(searchBase, scopeObject[scope], searchFilter, + pageSize, this._searchID, this._binding, timeValue)); } reject(new StateError(errorMessages.bindErrorMessage)); }); diff --git a/libs/utils/check_variable_format.js b/libs/utils/check_variable_format.js index 66b3993..0a6472b 100644 --- a/libs/utils/check_variable_format.js +++ b/libs/utils/check_variable_format.js @@ -125,6 +125,18 @@ class CheckParam { return entryAttr; } + + /** + * + * Static method that checks if a string is a proper ldap URI. + * @param {String} uri String that represents the ldap server URI + */ + static checkURI(uri) { + + return uri.startsWith('ldap://') || uri.startsWith('ldaps://'); + + } + } module.exports = CheckParam; From 8c44d335bf971cacd0e6339168ca296a82156a6b Mon Sep 17 00:00:00 2001 From: Radu94 Date: Fri, 2 Mar 2018 14:41:07 +0200 Subject: [PATCH 2/2] Update package.json Bumped version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 42c60e5..0caec98 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openldapjs", - "version": "1.0.1", + "version": "1.0.4", "description": "A ldap client nodejs", "main": "index.js", "repository": {