Files
kami-parse-server/spec/MockLdapServer.js
Diamond Lewis e6ac3b6932 fix(prettier): Properly handle lint-stage files (#6970)
Now handles top level files and recursive files in folders.

Set max line length to be 100
2020-10-25 15:06:58 -05:00

49 lines
1.2 KiB
JavaScript

const ldapjs = require('ldapjs');
function newServer(port, dn, provokeSearchError = false) {
const server = ldapjs.createServer();
server.bind('o=example', function (req, res, next) {
if (req.dn.toString() !== dn || req.credentials !== 'secret')
return next(new ldapjs.InvalidCredentialsError());
res.end();
return next();
});
server.search('o=example', function (req, res, next) {
if (provokeSearchError) {
res.end(ldapjs.LDAP_SIZE_LIMIT_EXCEEDED);
return next();
}
const obj = {
dn: req.dn.toString(),
attributes: {
objectclass: ['organization', 'top'],
o: 'example',
},
};
const group = {
dn: req.dn.toString(),
attributes: {
objectClass: ['groupOfUniqueNames', 'top'],
uniqueMember: ['uid=testuser, o=example'],
cn: 'powerusers',
ou: 'powerusers',
},
};
if (req.filter.matches(obj.attributes)) {
res.send(obj);
}
if (req.filter.matches(group.attributes)) {
res.send(group);
}
res.end();
});
return new Promise(resolve => server.listen(port, () => resolve(server)));
}
module.exports = newServer;