From 779c46ae52d210a716f4818308238a956f115b0d Mon Sep 17 00:00:00 2001 From: Vartan Simonian Date: Mon, 22 Jun 2015 04:37:10 -0700 Subject: [PATCH] Fix unhandled "unshift is not a function" error 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. --- lib/adauth.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/adauth.js b/lib/adauth.js index 6d21da7..5e744d8 100644 --- a/lib/adauth.js +++ b/lib/adauth.js @@ -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 ]; } }