From 68fd3a7843112c6895dd61a3bf37bbfd573a6dff Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Wed, 18 Jan 2023 14:43:06 -0800 Subject: [PATCH] Release v1.1.0 (#27) * test: use async redis_ping --- .github/workflows/publish.yml | 2 ++ Changes.md | 8 ++++++ index.js | 7 ++--- package.json | 2 +- test/recipient-routes.js | 48 +++++++++++++---------------------- 5 files changed, 31 insertions(+), 36 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index d97a994..e81c15f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -4,6 +4,8 @@ on: push: branches: - master + paths: + - package.json env: CI: true diff --git a/Changes.md b/Changes.md index 01273c9..df3be59 100644 --- a/Changes.md +++ b/Changes.md @@ -1,6 +1,12 @@ ### Unreleased +### [1.1.0] - 2022-11-22 + +- fix: use this.redis_ping during runtime, #26 +- test: more async tests + + ### 1.0.4 - 2022-11-15 - fix: run redis_ping when registering, fixes #23 @@ -10,6 +16,7 @@ - dep(eslint): 4 -> 8 - dep(url): drop npm url package, use builtin - test: replace node_unit with mocha +- doc(README): update badge URLs ### 1.0.3 - 2019-04-11 @@ -36,3 +43,4 @@ [1.0.4]: https://github.com/haraka/haraka-plugin-recipient-routes/releases/tag/1.0.4 +[1.1.0]: https://github.com/haraka/haraka-plugin-recipient-routes/releases/tag/1.1.0 diff --git a/index.js b/index.js index d44509e..2b437e3 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,6 @@ exports.register = function () { this.load_rcpt_to_routes_ini(); this.merge_redis_ini(); - this.redis_ping(); this.register_hook('init_master', 'init_redis_plugin'); this.register_hook('init_child', 'init_redis_plugin'); @@ -106,12 +105,10 @@ exports.rcpt = async function (next, connection, params) { } // if we can't use redis, try files - if (!!this.db && ! await this.redis_ping() ) { + if (!this.db || ! await this.redis_ping() ) { return next(await this.do_file_search(txn, address, domain)); } - - // redis connection open, try it next(await this.do_redis_search(connection, address, domain)) } @@ -166,7 +163,7 @@ exports.get_mx = async function (next, hmail, domain) { } // if we can't use redis, try files and return - if (!! this.db && ! await this.redis_ping() ) { + if (! this.db || ! await this.redis_ping() ) { this.get_mx_file(address, domain, next); return; } diff --git a/package.json b/package.json index 547a230..f6d4ac4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "haraka-plugin-recipient-routes", - "version": "1.0.4", + "version": "1.1.0", "description": "Haraka plugin that validates and routes mail based on recipient domain or address", "main": "index.js", "scripts": { diff --git a/test/recipient-routes.js b/test/recipient-routes.js index 2188c83..70fafb5 100644 --- a/test/recipient-routes.js +++ b/test/recipient-routes.js @@ -45,16 +45,9 @@ function redis_setup (done) { if (this.plugin.redisCfg.opts === undefined) this.plugin.redisCfg.opts = {} this.plugin.redisCfg.opts.retry_strategy = function (options) { return; } - this.plugin.init_redis_shared(err => { - if (err) { - console.error(err.message); - return done(); - } - - this.plugin.db = this.server.notes.redis; - this.plugin.redis_ping().then(() => { - done() - }).catch(done) + this.plugin.init_redis_plugin(err => { + if (err) console.error(err.message) + done() }, this.server); } @@ -104,31 +97,29 @@ describe('haraka-plugin-recipient-routes', function () { this.plugin.db.quit() }) - it('miss returns undefined on null', function (done) { + it('miss returns undefined on null', async function () { const addr = new Address(''); - if (!this.plugin.redis_pings) { + if (! await this.plugin.redis_ping()) { console.error('ERROR: no redis available!'); - return done(); + return; } this.plugin.delete_route(addr.address()); this.plugin.rcpt((rc, msg) => { assert.equal(rc, undefined); assert.equal(msg, undefined); - done(); }, this.connection, [addr]); }) - it('hit returns OK', function (done) { - if (!this.plugin.redis_pings) return done(); + it('hit returns OK', async function () { + if (!await this.plugin.redis_ping()) return const addr = new Address(''); this.plugin.insert_route(addr.address(),'192.168.2.1'); - this.plugin.rcpt((rc, msg) => { + await this.plugin.rcpt((rc, msg) => { assert.equal(rc, OK); assert.equal(msg, undefined); - done(); }, this.connection, [addr]); }) }) @@ -178,43 +169,40 @@ describe('haraka-plugin-recipient-routes', function () { this.plugin.db.quit() }) - it('email address redis hit', function (done) { - if (!this.plugin.redis_pings) return done(); + it('email address redis hit', async function () { + if (! await this.plugin.redis_ping()) return const addr = new Address(''); this.plugin.insert_route('matt@example.com','192.168.2.1'); - this.plugin.get_mx((rc, mx) => { + await this.plugin.get_mx((rc, mx) => { assert.equal(rc, OK); assert.equal(mx, '192.168.2.1'); - done(); this.plugin.delete_route(addr.address()); }, hmail, addr.host); }) - it('email domain redis hit', function (done) { - if (!this.plugin.redis_pings) return done(); + it('email domain redis hit', async function () { + if (!await this.plugin.redis_ping()) return const addr = new Address(''); this.plugin.insert_route(addr.address(),'192.168.2.2'); - this.plugin.get_mx((rc, mx) => { + await this.plugin.get_mx((rc, mx) => { assert.equal(rc, OK); assert.equal(mx, '192.168.2.2'); - done(); this.plugin.delete_route(addr.address()); }, hmail, addr.host); }) - it('address preferred redis', function (done) { - if (!this.plugin.redis_pings) return done(); + it('address preferred redis', async function () { + if (!await this.plugin.redis_ping()) return this.plugin.insert_route('matt@example.com','192.168.2.1'); this.plugin.insert_route( 'example.com','192.168.2.2'); const addr = new Address(''); - this.plugin.get_mx((rc, mx) => { + await this.plugin.get_mx((rc, mx) => { assert.equal(rc, OK); assert.equal(mx, '192.168.2.1'); - done(); this.plugin.delete_route('matt@example.com'); this.plugin.delete_route( 'example.com'); }, hmail, addr.host);