Skip to content

Commit

Permalink
Merge pull request liberkee#58 from 6labs/feature/URI_checking
Browse files Browse the repository at this point in the history
Js URI checking
  • Loading branch information
Radu94 authored Mar 2, 2018
2 parents 39ab117 + d897523 commit 1a23e5d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
11 changes: 8 additions & 3 deletions libs/ldap_async_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
});
Expand Down
12 changes: 12 additions & 0 deletions libs/utils/check_variable_format.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openldapjs",
"version": "1.0.3",
"version": "1.0.4",
"description": "A ldap client nodejs",
"main": "index.js",
"repository": {
Expand Down

0 comments on commit 1a23e5d

Please sign in to comment.