Skip to content

Commit

Permalink
Release v1.1.0 (#27)
Browse files Browse the repository at this point in the history
* test: use async redis_ping
  • Loading branch information
msimerson authored Jan 18, 2023
1 parent 17ae5ae commit 68fd3a7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches:
- master
paths:
- package.json

env:
CI: true
Expand Down
8 changes: 8 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
7 changes: 2 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
48 changes: 18 additions & 30 deletions test/recipient-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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('<[email protected]>');
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('<[email protected]>');
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]);
})
})
Expand Down Expand Up @@ -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('<[email protected]>');
this.plugin.insert_route('[email protected]','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('<[email protected]>');
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('[email protected]','192.168.2.1');
this.plugin.insert_route( 'example.com','192.168.2.2');
const addr = new Address('<[email protected]>');

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('[email protected]');
this.plugin.delete_route( 'example.com');
}, hmail, addr.host);
Expand Down

0 comments on commit 68fd3a7

Please sign in to comment.