From 6811603e33e6bdc261e273c74f784be55fb076ac Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Tue, 7 Jan 2025 16:02:29 -0800 Subject: [PATCH] Release v1.2.1 (#31) - doc(CHANGELOG): renamed from Changes - doc(CONTRIBUTORS): added - style: automated code formatting with prettier - ci: update local copy of ci.yml - dep(eslint): updated to v9 - dep: eslint-plugin-haraka -> @haraka/eslint-config - lint: remove duplicate / stale rules from .eslintrc - populate [files] in package.json. --- .codeclimate.yml | 4 +- .eslintrc.yaml | 22 --- .github/workflows/ci.yml | 33 +--- .github/workflows/codeql.yml | 4 +- .prettierrc | 2 + .release | 2 +- Changes.md | 19 +-- README.md | 6 +- eslint.config.mjs | 28 ++++ index.js | 164 +++++++++----------- package.json | 26 ++-- test/recipient-routes.js | 286 ++++++++++++++++++++--------------- 12 files changed, 307 insertions(+), 289 deletions(-) delete mode 100644 .eslintrc.yaml create mode 100644 .prettierrc create mode 100644 eslint.config.mjs diff --git a/.codeclimate.yml b/.codeclimate.yml index 63706e0..685e02e 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,6 +1,6 @@ plugins: eslint: enabled: true - channel: "eslint-8" + channel: 'eslint-9' config: - config: ".eslintrc.yaml" + config: 'eslint.config.mjs' diff --git a/.eslintrc.yaml b/.eslintrc.yaml deleted file mode 100644 index 3f51e95..0000000 --- a/.eslintrc.yaml +++ /dev/null @@ -1,22 +0,0 @@ -env: - node: true - es6: true - mocha: true - es2020: true - -plugins: [ haraka ] - -extends: [ eslint:recommended, plugin:haraka/recommended ] - -root: true - -rules: - indent: [2, 2, { SwitchCase: 1 } ] - -globals: - OK: true - CONT: true - DENY: true - DENYSOFT: true - DENYDISCONNECT: true - DENYSOFTDISCONNECT: true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8e8a0e2..79b3073 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,41 +1,14 @@ name: CI -on: [ pull_request, push ] +on: [pull_request, push] env: CI: true jobs: - lint: uses: haraka/.github/.github/workflows/lint.yml@master - # coverage: - # uses: haraka/.github/.github/workflows/coverage.yml@master - # secrets: inherit - test: - needs: lint - runs-on: ${{ matrix.os }} - services: - redis: - image: redis - ports: - - 6379:6379 - strategy: - matrix: - os: [ ubuntu-latest ] - node-version: [ 16, 18 ] - fail-fast: false - - steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-node@v3 - name: Node ${{ matrix.node-version }} on ${{ matrix.os }} - with: - node-version: ${{ matrix.node-version }} - - - run: npm install - - run: npm test - + needs: [lint] + uses: haraka/.github/.github/workflows/ubuntu.yml@master diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 3627451..8314a66 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -2,10 +2,10 @@ name: CodeQL on: push: - branches: [ master ] + branches: [master] pull_request: # The branches below must be a subset of the branches above - branches: [ master ] + branches: [master] schedule: - cron: '18 7 * * 4' diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..8ded5e0 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,2 @@ +singleQuote: true +semi: false diff --git a/.release b/.release index 0890e94..0bf2a09 160000 --- a/.release +++ b/.release @@ -1 +1 @@ -Subproject commit 0890e945e4e061c96c7b2ab45017525904c17728 +Subproject commit 0bf2a098d4792848c2103dfce0f911e00a14709e diff --git a/Changes.md b/Changes.md index b11a178..41bb2df 100644 --- a/Changes.md +++ b/Changes.md @@ -1,53 +1,54 @@ ### Unreleased +### [1.2.1] - 2025-01-07 + +- style: automated code formatting with prettier +- ci: update local copy of ci.yml +- dep(eslint): updated to v9 +- dep: eslint-plugin-haraka -> @haraka/eslint-config +- lint: remove duplicate / stale rules from .eslintrc +- populate [files] in package.json. ### [1.2.0] - 2023-03-29 - maint: replace for..i iterator with for..of, add test - feat: add redis enabled setting, #28 - ### [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 - ci: replace travis/appveyor with GHA - dep(redis): 2 -> 4 -- dep(pi-redis): * -> 2 +- dep(pi-redis): \* -> 2 - 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 - 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 - - [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 [1.2.0]: https://github.com/haraka/haraka-plugin-recipient-routes/releases/tag/1.2.0 +[1.2.1]: https://github.com/haraka/haraka-plugin-recipient-routes/releases/tag/1.2.1 diff --git a/README.md b/README.md index 1425e61..db5b87c 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ Recipient Routes does recipient validation and MX routing. [![Code Climate][clim-img]][clim-url] [![NPM][npm-img]][npm-url] - ## Recipient Validation Recipients can be listed in the [routes] section of the config file @@ -29,7 +28,7 @@ rejected. ## MX Routing -NOTE: MX routing by default routes *only* based on domains. To route for email +NOTE: MX routing by default routes _only_ based on domains. To route for email addresses, you must set the preference `always_split=true` in 'config/outbound.ini'. @@ -93,12 +92,11 @@ Matt Simerson. Underwritten and graciously donated to the Haraka community by [Serious Mumbo, Inc.](http://seriousmumbo.com) - + [ci-img]: https://github.com/haraka/haraka-plugin-recipient-routes/actions/workflows/ci.yml/badge.svg [ci-url]: https://github.com/haraka/haraka-plugin-recipient-routes/actions/workflows/ci.yml [clim-img]: https://codeclimate.com/github/haraka/haraka-plugin-recipient-routes/badges/gpa.svg [clim-url]: https://codeclimate.com/github/haraka/haraka-plugin-recipient-routes [npm-img]: https://nodei.co/npm/haraka-plugin-recipient-routes.png [npm-url]: https://www.npmjs.com/package/haraka-plugin-recipient-routes - diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..507e7c5 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,28 @@ +import globals from 'globals' +import path from 'node:path' +import { fileURLToPath } from 'node:url' +import js from '@eslint/js' +import { FlatCompat } from '@eslint/eslintrc' + +const __filename = fileURLToPath(import.meta.url) +const __dirname = path.dirname(__filename) +const compat = new FlatCompat({ + baseDirectory: __dirname, + recommendedConfig: js.configs.recommended, + allConfig: js.configs.all, +}) + +export default [ + ...compat.extends('@haraka'), + { + languageOptions: { + globals: { + ...globals.node, + ...globals.mocha, + }, + }, + rules: { + 'no-unused-vars': 'warn', + }, + }, +] diff --git a/index.js b/index.js index 60661ee..4de3865 100644 --- a/index.js +++ b/index.js @@ -3,38 +3,39 @@ // validates incoming recipients against flat file & Redis // routes mail based on per-email or per-domain specified routes -const urlparser = require('url'); +const urlparser = require('url') exports.register = function () { - this.inherits('haraka-plugin-redis'); + this.inherits('haraka-plugin-redis') - this.cfg = {}; - this.route_list={}; + this.cfg = {} + this.route_list = {} - this.load_rcpt_to_routes_ini(); + this.load_rcpt_to_routes_ini() if (this.cfg.redis.opts.enabled) { - this.merge_redis_ini(); + this.merge_redis_ini() - this.register_hook('init_master', 'init_redis_plugin'); - this.register_hook('init_child', 'init_redis_plugin'); + this.register_hook('init_master', 'init_redis_plugin') + this.register_hook('init_child', 'init_redis_plugin') } - this.register_hook('rcpt', 'rcpt'); - this.register_hook('get_mx', 'get_mx'); + this.register_hook('rcpt', 'rcpt') + this.register_hook('get_mx', 'get_mx') } exports.load_rcpt_to_routes_ini = function () { - const plugin = this; - plugin.cfg = plugin.config.get('rcpt_to.routes.ini', { - booleans: [ - '+redis.enabled', - ], - }, - function () { - plugin.load_rcpt_to_routes_ini(); - }) - - if (!plugin.cfg.redis) plugin.cfg.redis = {}; + const plugin = this + plugin.cfg = plugin.config.get( + 'rcpt_to.routes.ini', + { + booleans: ['+redis.enabled'], + }, + function () { + plugin.load_rcpt_to_routes_ini() + }, + ) + + if (!plugin.cfg.redis) plugin.cfg.redis = {} plugin.cfg.redis.opts = { host: plugin.cfg.redis.server_ip || plugin.cfg.redis.host || '127.0.0.1', @@ -42,79 +43,71 @@ exports.load_rcpt_to_routes_ini = function () { enabled: plugin.cfg.redis.enabled ?? true, } - const lowered = {}; + const lowered = {} if (plugin.cfg.routes) { - const keys = Object.keys(plugin.cfg.routes); - for (const key of keys) { - lowered[key.toLowerCase()] = plugin.cfg.routes[key]; + for (const key of Object.keys(plugin.cfg.routes)) { + lowered[key.toLowerCase()] = plugin.cfg.routes[key] } - plugin.route_list = lowered; + plugin.route_list = lowered } } exports.do_file_search = async function (txn, address, domain) { - if (this.route_list[address]) { - txn.results.add(this, { pass: 'file.email' }); + txn.results.add(this, { pass: 'file.email' }) return OK } - if (this.route_list[domain]) { - txn.results.add(this, { pass: 'file.domain' }); + if (this.route_list[domain]) { + txn.results.add(this, { pass: 'file.domain' }) return OK } // not permitted (by this rcpt_to plugin) - txn.results.add(this, { fail: 'file' }); + txn.results.add(this, { fail: 'file' }) } exports.get_rcpt_address = function (rcpt) { + if (!rcpt.host) return [rcpt.address().toLowerCase()] - if (!rcpt.host) return [ rcpt.address().toLowerCase() ]; - - return [ rcpt.address().toLowerCase(), rcpt.host.toLowerCase() ]; + return [rcpt.address().toLowerCase(), rcpt.host.toLowerCase()] } exports.do_redis_search = async function (connection, address, domain) { - - const replies = await this.db.multi() - .get(address) - .get(domain) - .exec() + const replies = await this.db.multi().get(address).get(domain).exec() try { // any replies from Redis with an MX? if (replies[0]) { - connection.transaction.results.add(this, {pass: 'redis.email'}); - return OK; + connection.transaction.results.add(this, { pass: 'redis.email' }) + return OK } if (replies[1]) { - connection.transaction.results.add(this, {pass: 'redis.domain'}); + connection.transaction.results.add(this, { pass: 'redis.domain' }) return OK } // no redis record, try files - return await this.do_file_search(connection.transaction, address, domain); - } - catch (err) { - connection.results.add(this, { err }); + return await this.do_file_search(connection.transaction, address, domain) + } catch (err) { + connection.results.add(this, { err }) } } exports.rcpt = async function (next, connection, params) { + const txn = connection.transaction + if (!txn) return next() - const txn = connection.transaction; - if (!txn) return next(); - - const [address, domain] = this.get_rcpt_address(params[0]); - if (!domain) { // ignore RCPT TO without an @ - txn.results.add(this, {fail: 'rcpt!domain'}); - return next(); + const [address, domain] = this.get_rcpt_address(params[0]) + if (!domain) { + // ignore RCPT TO without an @ + txn.results.add(this, { fail: 'rcpt!domain' }) + return next() } // if we can't use redis, try files - if (!this.cfg.redis.opts.enabled || !this.db || !await this.redis_ping()) { - return next(await this.do_file_search(txn, address, domain)); + if (!this.cfg.redis.opts.enabled || !this.db || !(await this.redis_ping())) { + return next(await this.do_file_search(txn, address, domain)) } // redis connection open, try it @@ -122,10 +115,9 @@ exports.rcpt = async function (next, connection, params) { } exports.parse_mx = function (entry) { + const uri = new urlparser.parse(entry) - const uri = new urlparser.parse(entry); - - if ( uri.protocol == 'lmtp:' ) { + if (uri.protocol == 'lmtp:') { return { exchange: uri.hostname, port: uri.port, @@ -133,78 +125,72 @@ exports.parse_mx = function (entry) { } } - if ( uri.protocol == 'smtp:' ) { + if (uri.protocol == 'smtp:') { return { exchange: uri.hostname, port: uri.port, } } - return entry; + return entry } exports.get_mx_file = function (address, domain, next) { - // check email adress for route if (this.route_list[address]) { - return next(OK, this.parse_mx(this.route_list[address])); + return next(OK, this.parse_mx(this.route_list[address])) } // check email domain for route if (this.route_list[domain]) { - return next(OK, this.parse_mx(this.route_list[domain])); + return next(OK, this.parse_mx(this.route_list[domain])) } - this.loginfo(`using DNS MX for: ${address}`); - next(); + this.loginfo(`using DNS MX for: ${address}`) + next() } exports.get_mx = async function (next, hmail, domain) { - // get email address - let address = domain.toLowerCase(); + let address = domain.toLowerCase() if (hmail && hmail.todo && hmail.todo.rcpt_to && hmail.todo.rcpt_to[0]) { - address = hmail.todo.rcpt_to[0].address().toLowerCase(); - } - else { - this.logerror('no rcpt from hmail, using domain' ); + address = hmail.todo.rcpt_to[0].address().toLowerCase() + } else { + this.logerror('no rcpt from hmail, using domain') } // if we can't use redis, try files and return - if (!this.cfg.redis.opts.enabled || !this.db || !await this.redis_ping()) { - this.get_mx_file(address, domain, next); - return; + if (!this.cfg.redis.opts.enabled || !this.db || !(await this.redis_ping())) { + this.get_mx_file(address, domain, next) + return } // redis connection open, try it - const replies = await this.db.multi() - .get(address) - .get(domain) - .exec() + const replies = await this.db.multi().get(address).get(domain).exec() try { // got replies from Redis, any with an MX? - if (replies[0]) return next(OK, this.parse_mx(replies[0])); - if (replies[1]) return next(OK, this.parse_mx(replies[1])); + if (replies[0]) return next(OK, this.parse_mx(replies[0])) + if (replies[1]) return next(OK, this.parse_mx(replies[1])) // no redis record, try files - this.get_mx_file(address, domain, next); - } - catch (err) { - this.logerror(err); - next(); + this.get_mx_file(address, domain, next) + } catch (err) { + this.logerror(err) + next() } } exports.insert_route = function (email, route) { // for importing, see http://redis.io/topics/mass-insert - if (!this.cfg.redis.opts.enabled || !this.db || !this.redis_pings) return false; + if (!this.cfg.redis.opts.enabled || !this.db || !this.redis_pings) + return false - this.db.set(email, route); + this.db.set(email, route) } exports.delete_route = function (email) { - if (!this.cfg.redis.opts.enabled || !this.redis_pings) return false; + if (!this.cfg.redis.opts.enabled || !this.redis_pings) return false - this.db.del(email); + this.db.del(email) } diff --git a/package.json b/package.json index 20a0fa6..6f30cd8 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,21 @@ { "name": "haraka-plugin-recipient-routes", - "version": "1.2.0", + "version": "1.2.1", "description": "Haraka plugin that validates and routes mail based on recipient domain or address", + "files": [ + "CHANGELOG.md", + "config" + ], "main": "index.js", "scripts": { + "format": "npm run prettier:fix && npm run lint:fix", "lint": "npx eslint *.js test", - "lintfix": "npx eslint --fix *.js test", + "lint:fix": "npx eslint *.js test --fix", + "prettier": "npx prettier . --check", + "prettier:fix": "npx prettier . --write --log-level=warn", "test": "npx mocha", - "versions": "npx dependency-version-checker check" + "versions": "npx dependency-version-checker check", + "versions:fix": "npx dependency-version-checker update" }, "repository": { "type": "git", @@ -25,13 +33,13 @@ }, "homepage": "https://github.com/haraka/haraka-plugin-recipient-routes#readme", "devDependencies": { - "eslint": "8", - "eslint-plugin-haraka": "*", - "haraka-test-fixtures": "*", - "mocha": "9" + "eslint": "9.17.0", + "@haraka/eslint-config": "2.0.2", + "haraka-test-fixtures": "1.3.8", + "mocha": "11.1.0" }, "dependencies": { - "haraka-plugin-redis": "2", - "redis": "4" + "haraka-plugin-redis": "2.0.8", + "redis": "4.7.0" } } diff --git a/test/recipient-routes.js b/test/recipient-routes.js index 28a24d2..f748370 100644 --- a/test/recipient-routes.js +++ b/test/recipient-routes.js @@ -1,87 +1,100 @@ -'use strict'; +'use strict' -const assert = require('assert') -const path = require('path') +const assert = require('assert') +const path = require('path') -const Address = require('address-rfc2821').Address; -const fixtures = require('haraka-test-fixtures'); +const Address = require('address-rfc2821').Address +const fixtures = require('haraka-test-fixtures') const hmail = { todo: { - "queue_time":1402091363826, - "domain":"example.com", - "rcpt_to":[ new Address('matt@example.com') ], - "mail_from": new Address('<>'), - "notes": { - authentication_results: [ 'spf=pass smtp.mailfrom=example.net' ], + queue_time: 1402091363826, + domain: 'example.com', + rcpt_to: [new Address('matt@example.com')], + mail_from: new Address('<>'), + notes: { + authentication_results: ['spf=pass smtp.mailfrom=example.net'], spf_mail_result: 'Pass', local_sender: true, }, - "uuid":"DFB28F2B-CC21-438B-864D-934E6860AB61.1", + uuid: 'DFB28F2B-CC21-438B-864D-934E6860AB61.1', }, -}; +} -function file_setup (done) { - this.server = {}; - this.plugin = new fixtures.plugin('index'); - this.plugin.config = this.plugin.config.module_config(path.resolve('test')); +function file_setup(done) { + this.server = {} + this.plugin = new fixtures.plugin('index') + this.plugin.config = this.plugin.config.module_config(path.resolve('test')) - 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.connection = fixtures.connection.createConnection() + this.connection.transaction = fixtures.transaction.createTransaction() + this.connection.transaction.results = new fixtures.results(this.connection) done() } -function redis_setup (done) { - this.server = { notes: { } }; +function redis_setup(done) { + this.server = { notes: {} } - this.plugin = new fixtures.plugin('index'); - this.plugin.register(); + 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.connection = fixtures.connection.createConnection() + this.connection.transaction = fixtures.transaction.createTransaction() + this.connection.transaction.results = new fixtures.results(this.connection) if (this.plugin.redisCfg.opts === undefined) this.plugin.redisCfg.opts = {} - this.plugin.redisCfg.opts.retry_strategy = function (options) { return; } + this.plugin.redisCfg.opts.retry_strategy = function () { + return + } - this.plugin.init_redis_plugin(err => { + this.plugin.init_redis_plugin((err) => { if (err) console.error(err.message) done() - }, this.server); + }, this.server) } describe('haraka-plugin-recipient-routes', function () { - describe('rcpt file', function () { beforeEach(file_setup) it('miss returns undefined on null', function (done) { - this.plugin.rcpt(function (rc, msg) { - assert.equal(rc, undefined); - assert.equal(msg, undefined); - done() - }, this.connection, [ new Address('') ]); + this.plugin.rcpt( + function (rc, msg) { + assert.equal(rc, undefined) + assert.equal(msg, undefined) + done() + }, + this.connection, + [new Address('')], + ) }) it('hit returns OK', function (done) { - this.plugin.rcpt(function (rc, msg) { - assert.equal(rc, OK); - assert.equal(msg, undefined); - done() - }, this.connection, [new Address('')]); + this.plugin.rcpt( + function (rc, msg) { + assert.equal(rc, OK) + assert.equal(msg, undefined) + done() + }, + this.connection, + [new Address('')], + ) }) it('missing domain', function (done) { try { - this.plugin.rcpt(function (rc, msg) { - assert.ok(false) - done() - }, this.connection, [ new Address('')] ); - } - catch (e) { + this.plugin.rcpt( + function () { + assert.ok(false) + done() + }, + this.connection, + [new Address('')], + ) + } catch (ignore) { + // console.error(ignore) // an error is expected done() } @@ -89,8 +102,8 @@ describe('haraka-plugin-recipient-routes', function () { it('lowers mixed case routes', function () { assert.deepEqual(this.plugin.route_list, { - "bad@example.com": "127.0.0.1:26", - "matt@example.com": "192.168.76.66", + 'bad@example.com': '127.0.0.1:26', + 'matt@example.com': '192.168.76.66', 'mixed@example.com': '172.16.1.1', }) }) @@ -100,34 +113,41 @@ describe('haraka-plugin-recipient-routes', function () { beforeEach(redis_setup) afterEach(function () { - this.plugin.delete_route('matt@example.com'); + this.plugin.delete_route('matt@example.com') this.plugin.db.quit() }) it('miss returns undefined on null', async function () { - - const addr = new Address(''); - if (! await this.plugin.redis_ping()) { - console.error('ERROR: no redis available!'); - return; + const addr = new Address('') + if (!(await this.plugin.redis_ping())) { + console.error('ERROR: no redis available!') + return } - this.plugin.delete_route(addr.address()); - this.plugin.rcpt((rc, msg) => { - assert.equal(rc, undefined); - assert.equal(msg, undefined); - }, this.connection, [addr]); + this.plugin.delete_route(addr.address()) + this.plugin.rcpt( + (rc, msg) => { + assert.equal(rc, undefined) + assert.equal(msg, undefined) + }, + this.connection, + [addr], + ) }) 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'); - await this.plugin.rcpt((rc, msg) => { - assert.equal(rc, OK); - assert.equal(msg, undefined); - }, this.connection, [addr]); + if (!(await this.plugin.redis_ping())) return + + const addr = new Address('') + this.plugin.insert_route(addr.address(), '192.168.2.1') + await this.plugin.rcpt( + (rc, msg) => { + assert.equal(rc, OK) + assert.equal(msg, undefined) + }, + this.connection, + [addr], + ) }) }) @@ -135,36 +155,48 @@ describe('haraka-plugin-recipient-routes', function () { beforeEach(file_setup) it('email address file hit', function (done) { - this.plugin.route_list = {'matt@example.com': '192.168.1.1'}; - const addr = new Address(''); - this.plugin.get_mx((rc, mx) => { - assert.equal(rc, OK); - assert.equal(mx, '192.168.1.1'); - done(); - }, hmail, addr.host); + this.plugin.route_list = { 'matt@example.com': '192.168.1.1' } + const addr = new Address('') + this.plugin.get_mx( + (rc, mx) => { + assert.equal(rc, OK) + assert.equal(mx, '192.168.1.1') + done() + }, + hmail, + addr.host, + ) }) it('email domain file hit', function (done) { - this.plugin.route_list = {'example.com': '192.168.1.2'}; - const addr = new Address(''); - this.plugin.get_mx((rc, mx) => { - assert.equal(rc, OK); - assert.equal(mx, '192.168.1.2'); - done(); - }, hmail, addr.host); + this.plugin.route_list = { 'example.com': '192.168.1.2' } + const addr = new Address('') + this.plugin.get_mx( + (rc, mx) => { + assert.equal(rc, OK) + assert.equal(mx, '192.168.1.2') + done() + }, + hmail, + addr.host, + ) }) it('address preferred file', function (done) { this.plugin.route_list = { 'matt@example.com': '192.168.1.1', 'example.com': '192.168.1.2', - }; - const addr = new Address(''); - this.plugin.get_mx((rc, mx) => { - assert.equal(rc, OK); - assert.equal(mx, '192.168.1.1'); - done(); - }, hmail, addr.host); + } + const addr = new Address('') + this.plugin.get_mx( + (rc, mx) => { + assert.equal(rc, OK) + assert.equal(mx, '192.168.1.1') + done() + }, + hmail, + addr.host, + ) }) }) @@ -172,47 +204,59 @@ describe('haraka-plugin-recipient-routes', function () { beforeEach(redis_setup) afterEach(function () { - this.plugin.delete_route('matt@example.com'); + this.plugin.delete_route('matt@example.com') this.plugin.db.quit() }) 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'); - await this.plugin.get_mx((rc, mx) => { - assert.equal(rc, OK); - assert.equal(mx, '192.168.2.1'); - this.plugin.delete_route(addr.address()); - }, hmail, addr.host); + if (!(await this.plugin.redis_ping())) return + + const addr = new Address('') + this.plugin.insert_route('matt@example.com', '192.168.2.1') + await this.plugin.get_mx( + (rc, mx) => { + assert.equal(rc, OK) + assert.equal(mx, '192.168.2.1') + this.plugin.delete_route(addr.address()) + }, + hmail, + addr.host, + ) }) 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'); - await this.plugin.get_mx((rc, mx) => { - assert.equal(rc, OK); - assert.equal(mx, '192.168.2.2'); - this.plugin.delete_route(addr.address()); - }, hmail, addr.host); + if (!(await this.plugin.redis_ping())) return + + const addr = new Address('') + this.plugin.insert_route(addr.address(), '192.168.2.2') + await this.plugin.get_mx( + (rc, mx) => { + assert.equal(rc, OK) + assert.equal(mx, '192.168.2.2') + this.plugin.delete_route(addr.address()) + }, + hmail, + addr.host, + ) }) 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(''); - - await this.plugin.get_mx((rc, mx) => { - assert.equal(rc, OK); - assert.equal(mx, '192.168.2.1'); - this.plugin.delete_route('matt@example.com'); - this.plugin.delete_route( 'example.com'); - }, hmail, addr.host); + 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('') + + await this.plugin.get_mx( + (rc, mx) => { + assert.equal(rc, OK) + assert.equal(mx, '192.168.2.1') + this.plugin.delete_route('matt@example.com') + this.plugin.delete_route('example.com') + }, + hmail, + addr.host, + ) }) }) })