From 46b649e34d98497ca205f40d995b821cd8cd713d Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Fri, 15 Mar 2024 11:04:23 -0700 Subject: [PATCH] test: update --- package.json | 4 +-- pool.js | 7 ++--- test/fixtures/macports/setup.sh | 17 ++++++++---- test/pool.js | 47 +++++++++++++++------------------ 4 files changed, 38 insertions(+), 37 deletions(-) diff --git a/package.json b/package.json index 2d7358d..e997abb 100644 --- a/package.json +++ b/package.json @@ -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": "*", diff --git a/pool.js b/pool.js index a7af1a4..faae41e 100644 --- a/pool.js +++ b/pool.js @@ -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, diff --git a/test/fixtures/macports/setup.sh b/test/fixtures/macports/setup.sh index 8c0c1e5..85c2964 100644 --- a/test/fixtures/macports/setup.sh +++ b/test/fixtures/macports/setup.sh @@ -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 diff --git a/test/pool.js b/test/pool.js index 668f3c2..7bf0c62 100644 --- a/test/pool.js +++ b/test/pool.js @@ -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); @@ -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, @@ -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; @@ -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(); @@ -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) })