Skip to content

Commit

Permalink
feat(destroy): added destroy() method to end client connections to se…
Browse files Browse the repository at this point in the history
…rver
  • Loading branch information
jxjj committed Apr 9, 2017
1 parent 8094f72 commit c1836d6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ ldap
// sn: 'Vandelay',
// telephoneNumber: '555-123-4567',
// }]

// disconnect from LDAP server and do no allow reconnection
ldap.destroy();
```

## Streams Example
Expand All @@ -79,7 +82,7 @@ const settings = {
}

// create a new client
const ldap = new SimpleLDAP(settings.ldap);
const ldap = new SimpleLDAP(settings);


ldap.get()
Expand Down Expand Up @@ -126,3 +129,6 @@ Returns a promise for the data.

### `ldap.getStream(filter, attributes)`
Returns a readable stream of data.

### `ldap.destroy()`
Destroys the connection to the LDAP server.
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,11 @@ export default class SimpleLDAPGet {
});
});
}

destroy() {
if (this.client) {
this.client.destroy();
this.client = null;
}
}
}
15 changes: 14 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import through from 'through2';
import concat from 'concat-stream';
import ldapjs from 'ldapjs';
import settings from './settings.example.js';
import TestLDAPServer from './ldapServer';
import mockData from './mockData';
Expand Down Expand Up @@ -33,10 +34,22 @@ describe('LDAP', () => {

// create a new connection to test LDAP server
beforeEach((done) => {
ldap = new SimpleLDAP(settings.ldap);
ldap = new SimpleLDAP(settings);
done();
});

describe('ldap client', () => {
it('new creates new instance of client', (done) => {
expect(ldap.client).to.be.instanceOf(ldapjs.Client);
done();
});
it('is destroyable', () => {
ldap.destroy();
expect(ldap.client).to.be.null;
});
});


describe('ldap.getPromise()', () => {
it('gets data from LDAP given a filter', () => {
const expected = {
Expand Down
12 changes: 5 additions & 7 deletions test/settings.example.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
export default {
ldap: {
url: 'ldap://0.0.0.0:1389',
base: 'dc=users,dc=localhost',
bind: {
dn: 'cn=root',
password: 'secret',
},
url: 'ldap://0.0.0.0:1389',
base: 'dc=users,dc=localhost',
bind: {
dn: 'cn=root',
password: 'secret',
},
};

0 comments on commit c1836d6

Please sign in to comment.