(port, dn, provokeSearchError = false, ssl = false)
| 7 | }; |
| 8 | |
| 9 | function newServer(port, dn, provokeSearchError = false, ssl = false) { |
| 10 | const server = ssl ? ldapjs.createServer(tlsOptions) : ldapjs.createServer(); |
| 11 | |
| 12 | server.bind('o=example', function (req, res, next) { |
| 13 | if (req.dn.toString() !== dn || req.credentials !== 'secret') |
| 14 | { return next(new ldapjs.InvalidCredentialsError()); } |
| 15 | res.end(); |
| 16 | return next(); |
| 17 | }); |
| 18 | |
| 19 | server.search('o=example', function (req, res, next) { |
| 20 | if (provokeSearchError) { |
| 21 | res.end(ldapjs.LDAP_SIZE_LIMIT_EXCEEDED); |
| 22 | return next(); |
| 23 | } |
| 24 | const obj = { |
| 25 | dn: req.dn.toString(), |
| 26 | attributes: { |
| 27 | objectclass: ['organization', 'top'], |
| 28 | o: 'example', |
| 29 | }, |
| 30 | }; |
| 31 | |
| 32 | const group = { |
| 33 | dn: req.dn.toString(), |
| 34 | attributes: { |
| 35 | objectClass: ['groupOfUniqueNames', 'top'], |
| 36 | uniqueMember: ['uid=testuser, o=example'], |
| 37 | cn: 'powerusers', |
| 38 | ou: 'powerusers', |
| 39 | }, |
| 40 | }; |
| 41 | |
| 42 | if (req.filter.matches(obj.attributes)) { |
| 43 | res.send(obj); |
| 44 | } |
| 45 | |
| 46 | if (req.filter.matches(group.attributes)) { |
| 47 | res.send(group); |
| 48 | } |
| 49 | res.end(); |
| 50 | }); |
| 51 | return new Promise(resolve => server.listen(port, () => resolve(server))); |
| 52 | } |
| 53 | |
| 54 | module.exports = newServer; |
nothing calls this directly
no test coverage detected