Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed Mar 15, 2024
1 parent 46b649e commit 80273b2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 2 additions & 4 deletions pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
7 changes: 3 additions & 4 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -29,15 +29,14 @@ 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'
}
})
}
};
done();
}

describe('handle_authn', function () {
Expand Down Expand Up @@ -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) {
Expand Down
29 changes: 19 additions & 10 deletions test/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -75,21 +75,21 @@ 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();
})

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();
Expand All @@ -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()
})
});
});
})
Expand All @@ -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();
})
});
})
})
Expand Down Expand Up @@ -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();
})
});
})
})
Expand All @@ -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();
})
})
Expand Down
2 changes: 1 addition & 1 deletion test/rcpt_to.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 80273b2

Please sign in to comment.