Skip to content

Commit

Permalink
Fix unhandled "unshift is not a function" error
Browse files Browse the repository at this point in the history
In certain cases, if there is only one entry for `memberOf`, the
attribute may be a string rather than an array. Attempting to call
`unshift` on the string object would cause an unhandled error. Added a
check to ensure that `memberOf` is an array before calling `unshift`,
and if it is a string, convert it into an array with the primary group
prepended.
  • Loading branch information
adalinesimonian committed Jun 22, 2015
1 parent 362f4b3 commit 779c46a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/adauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,10 @@ ADAuth.prototype._findGroups = function (obj, options, callback) {

if (primaryGroup) {
groups.unshift(primaryGroup);
if (obj.memberOf) {
if (Array.isArray(obj.memberOf)) {
obj.memberOf.unshift(primaryGroup.dn);
} else if (obj.memberOf) {
obj.memberOf = [ primaryGroup.dn, obj.memberOf ];
}
}

Expand Down

0 comments on commit 779c46a

Please sign in to comment.