Skip to content

Commit 7d40ab9

Browse files
authored
release 1.2.1
- fix: call skip_hosts via 'this' instead of exports #11 - es6: replace `plugin` with `this` #12 - deps: bump versions to latest
1 parent 0f7a23f commit 7d40ab9

File tree

5 files changed

+59
-52
lines changed

5 files changed

+59
-52
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: CI
22

3-
on: [ push ]
3+
on: [ push, pull_request ]
44

55
env:
66
CI: true

Changes.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11

22
### Unreleased
33

4-
- Fix bug where skip configuration was ignored
4+
5+
### [1.2.1] - 2023-06-19
6+
7+
- fix: call skip_hosts via 'this' instead of exports (#11)
8+
- skip configuration was being ignored
9+
- es6: replace `plugin` with `this`
10+
- deps: bump versions to latest
11+
512

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

@@ -44,3 +51,4 @@
4451
[1.1.2]: https://github.com/haraka/haraka-plugin-spf/releases/tag/1.1.2
4552
[1.1.3]: https://github.com/haraka/haraka-plugin-spf/releases/tag/1.1.3
4653
[1.2.0]: https://github.com/haraka/haraka-plugin-spf/releases/tag/1.2.0
54+
[1.2.1]: https://github.com/haraka/haraka-plugin-spf/releases/tag/1.2.1

index.js

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,21 @@ const DSN = require('haraka-dsn');
77
exports.SPF = SPF;
88

99
exports.register = function () {
10-
const plugin = this;
1110

1211
// Override logging in SPF module
13-
SPF.prototype.log_debug = str => plugin.logdebug(str);
12+
SPF.prototype.log_debug = str => this.logdebug(str);
1413

15-
plugin.load_spf_ini();
14+
this.load_spf_ini();
1615

17-
plugin.register_hook('helo', 'helo_spf');
18-
plugin.register_hook('ehlo', 'helo_spf');
16+
this.register_hook('helo', 'helo_spf');
17+
this.register_hook('ehlo', 'helo_spf');
1918
}
2019

2120
exports.load_spf_ini = function () {
22-
const plugin = this;
23-
plugin.nu = net_utils; // so tests can set public_ip
24-
plugin.SPF = SPF;
21+
this.nu = net_utils; // so tests can set public_ip
22+
this.SPF = SPF;
2523

26-
plugin.cfg = plugin.config.get('spf.ini', {
24+
this.cfg = this.config.get('spf.ini', {
2725
booleans: [
2826
'-defer.helo_temperror',
2927
'-defer.mfrom_temperror',
@@ -57,30 +55,30 @@ exports.load_spf_ini = function () {
5755
'-skip.auth',
5856
]
5957
},
60-
() => { plugin.load_spf_ini(); }
58+
() => { this.load_spf_ini(); }
6159
);
6260

6361
// when set, preserve legacy config settings
64-
['helo','mail'].forEach(phase => {
65-
if (plugin.cfg.main[`${phase}_softfail_reject`]) {
66-
plugin.cfg.deny[`${phase}_softfail`] = true;
62+
for (const phase of ['helo','mail']) {
63+
if (this.cfg.main[`${phase}_softfail_reject`]) {
64+
this.cfg.deny[`${phase}_softfail`] = true;
6765
}
68-
if (plugin.cfg.main[`${phase}_fail_reject`]) {
69-
plugin.cfg.deny[`${phase}_fail`] = true;
66+
if (this.cfg.main[`${phase}_fail_reject`]) {
67+
this.cfg.deny[`${phase}_fail`] = true;
7068
}
71-
if (plugin.cfg.main[`${phase}_temperror_defer`]) {
72-
plugin.cfg.defer[`${phase}_temperror`] = true;
69+
if (this.cfg.main[`${phase}_temperror_defer`]) {
70+
this.cfg.defer[`${phase}_temperror`] = true;
7371
}
74-
if (plugin.cfg.main[`${phase}_permerror_reject`]) {
75-
plugin.cfg.deny[`${phase}_permerror`] = true;
72+
if (this.cfg.main[`${phase}_permerror_reject`]) {
73+
this.cfg.deny[`${phase}_permerror`] = true;
7674
}
77-
});
75+
}
7876

79-
if (!plugin.cfg.relay) {
80-
plugin.cfg.relay = { context: 'sender' }; // default/legacy
77+
if (!this.cfg.relay) {
78+
this.cfg.relay = { context: 'sender' }; // default/legacy
8179
}
8280

83-
plugin.cfg.lookup_timeout = plugin.cfg.main.lookup_timeout || plugin.timeout - 1;
81+
this.cfg.lookup_timeout = this.cfg.main.lookup_timeout || this.timeout - 1;
8482
}
8583

8684
exports.helo_spf = async function (next, connection, helo) {
@@ -222,7 +220,6 @@ exports.hook_mail = async function (next, connection, params) {
222220
// if we check the public IP first. Only check the public IP if the
223221
// client IP returns a result other than 'Pass'.
224222
const result = await spf.check_host(connection.remote.ip, host, mfrom)
225-
226223
// typical inbound (!relay)
227224
if (!connection.relaying) return ch_cb(null, result)
228225

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

232229
// outbound (relaying), context=myself
233230
const my_public_ip = await net_utils.get_public_ip()
234-
235231
let spf_result;
236232
if (result) spf_result = spf.result(result).toLowerCase();
237233

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

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

266261
switch (result) {
267262
case spf.SPF_NONE:
268-
if (plugin.cfg[deny][`${scope}_none`]) {
269-
text = plugin.cfg[deny].openspf_text ? text : `${msgpre} SPF record not found`;
263+
if (this.cfg[deny][`${scope}_none`]) {
264+
text = this.cfg[deny].openspf_text ? text : `${msgpre} SPF record not found`;
270265
return next(DENY, text);
271266
}
272267
return next();
273268
case spf.SPF_NEUTRAL:
274269
case spf.SPF_PASS:
275270
return next();
276271
case spf.SPF_SOFTFAIL:
277-
if (plugin.cfg[deny][`${scope}_softfail`]) {
278-
text = plugin.cfg[deny].openspf_text ? text : `${msgpre} SPF SoftFail`;
272+
if (this.cfg[deny][`${scope}_softfail`]) {
273+
text = this.cfg[deny].openspf_text ? text : `${msgpre} SPF SoftFail`;
279274
return next(DENY, text);
280275
}
281276
return next();
282277
case spf.SPF_FAIL:
283-
if (plugin.cfg[deny][`${scope}_fail`]) {
284-
text = plugin.cfg[deny].openspf_text ? text : `${msgpre} SPF Fail`;
278+
if (this.cfg[deny][`${scope}_fail`]) {
279+
text = this.cfg[deny].openspf_text ? text : `${msgpre} SPF Fail`;
285280
return next(DENY, text);
286281
}
287282
return next();
288283
case spf.SPF_TEMPERROR:
289-
if (plugin.cfg[defer][`${scope}_temperror`]) {
284+
if (this.cfg[defer][`${scope}_temperror`]) {
290285
return next(DENYSOFT, `${msgpre} SPF Temporary Error`);
291286
}
292287
return next();
293288
case spf.SPF_PERMERROR:
294-
if (plugin.cfg[deny][`${scope}_permerror`]) {
289+
if (this.cfg[deny][`${scope}_permerror`]) {
295290
return next(DENY, `${msgpre} SPF Permanent Error`);
296291
}
297292
return next();
298293
default:
299294
// Unknown result
300-
connection.logerror(plugin, `unknown result code=${result}`);
295+
connection.logerror(this, `unknown result code=${result}`);
301296
return next();
302297
}
303298
}
@@ -314,9 +309,8 @@ exports.save_to_header = (connection, spf, result, mfrom, host, id, ip) => {
314309
}
315310

316311
exports.skip_hosts = function (connection) {
317-
const plugin = this;
318312

319-
const skip = plugin?.cfg?.skip;
313+
const skip = this?.cfg?.skip;
320314
if (skip) {
321315
if (skip.relaying && connection.relaying) return 'relay';
322316
if (skip.auth && connection.notes.auth_user) return 'auth';

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "haraka-plugin-spf",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "Sender Policy Framework (SPF) plugin for Haraka",
55
"main": "index.js",
66
"scripts": {
@@ -25,18 +25,18 @@
2525
},
2626
"homepage": "https://github.com/haraka/haraka-plugin-spf#readme",
2727
"devDependencies": {
28-
"eslint": "8",
28+
"eslint": "^8.42.0",
2929
"eslint-plugin-haraka": "*",
3030
"haraka-test-fixtures": "*",
31-
"mocha": "9"
31+
"mocha": "^9.2.0"
3232
},
3333
"bin": {
3434
"spf": "./bin/spf"
3535
},
3636
"dependencies": {
3737
"haraka-dsn": "^1.0.4",
3838
"haraka-net-utils": "^1.5.0",
39-
"ipaddr.js": "^2.0.1",
40-
"nopt": "^7.0.0"
39+
"ipaddr.js": "^2.1.0",
40+
"nopt": "^7.2.0"
4141
}
4242
}

test/index.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ beforeEach(function () {
1616
this.plugin.timeout = 8000;
1717
this.plugin.load_spf_ini();
1818

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

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

167167
describe('hook_mail', function () {
168-
it('rfc1918', function (done) {
169168

170-
this.connection.remote.is_private=true;
171-
this.connection.remote.ip='192.168.1.1';
169+
it('rfc1918', function (done) {
170+
this.connection.set('remote.is_private', true);
171+
this.connection.set('remote.ip', '192.168.1.1');
172172
this.plugin.hook_mail(function next () {
173173
assert.equal(undefined, arguments[0]);
174174
done()
@@ -190,31 +190,36 @@ describe('hook_mail', function () {
190190
delete this.connection.transaction;
191191
this.plugin.hook_mail(function next () {
192192
assert.equal(undefined, arguments[0]);
193+
assert.equal(undefined, arguments[1]);
193194
done()
194195
}, this.connection);
195196
})
196197

197198
it('txn, no helo', function (done) {
199+
this.timeout(3000)
198200
this.plugin.cfg.deny.mfrom_fail = false;
199-
this.connection.remote.ip='207.85.1.1';
201+
this.connection.set('remote.ip', '207.85.1.1');
200202
this.plugin.hook_mail(function next () {
201203
assert.equal(undefined, arguments[0]);
204+
assert.equal(undefined, arguments[1]);
202205
done()
203206
}, this.connection, [test_addr]);
204207
})
205208

206209
it('txn', function (done) {
207-
this.connection.set('remote', 'ip', '207.85.1.1');
208-
this.connection.set('hello', 'host', 'mail.example.com');
210+
this.timeout(3000)
211+
this.connection.set('remote.ip', '207.85.1.1');
212+
this.connection.set('hello.host', 'mail.example.com');
209213
this.plugin.hook_mail(function next (rc) {
210214
assert.equal(undefined, rc);
211215
done()
212216
}, this.connection, [test_addr]);
213217
})
214218

215219
it('txn, relaying', function (done) {
220+
this.timeout(3000)
216221
this.connection.set('remote.ip', '207.85.1.1');
217-
this.connection.relaying=true;
222+
this.connection.set('relaying', true);
218223
this.connection.set('hello.host', 'mail.example.com');
219224
this.plugin.hook_mail(function next (rc) {
220225
assert.equal(undefined, rc);

0 commit comments

Comments
 (0)