UNPKG

1.24 kBPlain TextView Raw
1/**
2 * A dummy manual test script
3 */
4import * as Logger from 'bunyan';
5import * as LdapAuth from '../lib/ldapauth';
6
7const log = new Logger({
8 name: 'ldap',
9 component: 'client',
10 stream: process.stderr,
11 level: 'trace'
12});
13
14const opts: LdapAuth.Options = {
15 url: 'ldap://ldap.forumsys.com:389',
16 bindDN: 'cn=read-only-admin,dc=example,dc=com',
17 bindCredentials: 'password',
18 searchBase: 'dc=example,dc=com',
19 searchFilter: '(uid={{username}})',
20 log: log,
21 cache: true,
22 includeRaw: true,
23 groupSearchFilter: '(member={{dn}})',
24 groupSearchBase: 'dc=example,dc=com'
25};
26
27const auth = new LdapAuth(opts);
28
29auth.on('error', (err) => {
30 console.warn(err);
31 // TODO: auth.close() doesn't do anything here
32});
33
34auth.authenticate('riemann', 'password', (err, user) => {
35 if (err) {
36 console.warn(err);
37 auth.close(() => console.log('Unbound'));
38 } else {
39 console.log(user);
40 // Re-auth to be able to verify cache works
41 auth.authenticate('riemann', 'password', (err, user) => {
42 if (err) {
43 console.warn(err);
44 } else {
45 console.log('Re-auth user DN:', user.dn);
46 }
47 auth.close();
48 });
49 }
50});