Skip to content

Commit

Permalink
Fix missing default for groupExists (#100)
Browse files Browse the repository at this point in the history
* Fix no default opts on userExsits and groupExists

* Fix double error emitting
  • Loading branch information
peetypeet5000 authored Jun 14, 2023
1 parent 8ff17bd commit 638b56c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
9 changes: 4 additions & 5 deletions lib/activedirectory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 3 additions & 3 deletions test/groupexists.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ 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()
})
})

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()
})
})

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()
Expand Down
6 changes: 3 additions & 3 deletions test/groupexistsPromised.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ 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)
})
.catch(t.error)
})

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)
})
.catch(t.error)
})

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)
})
Expand Down

0 comments on commit 638b56c

Please sign in to comment.