MCPcopy Index your code
hub / github.com/parse-community/parse-server / newServer

Function newServer

spec/support/MockLdapServer.js:9–52  ·  view source on GitHub ↗
(port, dn, provokeSearchError = false, ssl = false)

Source from the content-addressed store, hash-verified

7};
8
9function 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
54module.exports = newServer;

Callers

nothing calls this directly

Calls 5

nextFunction · 0.85
createServerMethod · 0.80
toStringMethod · 0.80
resolveFunction · 0.50
sendMethod · 0.45

Tested by

no test coverage detected