diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 09eb772..8e8a0e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ name: CI -on: [ push ] +on: [ pull_request, push ] env: CI: true diff --git a/Changes.md b/Changes.md index 901591b..b11a178 100644 --- a/Changes.md +++ b/Changes.md @@ -1,6 +1,11 @@ ### Unreleased -- add redis enabled setting + +### [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 @@ -45,3 +50,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 +[1.2.0]: https://github.com/haraka/haraka-plugin-recipient-routes/releases/tag/1.2.0 diff --git a/index.js b/index.js index 549072f..60661ee 100644 --- a/index.js +++ b/index.js @@ -26,9 +26,9 @@ exports.register = function () { exports.load_rcpt_to_routes_ini = function () { const plugin = this; plugin.cfg = plugin.config.get('rcpt_to.routes.ini', { - booleans: [ - '+redis.enabled', - ], + booleans: [ + '+redis.enabled', + ], }, function () { plugin.load_rcpt_to_routes_ini(); @@ -45,8 +45,8 @@ exports.load_rcpt_to_routes_ini = function () { const lowered = {}; if (plugin.cfg.routes) { const keys = Object.keys(plugin.cfg.routes); - for (let i=0; i < keys.length; i++) { - lowered[keys[i].toLowerCase()] = plugin.cfg.routes[keys[i]]; + for (const key of keys) { + lowered[key.toLowerCase()] = plugin.cfg.routes[key]; } plugin.route_list = lowered; } diff --git a/package.json b/package.json index f6d4ac4..20a0fa6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "haraka-plugin-recipient-routes", - "version": "1.1.0", + "version": "1.2.0", "description": "Haraka plugin that validates and routes mail based on recipient domain or address", "main": "index.js", "scripts": { diff --git a/test/config/rcpt_to.routes.ini b/test/config/rcpt_to.routes.ini new file mode 100644 index 0000000..1816819 --- /dev/null +++ b/test/config/rcpt_to.routes.ini @@ -0,0 +1,11 @@ + +; [redis] +; host=127.0.0.1 +; port=6379 +; db=0 +; enabled=true + +[routes] +matt@example.com=192.168.76.66 +bad@example.com=127.0.0.1:26 +mixEd@examPle.com=172.16.1.1 diff --git a/test/recipient-routes.js b/test/recipient-routes.js index 70fafb5..28a24d2 100644 --- a/test/recipient-routes.js +++ b/test/recipient-routes.js @@ -1,6 +1,7 @@ 'use strict'; const assert = require('assert') +const path = require('path') const Address = require('address-rfc2821').Address; const fixtures = require('haraka-test-fixtures'); @@ -23,6 +24,7 @@ const hmail = { 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(); @@ -61,12 +63,10 @@ describe('haraka-plugin-recipient-routes', function () { assert.equal(rc, undefined); assert.equal(msg, undefined); done() - }, this.connection, [ new Address('') ]); + }, this.connection, [ new Address('') ]); }) it('hit returns OK', function (done) { - this.plugin.route_list = { 'matt@example.com': '192.168.1.1' }; - this.plugin.rcpt(function (rc, msg) { assert.equal(rc, OK); assert.equal(msg, undefined); @@ -75,7 +75,6 @@ describe('haraka-plugin-recipient-routes', function () { }) it('missing domain', function (done) { - this.plugin.route_list = { 'matt@example.com': '192.168.1.1' }; try { this.plugin.rcpt(function (rc, msg) { assert.ok(false) @@ -87,6 +86,14 @@ describe('haraka-plugin-recipient-routes', function () { done() } }) + + 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", + 'mixed@example.com': '172.16.1.1', + }) + }) }) describe('rcpt redis', function () {