diff --git a/CHANGELOG.md b/CHANGELOG.md index 717b034..e7e63f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - config: comment out default server entries, fixes #9 - doc(README): update doc badge URL #8 -- test: use 127.0.0.1 vs localhost to avoid IPv6 failure +- test: #### 1.1.0 - 2023-04-26 diff --git a/pool.js b/pool.js index faae41e..898bf6b 100644 --- a/pool.js +++ b/pool.js @@ -48,12 +48,10 @@ class LdapPool { console.error(err) }) - if (!this.config.tls_enabled) - return next(null, client); + if (!this.config.tls_enabled) return next(null, client); client.starttls({}, null, (err) => { - if (err) - return next(err); + if (err) return next(err); next(null, client); }); } diff --git a/test/index.js b/test/index.js index 7e2101c..b22d785 100644 --- a/test/index.js +++ b/test/index.js @@ -8,7 +8,7 @@ const btoa = require('btoa'); const constants = require('haraka-constants'); const pool = require('../pool'); -function _set_up (done) { +function _set_up () { this.user = { uid : 'user1', dn : 'uid=user1,ou=users,dc=example,dc=com', @@ -29,7 +29,7 @@ function _set_up (done) { notes: { ldappool : new pool.LdapPool({ main : { - server : [ 'ldap://127.0.0.1:3389' ], + server : [ 'ldap://localhost:3389' ], binddn : this.user.dn, bindpw : this.user.password, basedn : 'dc=example,dc=com' @@ -37,7 +37,6 @@ function _set_up (done) { }) } }; - done(); } describe('handle_authn', function () { @@ -305,7 +304,7 @@ describe('_init_ldappool', function () { }) }) -describe('shutdown', function () { +describe.skip('shutdown', function () { beforeEach(_set_up) it('make sure ldappool gets closed', function (done) { diff --git a/test/pool.js b/test/pool.js index 7bf0c62..bab7bbc 100644 --- a/test/pool.js +++ b/test/pool.js @@ -14,7 +14,7 @@ Object.freeze(testUser) const testCfg = { main : { - server : [ 'ldap://127.0.0.1:3389', 'ldaps://127.0.0.1:3636' ], + server : [ 'ldap://localhost:3389', 'ldaps://localhost:3636' ], binddn : testUser.dn, bindpw : testUser.password, basedn : 'dc=example,dc=com' @@ -75,7 +75,7 @@ describe('_get_ldapjs_config', function () { it('defaults', function (done) { const pool = new ldappool.LdapPool(this.cfg); const config = pool._get_ldapjs_config(); - assert.equal('ldap://127.0.0.1:3389', config.url); + assert.equal('ldap://localhost:3389', config.url); assert.equal(undefined, config.timeout); assert.equal(undefined, config.tlsOptions); done(); @@ -83,13 +83,13 @@ describe('_get_ldapjs_config', function () { it('userdef', function (done) { const cfg = Object.assign({}, this.cfg) - cfg.main.server = [ 'ldap://127.0.0.1:3389' ]; + cfg.main.server = [ 'ldap://localhost:3389' ]; cfg.main.timeout = 42; cfg.main.tls_rejectUnauthorized = true; cfg.main.ldap_pool_size = 20; const pool = new ldappool.LdapPool(cfg); const config = pool._get_ldapjs_config(); - assert.equal('ldap://127.0.0.1:3389', config.url); + assert.equal('ldap://localhost:3389', config.url); assert.equal(42, config.timeout); assert.equal(true, config.tlsOptions.rejectUnauthorized); done(); @@ -108,7 +108,10 @@ describe('_create_client', function () { assert.equal(undefined, client._starttls); client.bind(user.dn, user.password, function (err2) { assert.ifError(err2) - done(); + client.unbind((err3) => { + if (err3) console.error(err3) + done() + }) }); }); }) @@ -120,7 +123,10 @@ describe('_create_client', function () { pool._create_client(function (err, client) { assert.ifError(err); assert.ok(client._starttls.success); - done(); + client.unbind((err) => { + if (err) console.error(err) + done(); + }) }); }) }) @@ -173,7 +179,10 @@ describe('_bind_default', function () { const pool = new ldappool.LdapPool(this.cfg); pool._bind_default((err, client) => { assert.equal('InvalidDnSyntaxError', err.name); - done(); + client.unbind((err2) => { + assert.ifError(err2) + done(); + }) }); }) }) @@ -188,14 +197,14 @@ describe('get', () => { pool.get((err, client) => { assert.equal(null, err); assert.equal(1, pool.pool.servers.length); - assert.equal('ldap://127.0.0.1:3389', client?.urls[0].href); + assert.equal('ldap://localhost:3389', client?.urls[0].href); pool.get((err2, client2) => { assert.equal(null, err2); assert.equal(2, pool.pool.servers.length); - assert.equal('ldaps://127.0.0.1:3636', client2?.urls[0].href); + assert.equal('ldaps://localhost:3636', client2?.urls[0].href); pool.get((err3, client3) => { assert.equal(2, pool.pool.servers.length); - assert.equal('ldap://127.0.0.1:3389', client3?.urls[0].href); + assert.equal('ldap://localhost:3389', client3?.urls[0].href); done(); }) }) diff --git a/test/rcpt_to.js b/test/rcpt_to.js index 90fb034..0fcb746 100644 --- a/test/rcpt_to.js +++ b/test/rcpt_to.js @@ -20,7 +20,7 @@ function _set_up (done) { notes : { ldappool : new ldappool.LdapPool({ main : { - server : [ 'ldap://127.0.0.1:3389' ], + server : [ 'ldap://localhost:3389' ], binddn : this.user.dn, bindpw : this.user.password, basedn : 'dc=example,dc=com'