* initial run * Update ParseGraphQLServer.spec.js * temporarily enable reporter * Bump retry limit * fix undefined database * try to catch error * Handle LiveQueryServers * Update Config.js * fast-fail false * Remove usage of AppCache * oops * Update contributing guide * enable debugger, try network retry attempt 1 * Fix ldap unbinding * move non specs to support * add missing mock adapter * fix Parse.Push * RestController should match batch.spec.js * Remove request attempt limit * handle index.spec.js * Update CHANGELOG.md * Handle error: tuple concurrently updated * test transactions * Clear RedisCache after every test * LoggerController.spec.js * Update schemas.spec.js * finally fix transactions * fix geopoint deadlock * transaction with clean database * batch.spec.js
55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
const ldapjs = require('ldapjs');
|
|
const fs = require('fs');
|
|
|
|
const tlsOptions = {
|
|
key: fs.readFileSync(__dirname + '/cert/key.pem'),
|
|
certificate: fs.readFileSync(__dirname + '/cert/cert.pem'),
|
|
};
|
|
|
|
function newServer(port, dn, provokeSearchError = false, ssl = false) {
|
|
const server = ssl ? ldapjs.createServer(tlsOptions) : 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;
|