All files / node-activedirectory/lib/services/internal service.getGroupDistinguishedName.js

23.81% Statements 5/21
0% Branches 0/12
0% Functions 0/2
23.81% Lines 5/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 431x 1x 1x 1x                                                                             1x
const isDistinguishedName               = require('./service.isDistinguishedName');
const getGroupQueryFilter               = require('./service.getGroupQueryFilter');
const getDistinguishedNames             = require('./service.getDistinguishedNames');
const log                               = require('./service.log');
/**
 * Gets the distinguished name for the specified group (cn).
 *
 * @private
 * @param {Object} [opts] Optional LDAP query string parameters to execute. { scope: '', filter: '', attributes: [ '', '', ... ], sizeLimit: 0, timelimit: 0 }
 * @param {String} groupName The name of the group to retrieve the distinguishedName (dn).
 * @param {Function} callback The callback to execute when completed. callback(err: {Object}, dn: {String})
 */
function getGroupDistinguishedName(opts, groupName, callback) {
    var self = this;
 
    if (typeof (groupName) === 'function') {
        callback = groupName;
        groupName = opts;
        opts = undefined;
    }
    log.trace('getGroupDistinguishedName(%j,%s)', opts, groupName);
 
    // Already a dn?
    if (isDistinguishedName.call(self, groupName)) {
        log.debug('"%s" is already a distinguishedName. NOT performing query.', groupName);
        callback(null, groupName);
        return;
    }
 
    getDistinguishedNames.call(self, opts, getGroupQueryFilter(groupName), function (err, dns) {
        if (err) {
            callback(err);
            return;
        }
 
        log.info('%d distinguishedName(s) found for group "%s". Returning first dn: "%s"',
            (dns || []).length, groupName, (dns || [])[0]);
        callback(null, (dns || [])[0]);
    });
}
 
 
module.exports = getGroupDistinguishedName;