From 479d78eb246881bee7f7f4c409ae12eb53690fb4 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Wed, 25 May 2022 13:08:55 -0700 Subject: [PATCH] feat: update for compat with redis 4 --- .codeclimate.yml | 4 ++-- .eslintrc.yaml | 1 + .gitignore | 2 ++ .travis.yml | 28 ------------------------ Changes.md | 9 ++++++++ appveyor.yml | 22 ------------------- index.js | 46 +++++++++++++++++----------------------- package.json | 9 ++++---- test/.eslintrc.json | 15 ------------- test/recipient-routes.js | 29 +++++++++++-------------- 10 files changed, 50 insertions(+), 115 deletions(-) delete mode 100644 .travis.yml delete mode 100644 appveyor.yml delete mode 100644 test/.eslintrc.json diff --git a/.codeclimate.yml b/.codeclimate.yml index 9e66e0a..63706e0 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,6 +1,6 @@ -plugins: +plugins: eslint: enabled: true - channel: "eslint-4" + channel: "eslint-8" config: config: ".eslintrc.yaml" diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 8ff22b3..6731f82 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -2,6 +2,7 @@ env: node: true es6: true mocha: true + es2020: true plugins: [ haraka ] diff --git a/.gitignore b/.gitignore index 5148e52..eba3cc2 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,5 @@ jspm_packages # Optional REPL history .node_repl_history + +package-lock.json \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7be7723..0000000 --- a/.travis.yml +++ /dev/null @@ -1,28 +0,0 @@ -language: node_js -node_js: - - "8" - - "10" - - "12" - -services: -# https://docs.travis-ci.com/user/database-setup/ -# - mongodb -# - elasticsearch - - redis-server - -before_script: - -script: - - npm run lint - - npm test - -after_success: -# -# enable codecov, which doesn't currently work for plugins because -# plugins are run in vm.runInNewContext() -# -# - npm install istanbul codecov -# - npm run cover -# - ./node_modules/.bin/codecov - -sudo: false diff --git a/Changes.md b/Changes.md index 7c4c7e3..2abd62b 100644 --- a/Changes.md +++ b/Changes.md @@ -1,18 +1,27 @@ +### 1.0.4 - 2022-05-24 + +- dep(eslint): 4 -> 8 +- dep(pi-redis): * -> 2 + + ### 1.0.3 - 2019-04-11 - test fix for unitialized redis config block + ### 1.0.2 - 2018-03-05 - for MX entries, previously only full email address matches in the file were parsed for LMTP/SMTP routes. Now all MX entries are parsed (email file, email domain, email redis, and domain redis) for URIs. - use es6 arrow functions - refactored the functions in rcpt() into separate functions (simplify, more testable) + ### 1.0.1 - 2017-08-19 - enable Redis install on AppVeyor CI testing + ### 1.0.0 - 2017-07-28 - imported from haraka/plugins/rcpt_to.routes diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 410e2c0..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,22 +0,0 @@ -environment: - nodejs_version: "8" - -install: - - ps: Install-Product node $env:nodejs_version - - npm install - - choco install redis-64 - - redis-server --service-install - - redis-server --service-start - -before_build: -build: off -after_build: - -before_test: - - node --version - - npm --version - -test_script: - - npm test - -after_test: diff --git a/index.js b/index.js index 1d46220..b5229d2 100644 --- a/index.js +++ b/index.js @@ -49,18 +49,18 @@ exports.do_file_search = function (txn, address, domain, next) { const plugin = this; if (plugin.route_list[address]) { - txn.results.add(plugin, {pass: 'file.email'}); + txn.results.add(plugin, { pass: 'file.email' }); return next(OK); } if (plugin.route_list[domain]) { - txn.results.add(plugin, {pass: 'file.domain'}); + txn.results.add(plugin, { pass: 'file.domain' }); return next(OK); } // not permitted (by this rcpt_to plugin) - txn.results.add(plugin, {fail: 'file'}); - return next(); + txn.results.add(plugin, { fail: 'file' }); + next(); } exports.get_rcpt_address = function (rcpt) { @@ -76,12 +76,8 @@ exports.do_redis_search = function (connection, address, domain, next) { plugin.db.multi() .get(address) .get(domain) - .exec((err, replies) => { - if (err) { - connection.results.add(plugin, {err: err}); - return next(); - } - + .exec() + .then(replies => { // got replies from Redis, any with an MX? if (replies[0]) { connection.transaction.results.add(plugin, {pass: 'redis.email'}); @@ -96,6 +92,10 @@ exports.do_redis_search = function (connection, address, domain, next) { plugin.do_file_search(connection.transaction, address, domain, next); } }) + .catch(err => { + connection.results.add(plugin, { err: err }); + next(); + }) } exports.rcpt = function (next, connection, params) { @@ -180,12 +180,8 @@ exports.get_mx = function (next, hmail, domain) { plugin.db.multi() .get(address) .get(domain) - .exec((err, replies) => { - if (err) { - plugin.logerror(err); - return next(); - } - + .exec() + .then(replies => { // got replies from Redis, any with an MX? if (replies[0]) return next(OK, plugin.parse_mx(replies[0])); if (replies[1]) return next(OK, plugin.parse_mx(replies[1])); @@ -193,6 +189,10 @@ exports.get_mx = function (next, hmail, domain) { // no redis record, try files plugin.get_mx_file(address, domain, next); }) + .catch(err => { + plugin.logerror(err); + next(); + }) } exports.insert_route = function (email, route) { @@ -202,16 +202,8 @@ exports.insert_route = function (email, route) { this.db.set(email, route); } -exports.delete_route = function (email, cb) { - if (!this.redis_pings) { - if (cb) cb(); - return false; - } +exports.delete_route = function (email) { + if (!this.redis_pings) return false; - if (cb) { - this.db.del(email, cb); - } - else { - this.db.del(email); - } + this.db.del(email); } diff --git a/package.json b/package.json index 0add38a..fc7c8cc 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,8 @@ "description": "Haraka plugin that validates and routes mail based on recipient domain or address", "main": "index.js", "scripts": { - "lint": "node node_modules/.bin/eslint *.js test/**/*.js", - "lintfix": "node node_modules/.bin/eslint --fix *.js test/**/*.js", + "lint": "npx eslint *.js test", + "lintfix": "npx eslint --fix *.js test", "test": "node run_tests" }, "repository": { @@ -24,13 +24,14 @@ }, "homepage": "https://github.com/haraka/haraka-plugin-recipient-routes#readme", "devDependencies": { - "eslint": ">=3", + "eslint": "8", "eslint-plugin-haraka": "*", "haraka-test-fixtures": "*", "nodeunit": "*" }, "dependencies": { - "haraka-plugin-redis": "*", + "haraka-plugin-redis": "2", + "redis": "4", "url": "^0.11.0" } } diff --git a/test/.eslintrc.json b/test/.eslintrc.json deleted file mode 100644 index 8d978a0..0000000 --- a/test/.eslintrc.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "env": { - "mocha": true, - "node": true, - "es6": true - }, - "globals": { - "OK": true, - "CONT": true, - "DENY": true, - "DENYSOFT": true, - "DENYDISCONNECT": true, - "DENYSOFTDISCONNECT": true - } -} diff --git a/test/recipient-routes.js b/test/recipient-routes.js index 39fc6c5..80f8713 100644 --- a/test/recipient-routes.js +++ b/test/recipient-routes.js @@ -33,44 +33,41 @@ function _set_up_file (done) { function _set_up_redis (done) { - this.server = {}; + this.server = { notes: { } }; + this.plugin = new fixtures.plugin('index'); + this.plugin.register() this.connection = fixtures.connection.createConnection(); this.connection.transaction = fixtures.transaction.createTransaction(); this.connection.transaction.results = new fixtures.results(this.connection); - this.plugin.register(); - this.plugin.server = { notes: { } }; if (this.plugin.redisCfg.opts === undefined) this.plugin.redisCfg.opts = {} this.plugin.redisCfg.opts.retry_strategy = function (options) { return; }; - const t = this; - this.plugin.init_redis_shared(function (err) { + this.plugin.init_redis_shared(err => { if (err) { console.error(err.message); return done(); } - t.plugin.db = t.plugin.server.notes.redis; - t.plugin.redis_ping(function (err2, result) { - if (err2) { - console.error(err2.message); - return done(); - } - done(err2, result); - }); - }, this.plugin.server); + this.plugin.db = this.server.notes.redis; + this.plugin.redis_ping().then(() => { + done() + }).catch(done) + }, this.server); } function _tear_down_redis (done) { - this.plugin.delete_route('matt@example.com', done); + this.plugin.delete_route('matt@example.com'); + done() } exports.rcpt_file = { setUp : _set_up_file, + tearDown : _tear_down_redis, 'miss' : function (test) { test.expect(2); function cb (rc, msg) { @@ -107,8 +104,6 @@ exports.rcpt_file = { } - - exports.rcpt_redis = { setUp : _set_up_redis, tearDown : _tear_down_redis,