Skip to content

Commit

Permalink
release 1.2.1
Browse files Browse the repository at this point in the history
- fix: call skip_hosts via 'this' instead of exports haraka#11
- es6: replace `plugin` with `this` haraka#12
- deps: bump versions to latest
  • Loading branch information
msimerson authored Jun 20, 2023
1 parent 0f7a23f commit 7d40ab9
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI

on: [ push ]
on: [ push, pull_request ]

env:
CI: true
Expand Down
10 changes: 9 additions & 1 deletion Changes.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@

### Unreleased

- Fix bug where skip configuration was ignored

### [1.2.1] - 2023-06-19

- fix: call skip_hosts via 'this' instead of exports (#11)
- skip configuration was being ignored
- es6: replace `plugin` with `this`
- deps: bump versions to latest


### [1.2.0] - 2023-01-19

Expand Down Expand Up @@ -44,3 +51,4 @@
[1.1.2]: https://github.com/haraka/haraka-plugin-spf/releases/tag/1.1.2
[1.1.3]: https://github.com/haraka/haraka-plugin-spf/releases/tag/1.1.3
[1.2.0]: https://github.com/haraka/haraka-plugin-spf/releases/tag/1.2.0
[1.2.1]: https://github.com/haraka/haraka-plugin-spf/releases/tag/1.2.1
68 changes: 31 additions & 37 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,21 @@ const DSN = require('haraka-dsn');
exports.SPF = SPF;

exports.register = function () {
const plugin = this;

// Override logging in SPF module
SPF.prototype.log_debug = str => plugin.logdebug(str);
SPF.prototype.log_debug = str => this.logdebug(str);

plugin.load_spf_ini();
this.load_spf_ini();

plugin.register_hook('helo', 'helo_spf');
plugin.register_hook('ehlo', 'helo_spf');
this.register_hook('helo', 'helo_spf');
this.register_hook('ehlo', 'helo_spf');
}

exports.load_spf_ini = function () {
const plugin = this;
plugin.nu = net_utils; // so tests can set public_ip
plugin.SPF = SPF;
this.nu = net_utils; // so tests can set public_ip
this.SPF = SPF;

plugin.cfg = plugin.config.get('spf.ini', {
this.cfg = this.config.get('spf.ini', {
booleans: [
'-defer.helo_temperror',
'-defer.mfrom_temperror',
Expand Down Expand Up @@ -57,30 +55,30 @@ exports.load_spf_ini = function () {
'-skip.auth',
]
},
() => { plugin.load_spf_ini(); }
() => { this.load_spf_ini(); }
);

// when set, preserve legacy config settings
['helo','mail'].forEach(phase => {
if (plugin.cfg.main[`${phase}_softfail_reject`]) {
plugin.cfg.deny[`${phase}_softfail`] = true;
for (const phase of ['helo','mail']) {
if (this.cfg.main[`${phase}_softfail_reject`]) {
this.cfg.deny[`${phase}_softfail`] = true;
}
if (plugin.cfg.main[`${phase}_fail_reject`]) {
plugin.cfg.deny[`${phase}_fail`] = true;
if (this.cfg.main[`${phase}_fail_reject`]) {
this.cfg.deny[`${phase}_fail`] = true;
}
if (plugin.cfg.main[`${phase}_temperror_defer`]) {
plugin.cfg.defer[`${phase}_temperror`] = true;
if (this.cfg.main[`${phase}_temperror_defer`]) {
this.cfg.defer[`${phase}_temperror`] = true;
}
if (plugin.cfg.main[`${phase}_permerror_reject`]) {
plugin.cfg.deny[`${phase}_permerror`] = true;
if (this.cfg.main[`${phase}_permerror_reject`]) {
this.cfg.deny[`${phase}_permerror`] = true;
}
});
}

if (!plugin.cfg.relay) {
plugin.cfg.relay = { context: 'sender' }; // default/legacy
if (!this.cfg.relay) {
this.cfg.relay = { context: 'sender' }; // default/legacy
}

plugin.cfg.lookup_timeout = plugin.cfg.main.lookup_timeout || plugin.timeout - 1;
this.cfg.lookup_timeout = this.cfg.main.lookup_timeout || this.timeout - 1;
}

exports.helo_spf = async function (next, connection, helo) {
Expand Down Expand Up @@ -222,7 +220,6 @@ exports.hook_mail = async function (next, connection, params) {
// if we check the public IP first. Only check the public IP if the
// client IP returns a result other than 'Pass'.
const result = await spf.check_host(connection.remote.ip, host, mfrom)

// typical inbound (!relay)
if (!connection.relaying) return ch_cb(null, result)

Expand All @@ -231,7 +228,6 @@ exports.hook_mail = async function (next, connection, params) {

// outbound (relaying), context=myself
const my_public_ip = await net_utils.get_public_ip()

let spf_result;
if (result) spf_result = spf.result(result).toLowerCase();

Expand All @@ -256,7 +252,6 @@ exports.log_result = function (connection, scope, host, mfrom, result, ip) {
}

exports.return_results = function (next, connection, spf, scope, result, sender) {
const plugin = this;
const msgpre = (scope === 'helo') ? `sender ${sender}` : `sender <${sender}>`;
const deny = connection.relaying ? 'deny_relay' : 'deny';
const defer = connection.relaying ? 'defer_relay' : 'defer';
Expand All @@ -265,39 +260,39 @@ exports.return_results = function (next, connection, spf, scope, result, sender)

switch (result) {
case spf.SPF_NONE:
if (plugin.cfg[deny][`${scope}_none`]) {
text = plugin.cfg[deny].openspf_text ? text : `${msgpre} SPF record not found`;
if (this.cfg[deny][`${scope}_none`]) {
text = this.cfg[deny].openspf_text ? text : `${msgpre} SPF record not found`;
return next(DENY, text);
}
return next();
case spf.SPF_NEUTRAL:
case spf.SPF_PASS:
return next();
case spf.SPF_SOFTFAIL:
if (plugin.cfg[deny][`${scope}_softfail`]) {
text = plugin.cfg[deny].openspf_text ? text : `${msgpre} SPF SoftFail`;
if (this.cfg[deny][`${scope}_softfail`]) {
text = this.cfg[deny].openspf_text ? text : `${msgpre} SPF SoftFail`;
return next(DENY, text);
}
return next();
case spf.SPF_FAIL:
if (plugin.cfg[deny][`${scope}_fail`]) {
text = plugin.cfg[deny].openspf_text ? text : `${msgpre} SPF Fail`;
if (this.cfg[deny][`${scope}_fail`]) {
text = this.cfg[deny].openspf_text ? text : `${msgpre} SPF Fail`;
return next(DENY, text);
}
return next();
case spf.SPF_TEMPERROR:
if (plugin.cfg[defer][`${scope}_temperror`]) {
if (this.cfg[defer][`${scope}_temperror`]) {
return next(DENYSOFT, `${msgpre} SPF Temporary Error`);
}
return next();
case spf.SPF_PERMERROR:
if (plugin.cfg[deny][`${scope}_permerror`]) {
if (this.cfg[deny][`${scope}_permerror`]) {
return next(DENY, `${msgpre} SPF Permanent Error`);
}
return next();
default:
// Unknown result
connection.logerror(plugin, `unknown result code=${result}`);
connection.logerror(this, `unknown result code=${result}`);
return next();
}
}
Expand All @@ -314,9 +309,8 @@ exports.save_to_header = (connection, spf, result, mfrom, host, id, ip) => {
}

exports.skip_hosts = function (connection) {
const plugin = this;

const skip = plugin?.cfg?.skip;
const skip = this?.cfg?.skip;
if (skip) {
if (skip.relaying && connection.relaying) return 'relay';
if (skip.auth && connection.notes.auth_user) return 'auth';
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "haraka-plugin-spf",
"version": "1.2.0",
"version": "1.2.1",
"description": "Sender Policy Framework (SPF) plugin for Haraka",
"main": "index.js",
"scripts": {
Expand All @@ -25,18 +25,18 @@
},
"homepage": "https://github.com/haraka/haraka-plugin-spf#readme",
"devDependencies": {
"eslint": "8",
"eslint": "^8.42.0",
"eslint-plugin-haraka": "*",
"haraka-test-fixtures": "*",
"mocha": "9"
"mocha": "^9.2.0"
},
"bin": {
"spf": "./bin/spf"
},
"dependencies": {
"haraka-dsn": "^1.0.4",
"haraka-net-utils": "^1.5.0",
"ipaddr.js": "^2.0.1",
"nopt": "^7.0.0"
"ipaddr.js": "^2.1.0",
"nopt": "^7.2.0"
}
}
21 changes: 13 additions & 8 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ beforeEach(function () {
this.plugin.timeout = 8000;
this.plugin.load_spf_ini();

// uncomment this line to see detailed SPF evaluation
// comment this line to see detailed SPF evaluation
this.plugin.SPF.prototype.log_debug = () => {};

this.connection = fixtures.connection.createConnection();
Expand Down Expand Up @@ -165,10 +165,10 @@ describe('hook_helo', function () {
const test_addr = new Address('<[email protected]>');

describe('hook_mail', function () {
it('rfc1918', function (done) {

this.connection.remote.is_private=true;
this.connection.remote.ip='192.168.1.1';
it('rfc1918', function (done) {
this.connection.set('remote.is_private', true);
this.connection.set('remote.ip', '192.168.1.1');
this.plugin.hook_mail(function next () {
assert.equal(undefined, arguments[0]);
done()
Expand All @@ -190,31 +190,36 @@ describe('hook_mail', function () {
delete this.connection.transaction;
this.plugin.hook_mail(function next () {
assert.equal(undefined, arguments[0]);
assert.equal(undefined, arguments[1]);
done()
}, this.connection);
})

it('txn, no helo', function (done) {
this.timeout(3000)
this.plugin.cfg.deny.mfrom_fail = false;
this.connection.remote.ip='207.85.1.1';
this.connection.set('remote.ip', '207.85.1.1');
this.plugin.hook_mail(function next () {
assert.equal(undefined, arguments[0]);
assert.equal(undefined, arguments[1]);
done()
}, this.connection, [test_addr]);
})

it('txn', function (done) {
this.connection.set('remote', 'ip', '207.85.1.1');
this.connection.set('hello', 'host', 'mail.example.com');
this.timeout(3000)
this.connection.set('remote.ip', '207.85.1.1');
this.connection.set('hello.host', 'mail.example.com');
this.plugin.hook_mail(function next (rc) {
assert.equal(undefined, rc);
done()
}, this.connection, [test_addr]);
})

it('txn, relaying', function (done) {
this.timeout(3000)
this.connection.set('remote.ip', '207.85.1.1');
this.connection.relaying=true;
this.connection.set('relaying', true);
this.connection.set('hello.host', 'mail.example.com');
this.plugin.hook_mail(function next (rc) {
assert.equal(undefined, rc);
Expand Down

0 comments on commit 7d40ab9

Please sign in to comment.