Skip to content

Commit

Permalink
test: update
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed Mar 15, 2024
1 parent 6af6710 commit 46b649e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 37 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"license": "MIT",
"devDependencies": {
"btoa": "*",
"eslint": "8.56.0",
"eslint": "8.57.0",
"eslint-plugin-haraka": "*",
"haraka-test-fixtures": "*",
"mocha": "9.0.0"
"mocha": "10.30.0"
},
"dependencies": {
"address-rfc2821": "*",
Expand Down
7 changes: 2 additions & 5 deletions pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ class LdapPool {
this.pool = { 'servers': [] };
}

_set_config (config) {
if (config === undefined)
config = {};
if (config.main === undefined)
config.main = {};
_set_config (config = {}) {
if (config.main === undefined) config.main = {};
this.config = {
servers: config.main.server || ['ldap://localhost:389'],
timeout: config.main.timeout,
Expand Down
17 changes: 12 additions & 5 deletions test/fixtures/macports/setup.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
#!/bin/sh

/usr/bin/sed -i -e '/^server/ s/:389/:3389/' -e 's/^server.*:636$/:3636/' config/ldap.ini
if [ ! -d "/var/tmp/slapd" ]; then mkdir /var/tmp/slapd; fi
rm -r /var/tmp/slapd/* || exit
set -e

/opt/local/sbin/slapadd -n 0 -F /var/tmp/slapd -l test/fixtures/macosx/slapd.ldif || exit
/usr/bin/sed -i.bak -e '/^server/ s/:389/:3389/' -e '/^server/ s/:636/:3636/' test/config/ldap.ini
if [ -d "/var/tmp/slapd" ]; then rm -rf /var/tmp/slapd; fi
if [ ! -d /var/run/slapd ]; then mkdir /var/run/slapd; fi
mkdir /var/tmp/slapd

/opt/local/libexec/slapd -f test/fixtures/macosx/slapd.conf -h "ldap://localhost:3389 ldaps://localhost:3636" &
if [ ! -x /opt/local/sbin/slapadd ]; then
sudo port install openldap
fi

/opt/local/sbin/slapadd -n 0 -F /var/tmp/slapd -l test/fixtures/macports/slapd.ldif

/opt/local/libexec/slapd -f test/fixtures/macports/slapd.conf -h "ldap://localhost:3389 ldaps://localhost:3636" &
sleep 3

/opt/local/bin/ldapadd -x -D "cn=admin,dc=example,dc=com" -w "rAR84,NZ=F" -H ldap://localhost:3389 -f test/env/testdata.ldif
47 changes: 22 additions & 25 deletions test/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ const testCfg = {
Object.freeze(testCfg)

function _set_up () {
this.user = testUser;
this.cfg = testCfg;
this.user = JSON.parse(JSON.stringify(testUser));
this.cfg = JSON.parse(JSON.stringify(testCfg))
}

describe('_set_config', () => {
beforeEach(_set_up);

it('defaults', (done) => {
const pool = new ldappool.LdapPool(testCfg);
it('defaults', function (done) {
const pool = new ldappool.LdapPool(this.cfg);
const config = pool._set_config();
assert.equal(pool._set_config().toString(), pool._set_config({}).toString());
assert.equal(['ldap://127.0.0.1:389'].toString(), config.servers.toString());
assert.equal(['ldap://localhost:389'].toString(), config.servers.toString());
assert.equal(undefined, config.timeout);
assert.equal(false, config.tls_enabled);
assert.equal(undefined, config.tls_rejectUnauthorized);
Expand All @@ -45,8 +45,8 @@ describe('_set_config', () => {
done()
})

it('userdef', () => {
const pool = new ldappool.LdapPool(testCfg);
it('userdef', function () {
const pool = new ldappool.LdapPool(this.cfg);
const cfg = { main : {
server : 'testserver',
timeout : 10000,
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('_get_ldapjs_config', function () {
})

it('userdef', function (done) {
const cfg = Object.assign({}, testCfg)
const cfg = Object.assign({}, this.cfg)
cfg.main.server = [ 'ldap://127.0.0.1:3389' ];
cfg.main.timeout = 42;
cfg.main.tls_rejectUnauthorized = true;
Expand Down Expand Up @@ -156,23 +156,21 @@ describe('_bind_default', function () {
});
})

it('bind with no binddn / bindpw', (done) => {
const cfg = JSON.parse(JSON.stringify(testCfg))
cfg.main.binddn = undefined;
cfg.main.bindpw = undefined;
it('bind with no binddn / bindpw', function (done) {
this.cfg.main.binddn = undefined;
this.cfg.main.bindpw = undefined;

const pool = new ldappool.LdapPool(cfg);
const pool = new ldappool.LdapPool(this.cfg);
pool._bind_default((err, client) => {
assert.equal(false, client.connected);
done();
})
})

it('bind with invalid binddn / bindpw', (done) => {
const cfg = JSON.parse(JSON.stringify(testCfg))
cfg.main.binddn = 'invalid';
cfg.main.bindpw = 'invalid';
const pool = new ldappool.LdapPool(cfg);
it('bind with invalid binddn / bindpw', function (done) {
this.cfg.main.binddn = 'invalid';
this.cfg.main.bindpw = 'invalid';
const pool = new ldappool.LdapPool(this.cfg);
pool._bind_default((err, client) => {
assert.equal('InvalidDnSyntaxError', err.name);
done();
Expand All @@ -183,25 +181,24 @@ describe('_bind_default', function () {
describe('get', () => {
beforeEach(_set_up);

it('test connection validity and pooling', (done) => {
const pool = new ldappool.LdapPool(testCfg);
it('test connection validity and pooling', function (done) {
const pool = new ldappool.LdapPool(this.cfg);
assert.equal(0, pool.pool.servers.length);

pool.get((err, client) => {
assert.equal(null, err);
assert.equal(1, pool.pool.servers.length);
assert.equal('ldap://127.0.0.1:3389', client?.url?.href);
assert.equal('ldap://127.0.0.1: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?.url?.href);
assert.equal('ldaps://127.0.0.1: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?.url?.href);
assert.equal('ldap://127.0.0.1:3389', client3?.urls[0].href);
done();
})
})
})
})

after(_set_up)
})

0 comments on commit 46b649e

Please sign in to comment.