From 638b56cd0e56373a3c9eff1f73dab38f4521657b Mon Sep 17 00:00:00 2001 From: Peter LaMontagne <49214098+peetypeet5000@users.noreply.github.com> Date: Wed, 14 Jun 2023 09:22:38 -0700 Subject: [PATCH] Fix missing default for groupExists (#100) * Fix no default opts on userExsits and groupExists * Fix double error emitting --- lib/activedirectory.js | 9 ++++----- package.json | 2 +- test/groupexists.test.js | 6 +++--- test/groupexistsPromised.test.js | 6 +++--- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/activedirectory.js b/lib/activedirectory.js index ef65cbe..4de1f44 100755 --- a/lib/activedirectory.js +++ b/lib/activedirectory.js @@ -549,14 +549,14 @@ ActiveDirectory.prototype.getGroupMembershipForGroup = function getGroupMembersh * @param {function} callback The callback to execute when completed. */ ActiveDirectory.prototype.userExists = function userExists (opts, username, callback) { - let _opts = opts + let _opts = opts || {} let _username = username let _cb = callback if (typeof username === 'function') { _cb = username _username = opts - _opts = null + _opts = {} } _opts = merge({}, _opts || {}) log.trace('userExists(%j,%s)', _opts, _username) @@ -580,14 +580,14 @@ ActiveDirectory.prototype.userExists = function userExists (opts, username, call * @param {function} callback The callback to execute when completed. */ ActiveDirectory.prototype.groupExists = function groupExists (opts, groupName, callback) { - let _opts = opts + let _opts = opts || {} let _groupName = groupName let _cb = callback if (typeof groupName === 'function') { _cb = groupName _groupName = opts - _opts = null + _opts = {} } _opts = merge({}, _opts) log.trace('groupExists(%j,%s)', _opts, _groupName) @@ -999,7 +999,6 @@ ActiveDirectory.prototype.getRootDSE = function getRootDSE (url, attributes, cal if (err.errno !== 'ECONNRESET') { // we don't care about ECONNRESET log.trace('A connection error occured searching for root DSE at %s. Error: %s', _url, err) this.emit('error', err) - _cb(err) } }) // Anonymous bind diff --git a/package.json b/package.json index 5307beb..b2871cc 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "dependencies": { "abstract-logging": "^2.0.0", "async": "^3.1.0", - "ldapjs": "^2.1.0", + "ldapjs": "^2.3.3", "merge-options": "^2.0.0" }, "scripts": { diff --git a/test/groupexists.test.js b/test/groupexists.test.js index 22ea8a1..f82d4ab 100644 --- a/test/groupexists.test.js +++ b/test/groupexists.test.js @@ -22,7 +22,7 @@ tap.afterEach((done, t) => { }) tap.test('should return true if the groupName (commonName) exists', t => { - t.context.ad.groupExists(settings.sAMAccountName, settings.groupName.cn, function (err, exists) { + t.context.ad.groupExists(settings.groupName.cn, function (err, exists) { t.error(err) t.true(exists) t.end() @@ -30,7 +30,7 @@ tap.test('should return true if the groupName (commonName) exists', t => { }) tap.test('should return true if the groupName (distinguishedName) exists', t => { - t.context.ad.groupExists(settings.sAMAccountName, settings.groupName.dn, function (err, exists) { + t.context.ad.groupExists(settings.groupName.dn, function (err, exists) { t.error(err) t.true(exists) t.end() @@ -38,7 +38,7 @@ tap.test('should return true if the groupName (distinguishedName) exists', t => }) tap.test('should return false if the groupName doesn\'t exist', t => { - t.context.ad.groupExists(settings.sAMAccountName, '!!!NON-EXISTENT GROUP!!!', function (err, exists) { + t.context.ad.groupExists('!!!NON-EXISTENT GROUP!!!', function (err, exists) { t.error(err) t.false(exists) t.end() diff --git a/test/groupexistsPromised.test.js b/test/groupexistsPromised.test.js index 4794712..0bae930 100644 --- a/test/groupexistsPromised.test.js +++ b/test/groupexistsPromised.test.js @@ -22,7 +22,7 @@ tap.afterEach((done, t) => { }) tap.test('should return true if the groupName (commonName) exists', t => { - return t.context.ad.groupExists(settings.sAMAccountName, settings.groupName.cn) + return t.context.ad.groupExists(settings.groupName.cn) .then((exists) => { t.true(exists) }) @@ -30,7 +30,7 @@ tap.test('should return true if the groupName (commonName) exists', t => { }) tap.test('should return true if the groupName (distinguishedName) exists', t => { - return t.context.ad.groupExists(settings.sAMAccountName, settings.groupName.dn) + return t.context.ad.groupExists(settings.groupName.dn) .then((exists) => { t.true(exists) }) @@ -38,7 +38,7 @@ tap.test('should return true if the groupName (distinguishedName) exists', t => }) tap.test('should return false if the groupName doesn\'t exist', t => { - return t.context.ad.groupExists(settings.sAMAccountName, '!!!NON-EXISTENT GROUP!!!') + return t.context.ad.groupExists('!!!NON-EXISTENT GROUP!!!') .then((exists) => { t.false(exists) })