Haraka 3.0.4 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTORS.md +6 -5
- package/Changes.md +206 -28
- package/LICENSE +1 -1
- package/Plugins.md +3 -3
- package/bin/haraka +3 -1
- package/config/connection.ini +63 -0
- package/config/plugins +0 -2
- package/config/smtp.ini +1 -18
- package/config/tls.ini +2 -0
- package/connection.js +53 -63
- package/docs/CoreConfig.md +17 -78
- package/docs/HAProxy.md +10 -28
- package/docs/Outbound.md +8 -9
- package/docs/plugins/aliases.md +4 -6
- package/docs/plugins/block_me.md +2 -4
- package/docs/plugins/data.signatures.md +2 -4
- package/docs/plugins/max_unrecognized_commands.md +2 -4
- package/docs/plugins/prevent_credential_leaks.md +2 -5
- package/docs/plugins/process_title.md +1 -2
- package/docs/plugins/queue/test.md +9 -0
- package/docs/plugins/rcpt_to.in_host_list.md +1 -2
- package/docs/plugins/rcpt_to.max_count.md +2 -10
- package/docs/plugins/record_envelope_addresses.md +3 -6
- package/docs/plugins/relay.md +1 -155
- package/docs/plugins/reseed_rng.md +1 -2
- package/docs/plugins/tarpit.md +7 -10
- package/docs/plugins/tls.md +8 -0
- package/docs/plugins/toobusy.md +2 -4
- package/docs/plugins/xclient.md +1 -2
- package/eslint.config.mjs +27 -0
- package/http/html/index.html +6 -5
- package/logger.js +1 -8
- package/outbound/hmail.js +8 -1
- package/package.json +57 -56
- package/plugins/auth/auth_base.js +0 -1
- package/plugins/queue/lmtp.js +3 -1
- package/plugins/queue/test.js +5 -3
- package/server.js +0 -14
- package/test/config/smtp.ini +2 -0
- package/test/config/tls.ini +4 -2
- package/test/connection.js +20 -9
- package/test/outbound/index.js +1 -1
- package/test/tls_socket.js +5 -1
- package/.eslintrc.yaml +0 -12
- package/.prettierrc.yml +0 -1
- package/config/connection_close_message +0 -1
- package/config/databytes +0 -1
- package/config/dhparams.pem +0 -8
- package/config/early_talker.ini +0 -11
- package/config/mail_from.is_resolvable.ini +0 -6
- package/config/max_unrecognized_commands +0 -1
- package/config/smtp.json +0 -17
- package/docs/plugins/early_talker.md +0 -22
- package/docs/plugins/mail_from.is_resolvable.md +0 -29
- package/plugins/early_talker.js +0 -155
- package/plugins/mail_from.is_resolvable.js +0 -132
- package/plugins/relay.js +0 -207
- package/test/plugins/early_talker.js +0 -104
- package/test/plugins/mail_from.is_resolvable.js +0 -35
- package/test/plugins/relay.js +0 -303
- /package/docs/{plugins → deprecated}/access.md +0 -0
- /package/docs/{plugins → deprecated}/backscatterer.md +0 -0
- /package/docs/{plugins → deprecated}/data.headers.md +0 -0
package/plugins/relay.js
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
// relay
|
|
2
|
-
//
|
|
3
|
-
// documentation via: haraka -h relay
|
|
4
|
-
|
|
5
|
-
const net = require('node:net');
|
|
6
|
-
|
|
7
|
-
const ipaddr = require('ipaddr.js');
|
|
8
|
-
|
|
9
|
-
exports.register = function () {
|
|
10
|
-
|
|
11
|
-
this.load_relay_ini(); // plugin.cfg = { }
|
|
12
|
-
|
|
13
|
-
if (this.cfg.relay.acl) {
|
|
14
|
-
this.load_acls(); // plugin.acl_allow = [..]
|
|
15
|
-
this.register_hook('connect_init', 'acl');
|
|
16
|
-
this.register_hook('connect', 'pass_relaying');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (this.cfg.relay.force_routing || this.cfg.relay.dest_domains) {
|
|
20
|
-
this.load_dest_domains(); // plugin.dest.domains = { }
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (this.cfg.relay.force_routing) {
|
|
24
|
-
this.register_hook('get_mx', 'force_routing');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (this.cfg.relay.dest_domains) {
|
|
28
|
-
this.register_hook('rcpt', 'dest_domains');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (this.cfg.relay.all) {
|
|
32
|
-
this.register_hook('rcpt', 'all');
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
exports.load_relay_ini = function () {
|
|
37
|
-
this.cfg = this.config.get('relay.ini', {
|
|
38
|
-
booleans: [
|
|
39
|
-
'+relay.acl',
|
|
40
|
-
'+relay.force_routing',
|
|
41
|
-
'-relay.all',
|
|
42
|
-
'-relay.dest_domains',
|
|
43
|
-
],
|
|
44
|
-
}, () => {
|
|
45
|
-
this.load_relay_ini();
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
exports.load_dest_domains = function () {
|
|
50
|
-
this.dest = this.config.get(
|
|
51
|
-
'relay_dest_domains.ini',
|
|
52
|
-
'ini',
|
|
53
|
-
() => { this.load_dest_domains(); }
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
exports.load_acls = function () {
|
|
58
|
-
const file_name = 'relay_acl_allow';
|
|
59
|
-
|
|
60
|
-
// load with a self-referential callback
|
|
61
|
-
this.acl_allow = this.config.get(file_name, 'list', () => {
|
|
62
|
-
this.load_acls();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
for (let i=0; i<this.acl_allow.length; i++) {
|
|
66
|
-
const cidr = this.acl_allow[i].split('/');
|
|
67
|
-
if (!net.isIP(cidr[0])) {
|
|
68
|
-
this.logerror(this, `invalid entry in ${file_name}: ${cidr[0]}`);
|
|
69
|
-
}
|
|
70
|
-
if (!cidr[1]) {
|
|
71
|
-
this.logerror(this, `appending missing CIDR suffix in: ${file_name}`);
|
|
72
|
-
this.acl_allow[i] = `${cidr[0] }/32`;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
exports.acl = function (next, connection) {
|
|
78
|
-
if (!this.cfg.relay.acl) { return next(); }
|
|
79
|
-
|
|
80
|
-
connection.logdebug(this, `checking ${connection.remote.ip} in relay_acl_allow`);
|
|
81
|
-
|
|
82
|
-
if (!this.is_acl_allowed(connection)) {
|
|
83
|
-
connection.results.add(this, {skip: 'acl(unlisted)'});
|
|
84
|
-
return next();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
connection.results.add(this, {pass: 'acl'});
|
|
88
|
-
connection.relaying = true;
|
|
89
|
-
return next(OK);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
exports.pass_relaying = (next, connection) => {
|
|
93
|
-
if (connection.relaying) return next(OK);
|
|
94
|
-
|
|
95
|
-
next();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
exports.is_acl_allowed = function (connection) {
|
|
99
|
-
if (!this.acl_allow) { return false; }
|
|
100
|
-
if (!this.acl_allow.length) { return false; }
|
|
101
|
-
|
|
102
|
-
const { ip } = connection.remote;
|
|
103
|
-
|
|
104
|
-
for (const item of this.acl_allow) {
|
|
105
|
-
connection.logdebug(this, `checking if ${ip} is in ${item}`);
|
|
106
|
-
const cidr = item.split('/');
|
|
107
|
-
const c_net = cidr[0];
|
|
108
|
-
const c_mask = cidr[1] || 32;
|
|
109
|
-
|
|
110
|
-
if (!net.isIP(c_net)) continue; // bad config entry
|
|
111
|
-
if (net.isIPv4(ip) && net.isIPv6(c_net)) continue;
|
|
112
|
-
if (net.isIPv6(ip) && net.isIPv4(c_net)) continue;
|
|
113
|
-
|
|
114
|
-
if (ipaddr.parse(ip).match(ipaddr.parse(c_net), c_mask)) {
|
|
115
|
-
connection.logdebug(this, `checking if ${ip} is in ${item}: yes`);
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
exports.dest_domains = function (next, connection, params) {
|
|
123
|
-
if (!this.cfg.relay.dest_domains) { return next(); }
|
|
124
|
-
const { relaying, transaction } = connection ?? {}
|
|
125
|
-
if (!transaction) return next();
|
|
126
|
-
|
|
127
|
-
// Skip this if the host is already allowed to relay
|
|
128
|
-
if (relaying) {
|
|
129
|
-
transaction.results.add(this, {skip: 'relay_dest_domain(relay)'});
|
|
130
|
-
return next();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (!this.dest) {
|
|
134
|
-
transaction.results.add(this, {err: 'relay_dest_domain(no config!)'});
|
|
135
|
-
return next();
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if (!this.dest.domains) {
|
|
139
|
-
transaction.results.add(this, {skip: 'relay_dest_domain(config)'});
|
|
140
|
-
return next();
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const dest_domain = params[0].host;
|
|
144
|
-
connection.logdebug(this, `dest_domain = ${dest_domain}`);
|
|
145
|
-
|
|
146
|
-
const dst_cfg = this.dest.domains[dest_domain];
|
|
147
|
-
if (!dst_cfg) {
|
|
148
|
-
transaction.results.add(this, {fail: 'relay_dest_domain'});
|
|
149
|
-
return next(DENY, "You are not allowed to relay");
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const { action } = JSON.parse(dst_cfg);
|
|
153
|
-
connection.logdebug(this, `found config for ${dest_domain}: ${action}`);
|
|
154
|
-
|
|
155
|
-
switch (action) {
|
|
156
|
-
case "accept":
|
|
157
|
-
// why enable relaying here? Returning next(OK) will allow the
|
|
158
|
-
// address to be considered 'local'. What advantage does relaying
|
|
159
|
-
// bring?
|
|
160
|
-
connection.relaying = true;
|
|
161
|
-
transaction.results.add(this, {pass: 'relay_dest_domain'});
|
|
162
|
-
return next(OK);
|
|
163
|
-
case "continue":
|
|
164
|
-
// why oh why? Only reason I can think of is to enable outbound.
|
|
165
|
-
connection.relaying = true;
|
|
166
|
-
transaction.results.add(this, {pass: 'relay_dest_domain'});
|
|
167
|
-
return next(CONT); // same as next()
|
|
168
|
-
case "deny":
|
|
169
|
-
transaction.results.add(this, {fail: 'relay_dest_domain'});
|
|
170
|
-
return next(DENY, "You are not allowed to relay");
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
transaction.results.add(this, {fail: 'relay_dest_domain'});
|
|
174
|
-
next(DENY, "Mail for that recipient is not accepted here.");
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
exports.force_routing = function (next, hmail, domain) {
|
|
178
|
-
if (!this.cfg.relay.force_routing) { return next(); }
|
|
179
|
-
if (!this.dest) { return next(); }
|
|
180
|
-
if (!this.dest.domains) { return next(); }
|
|
181
|
-
let route = this.dest.domains[domain];
|
|
182
|
-
|
|
183
|
-
if (!route) {
|
|
184
|
-
route = this.dest.domains.any;
|
|
185
|
-
if (!route) {
|
|
186
|
-
this.logdebug(this, `using normal MX lookup for: ${domain}`);
|
|
187
|
-
return next();
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const { nexthop } = JSON.parse(route);
|
|
192
|
-
if (!nexthop) {
|
|
193
|
-
this.logdebug(this, `using normal MX lookup for: ${domain}`);
|
|
194
|
-
return next();
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
this.logdebug(this, `using ${nexthop} for: ${domain}`);
|
|
198
|
-
next(OK, nexthop);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
exports.all = function (next, connection, params) {
|
|
202
|
-
if (!this.cfg.relay.all) { return next(); }
|
|
203
|
-
|
|
204
|
-
connection.loginfo(this, `confirming recipient ${params[0]}`);
|
|
205
|
-
connection.relaying = true;
|
|
206
|
-
next(OK);
|
|
207
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
const assert = require('node:assert')
|
|
3
|
-
|
|
4
|
-
const fixtures = require('haraka-test-fixtures');
|
|
5
|
-
|
|
6
|
-
const _set_up = (done) => {
|
|
7
|
-
this.plugin = new fixtures.plugin('early_talker');
|
|
8
|
-
this.plugin.cfg = { main: { reject: true } };
|
|
9
|
-
|
|
10
|
-
this.connection = fixtures.connection.createConnection();
|
|
11
|
-
done();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
describe('early_talker', () => {
|
|
15
|
-
beforeEach(_set_up)
|
|
16
|
-
|
|
17
|
-
it('no config', (done) => {
|
|
18
|
-
this.plugin.early_talker((rc, msg) => {
|
|
19
|
-
assert.equal(rc, undefined);
|
|
20
|
-
assert.equal(msg, undefined);
|
|
21
|
-
done();
|
|
22
|
-
}, this.connection);
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
it('relaying', (done) => {
|
|
26
|
-
this.plugin.pause = 1;
|
|
27
|
-
this.connection.relaying = true;
|
|
28
|
-
this.plugin.early_talker((rc, msg) => {
|
|
29
|
-
assert.equal(rc, undefined);
|
|
30
|
-
assert.equal(msg, undefined);
|
|
31
|
-
done();
|
|
32
|
-
}, this.connection);
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it('is an early talker', (done) => {
|
|
36
|
-
const before = Date.now();
|
|
37
|
-
this.plugin.pause = 1001;
|
|
38
|
-
this.connection.early_talker = true;
|
|
39
|
-
this.plugin.early_talker((rc, msg) => {
|
|
40
|
-
assert.ok(Date.now() >= before + 1000);
|
|
41
|
-
assert.equal(rc, DENYDISCONNECT);
|
|
42
|
-
assert.equal(msg, 'You talk too soon');
|
|
43
|
-
done();
|
|
44
|
-
}, this.connection);
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
it('is an early talker, reject=false', (done) => {
|
|
48
|
-
const before = Date.now();
|
|
49
|
-
this.plugin.pause = 1001;
|
|
50
|
-
this.plugin.cfg.main.reject = false;
|
|
51
|
-
this.connection.early_talker = true;
|
|
52
|
-
this.plugin.early_talker((rc, msg) => {
|
|
53
|
-
assert.ok(Date.now() >= before + 1000);
|
|
54
|
-
assert.equal(undefined, rc);
|
|
55
|
-
assert.equal(undefined, msg);
|
|
56
|
-
assert.ok(this.connection.results.has('early_talker', 'fail', 'early'));
|
|
57
|
-
done();
|
|
58
|
-
}, this.connection);
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
it('relay whitelisted ip', (done) => {
|
|
62
|
-
this.plugin.pause = 1000;
|
|
63
|
-
this.plugin.whitelist = this.plugin.load_ip_list(['127.0.0.1']);
|
|
64
|
-
this.connection.remote.ip = '127.0.0.1';
|
|
65
|
-
this.connection.early_talker = true;
|
|
66
|
-
this.plugin.early_talker((rc, msg) => {
|
|
67
|
-
assert.equal(undefined, rc);
|
|
68
|
-
assert.equal(undefined, msg);
|
|
69
|
-
assert.ok(this.connection.results.has('early_talker', 'skip', 'whitelist'));
|
|
70
|
-
done();
|
|
71
|
-
}, this.connection);
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
it('relay whitelisted subnet', (done) => {
|
|
75
|
-
this.plugin.pause = 1000;
|
|
76
|
-
this.plugin.whitelist = this.plugin.load_ip_list(['127.0.0.0/16']);
|
|
77
|
-
this.connection.remote.ip = '127.0.0.88';
|
|
78
|
-
this.connection.early_talker = true;
|
|
79
|
-
this.plugin.early_talker((rc, msg) => {
|
|
80
|
-
assert.equal(undefined, rc);
|
|
81
|
-
assert.equal(undefined, msg);
|
|
82
|
-
assert.ok(this.connection.results.has('early_talker', 'skip', 'whitelist'));
|
|
83
|
-
done();
|
|
84
|
-
}, this.connection);
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
it('relay good senders', (done) => {
|
|
88
|
-
this.plugin.pause = 1000;
|
|
89
|
-
this.connection.results.add('karma', {good: 10});
|
|
90
|
-
this.connection.early_talker = true;
|
|
91
|
-
this.plugin.early_talker((rc, msg) => {
|
|
92
|
-
assert.equal(undefined, rc);
|
|
93
|
-
assert.equal(undefined, msg);
|
|
94
|
-
assert.ok(this.connection.results.has('early_talker', 'skip', '+karma'));
|
|
95
|
-
done();
|
|
96
|
-
}, this.connection);
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
it('test loading ip list', () => {
|
|
100
|
-
const whitelist = this.plugin.load_ip_list(['123.123.123.123', '127.0.0.0/16']);
|
|
101
|
-
assert.equal(whitelist[0][1], 32);
|
|
102
|
-
assert.equal(whitelist[1][1], 16);
|
|
103
|
-
})
|
|
104
|
-
})
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
const assert = require('node:assert')
|
|
3
|
-
const dns = require('node:dns');
|
|
4
|
-
|
|
5
|
-
const fixtures = require('haraka-test-fixtures');
|
|
6
|
-
const Address = require('address-rfc2821').Address
|
|
7
|
-
|
|
8
|
-
const _set_up = (done) => {
|
|
9
|
-
|
|
10
|
-
this.plugin = new fixtures.plugin('mail_from.is_resolvable');
|
|
11
|
-
this.plugin.register();
|
|
12
|
-
|
|
13
|
-
this.connection = fixtures.connection.createConnection();
|
|
14
|
-
this.connection.init_transaction()
|
|
15
|
-
|
|
16
|
-
done();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
describe('mail_from.is_resolvable', () => {
|
|
20
|
-
beforeEach(_set_up)
|
|
21
|
-
|
|
22
|
-
describe('hook_mail', () => {
|
|
23
|
-
it('any.com, no err code', (done) => {
|
|
24
|
-
const txn = this.connection.transaction;
|
|
25
|
-
this.plugin.hook_mail((code, msg) => {
|
|
26
|
-
// console.log()
|
|
27
|
-
assert.deepEqual(txn.results.get('mail_from.is_resolvable').pass, ['has_fwd_dns']);
|
|
28
|
-
done();
|
|
29
|
-
},
|
|
30
|
-
this.connection,
|
|
31
|
-
[new Address('<test@any.com>')]
|
|
32
|
-
)
|
|
33
|
-
})
|
|
34
|
-
})
|
|
35
|
-
})
|
package/test/plugins/relay.js
DELETED
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
const assert = require('node:assert')
|
|
3
|
-
|
|
4
|
-
const fixtures = require('haraka-test-fixtures');
|
|
5
|
-
|
|
6
|
-
const _set_up = (done) => {
|
|
7
|
-
this.plugin = new fixtures.plugin('relay');
|
|
8
|
-
this.plugin.cfg = {};
|
|
9
|
-
this.connection = fixtures.connection.createConnection();
|
|
10
|
-
done();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
describe('relay', () => {
|
|
14
|
-
describe('plugin', () => {
|
|
15
|
-
beforeEach(_set_up)
|
|
16
|
-
|
|
17
|
-
it('should have register function', () => {
|
|
18
|
-
assert.ok(this.plugin);
|
|
19
|
-
assert.equal('function', typeof this.plugin.register);
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('register function should call register_hook()', () => {
|
|
23
|
-
this.plugin.register();
|
|
24
|
-
assert.ok(this.plugin.register_hook.called);
|
|
25
|
-
})
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
describe('load_config_files', () => {
|
|
29
|
-
beforeEach(_set_up)
|
|
30
|
-
|
|
31
|
-
it('relay.ini', () => {
|
|
32
|
-
this.plugin.load_relay_ini();
|
|
33
|
-
assert.ok(typeof this.plugin.cfg === 'object');
|
|
34
|
-
assert.ok(this.plugin.cfg);
|
|
35
|
-
assert.ok(this.plugin.cfg.relay);
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
it('relay_dest_domains.ini', () => {
|
|
39
|
-
this.plugin.load_dest_domains();
|
|
40
|
-
assert.ok(typeof this.plugin.dest === 'object');
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
describe('is_acl_allowed', () => {
|
|
45
|
-
beforeEach(_set_up)
|
|
46
|
-
|
|
47
|
-
it('bare IP', () => {
|
|
48
|
-
this.plugin.acl_allow=['127.0.0.6'];
|
|
49
|
-
this.connection.remote.ip='127.0.0.6';
|
|
50
|
-
assert.equal(true, this.plugin.is_acl_allowed(this.connection));
|
|
51
|
-
this.connection.remote.ip='127.0.0.5';
|
|
52
|
-
assert.equal(false, this.plugin.is_acl_allowed(this.connection));
|
|
53
|
-
this.connection.remote.ip='127.0.1.5';
|
|
54
|
-
assert.equal(false, this.plugin.is_acl_allowed(this.connection));
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
it('netmask', () => {
|
|
58
|
-
this.plugin.acl_allow=['127.0.0.6/24'];
|
|
59
|
-
this.connection.remote.ip='127.0.0.6';
|
|
60
|
-
assert.equal(true, this.plugin.is_acl_allowed(this.connection));
|
|
61
|
-
this.connection.remote.ip='127.0.0.5';
|
|
62
|
-
assert.equal(true, this.plugin.is_acl_allowed(this.connection));
|
|
63
|
-
this.connection.remote.ip='127.0.1.5';
|
|
64
|
-
assert.equal(false, this.plugin.is_acl_allowed(this.connection));
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
it('mixed (ipv4 & ipv6 (Issue #428))', () => {
|
|
68
|
-
this.connection.remote.ip='2607:f060:b008:feed::2';
|
|
69
|
-
assert.equal(false, this.plugin.is_acl_allowed(this.connection));
|
|
70
|
-
|
|
71
|
-
this.plugin.acl_allow=['2607:f060:b008:feed::2/64'];
|
|
72
|
-
this.connection.remote.ip='2607:f060:b008:feed::2';
|
|
73
|
-
assert.equal(true, this.plugin.is_acl_allowed(this.connection));
|
|
74
|
-
|
|
75
|
-
this.plugin.acl_allow=['127.0.0.6/24'];
|
|
76
|
-
this.connection.remote.ip='2607:f060:b008:feed::2';
|
|
77
|
-
assert.equal(false, this.plugin.is_acl_allowed(this.connection));
|
|
78
|
-
})
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
describe('acl', () => {
|
|
82
|
-
beforeEach((done) => {
|
|
83
|
-
this.plugin = new fixtures.plugin('relay');
|
|
84
|
-
this.plugin.cfg = { relay: { dest_domains: true } };
|
|
85
|
-
this.connection = fixtures.connection.createConnection();
|
|
86
|
-
done();
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
it('relay.acl=false', (done) => {
|
|
90
|
-
this.plugin.cfg.relay.acl=false;
|
|
91
|
-
this.plugin.acl(() => {}, this.connection);
|
|
92
|
-
this.plugin.pass_relaying((rc) => {
|
|
93
|
-
assert.equal(undefined, rc);
|
|
94
|
-
done();
|
|
95
|
-
}, this.connection);
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
it('relay.acl=true, miss', (done) => {
|
|
99
|
-
this.plugin.cfg.relay.acl=true;
|
|
100
|
-
this.plugin.acl(() => {}, this.connection);
|
|
101
|
-
this.plugin.pass_relaying((rc) => {
|
|
102
|
-
assert.equal(undefined, rc);
|
|
103
|
-
assert.equal(false, this.connection.relaying);
|
|
104
|
-
done();
|
|
105
|
-
}, this.connection);
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
it('relay.acl=true, hit', (done) => {
|
|
109
|
-
this.plugin.cfg.relay.acl=true;
|
|
110
|
-
this.connection.remote.ip='1.1.1.1';
|
|
111
|
-
this.plugin.acl_allow=['1.1.1.1/32'];
|
|
112
|
-
this.plugin.acl(() => {}, this.connection);
|
|
113
|
-
this.plugin.pass_relaying((rc) => {
|
|
114
|
-
assert.equal(OK, rc);
|
|
115
|
-
assert.equal(true, this.connection.relaying);
|
|
116
|
-
done();
|
|
117
|
-
}, this.connection);
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
it('relay.acl=true, hit, missing mask', (done) => {
|
|
121
|
-
this.plugin.cfg.relay.acl=true;
|
|
122
|
-
this.connection.remote.ip='1.1.1.1';
|
|
123
|
-
this.plugin.acl_allow=['1.1.1.1'];
|
|
124
|
-
this.plugin.acl(() => {}, this.connection);
|
|
125
|
-
this.plugin.pass_relaying((rc) => {
|
|
126
|
-
assert.equal(OK, rc);
|
|
127
|
-
assert.equal(true, this.connection.relaying);
|
|
128
|
-
done();
|
|
129
|
-
}, this.connection);
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
it('relay.acl=true, hit, net', (done) => {
|
|
133
|
-
this.plugin.cfg.relay.acl=true;
|
|
134
|
-
this.connection.remote.ip='1.1.1.1';
|
|
135
|
-
this.plugin.acl_allow=['1.1.1.1/24'];
|
|
136
|
-
this.plugin.acl(() => {}, this.connection);
|
|
137
|
-
this.plugin.pass_relaying((rc) => {
|
|
138
|
-
assert.equal(OK, rc);
|
|
139
|
-
assert.equal(true, this.connection.relaying);
|
|
140
|
-
done();
|
|
141
|
-
}, this.connection);
|
|
142
|
-
})
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
describe('dest_domains', () => {
|
|
146
|
-
beforeEach((done) => {
|
|
147
|
-
this.plugin = new fixtures.plugin('relay');
|
|
148
|
-
this.plugin.cfg = { relay: { dest_domains: true } };
|
|
149
|
-
|
|
150
|
-
this.connection = fixtures.connection.createConnection();
|
|
151
|
-
this.connection.init_transaction();
|
|
152
|
-
|
|
153
|
-
done();
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
it('relay.dest_domains=false', (done) => {
|
|
157
|
-
this.plugin.cfg.relay.dest_domains=false;
|
|
158
|
-
this.plugin.dest_domains((rc) => {
|
|
159
|
-
assert.equal(undefined, rc);
|
|
160
|
-
done();
|
|
161
|
-
}, this.connection, [{host:'foo'}]);
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
it('relaying', (done) => {
|
|
165
|
-
this.connection.relaying=true;
|
|
166
|
-
this.plugin.dest_domains((rc) => {
|
|
167
|
-
assert.equal(undefined, rc);
|
|
168
|
-
assert.equal(1, this.connection.transaction.results.get('relay').skip.length);
|
|
169
|
-
done();
|
|
170
|
-
}, this.connection, [{host:'foo'}]);
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
it('no config', (done) => {
|
|
174
|
-
this.plugin.dest_domains((rc) => {
|
|
175
|
-
assert.equal(undefined, rc);
|
|
176
|
-
assert.equal(1, this.connection.transaction.results.get('relay').err.length);
|
|
177
|
-
done();
|
|
178
|
-
}, this.connection, [{host:'foo'}]);
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
it('action=undef', (done) => {
|
|
182
|
-
this.plugin.dest = { domains: { foo: '{"action":"dunno"}' } };
|
|
183
|
-
this.plugin.dest_domains((rc) => {
|
|
184
|
-
assert.equal(DENY, rc);
|
|
185
|
-
assert.equal(1, this.connection.transaction.results.get('relay').fail.length);
|
|
186
|
-
done();
|
|
187
|
-
}, this.connection, [{host:'foo'}]);
|
|
188
|
-
})
|
|
189
|
-
|
|
190
|
-
it('action=deny', (done) => {
|
|
191
|
-
this.plugin.dest = { domains: { foo: '{"action":"deny"}' } };
|
|
192
|
-
this.plugin.dest_domains((rc) => {
|
|
193
|
-
assert.equal(DENY, rc);
|
|
194
|
-
assert.equal(1, this.connection.transaction.results.get('relay').fail.length);
|
|
195
|
-
done();
|
|
196
|
-
}, this.connection, [{host:'foo'}]);
|
|
197
|
-
})
|
|
198
|
-
|
|
199
|
-
it('action=continue', (done) => {
|
|
200
|
-
this.plugin.dest = { domains: { foo: '{"action":"continue"}' } };
|
|
201
|
-
this.plugin.dest_domains((rc) => {
|
|
202
|
-
assert.equal(CONT, rc);
|
|
203
|
-
assert.equal(1, this.connection.transaction.results.get('relay').pass.length);
|
|
204
|
-
done();
|
|
205
|
-
}, this.connection, [{host:'foo'}]);
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
it('action=accept', (done) => {
|
|
209
|
-
this.plugin.dest = { domains: { foo: '{"action":"continue"}' } };
|
|
210
|
-
this.plugin.dest_domains((rc) => {
|
|
211
|
-
assert.equal(CONT, rc);
|
|
212
|
-
assert.equal(1, this.connection.transaction.results.get('relay').pass.length);
|
|
213
|
-
done();
|
|
214
|
-
}, this.connection, [{host:'foo'}]);
|
|
215
|
-
})
|
|
216
|
-
})
|
|
217
|
-
|
|
218
|
-
describe('force_routing', () => {
|
|
219
|
-
beforeEach((done) => {
|
|
220
|
-
this.plugin = new fixtures.plugin('relay');
|
|
221
|
-
this.plugin.cfg = { relay: { force_routing: true } };
|
|
222
|
-
this.plugin.dest = {};
|
|
223
|
-
|
|
224
|
-
this.connection = fixtures.connection.createConnection();
|
|
225
|
-
this.connection.init_transaction()
|
|
226
|
-
|
|
227
|
-
done();
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
it('relay.force_routing=false', (done) => {
|
|
231
|
-
this.plugin.cfg.relay.force_routing=false;
|
|
232
|
-
this.plugin.force_routing((rc) => {
|
|
233
|
-
assert.equal(undefined, rc);
|
|
234
|
-
done();
|
|
235
|
-
}, this.connection, 'foo');
|
|
236
|
-
})
|
|
237
|
-
|
|
238
|
-
it('dest_domains empty', (done) => {
|
|
239
|
-
this.plugin.force_routing((rc) => {
|
|
240
|
-
assert.equal(undefined, rc);
|
|
241
|
-
done();
|
|
242
|
-
}, this.connection, 'foo');
|
|
243
|
-
})
|
|
244
|
-
|
|
245
|
-
it('dest_domains, no route', (done) => {
|
|
246
|
-
this.plugin.dest = { domains: { foo: '{"action":"blah blah"}' } };
|
|
247
|
-
this.plugin.force_routing((rc, nexthop) => {
|
|
248
|
-
assert.equal(undefined, rc);
|
|
249
|
-
assert.equal(undefined, nexthop);
|
|
250
|
-
done();
|
|
251
|
-
}, this.connection, 'foo');
|
|
252
|
-
})
|
|
253
|
-
|
|
254
|
-
it('dest_domains, route', (done) => {
|
|
255
|
-
this.plugin.dest = { domains: { foo: '{"action":"blah blah","nexthop":"other-server"}' } };
|
|
256
|
-
this.plugin.force_routing((rc, nexthop) => {
|
|
257
|
-
assert.equal(OK, rc);
|
|
258
|
-
assert.equal('other-server', nexthop);
|
|
259
|
-
done();
|
|
260
|
-
}, this.connection, 'foo');
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
it('dest-domains, any', (done) => {
|
|
264
|
-
this.plugin.dest = { domains: { foo: '{"action":"blah blah","nexthop":"other-server"}',
|
|
265
|
-
any: '{"action":"blah blah","nexthop":"any-server"}'} };
|
|
266
|
-
this.plugin.force_routing((rc, nexthop) => {
|
|
267
|
-
assert.equal(OK, rc);
|
|
268
|
-
assert.equal('any-server', nexthop);
|
|
269
|
-
done();
|
|
270
|
-
}, this.connection, 'not');
|
|
271
|
-
})
|
|
272
|
-
})
|
|
273
|
-
|
|
274
|
-
describe('all', () => {
|
|
275
|
-
beforeEach(_set_up)
|
|
276
|
-
|
|
277
|
-
it('register_hook() should register available function', () => {
|
|
278
|
-
assert.ok(this.plugin.all);
|
|
279
|
-
assert.equal('function', typeof this.plugin.all);
|
|
280
|
-
this.plugin.register();
|
|
281
|
-
this.plugin.cfg.relay.all = true;
|
|
282
|
-
this.plugin.register_hook('rcpt', 'all'); // register() doesn't b/c config is disabled
|
|
283
|
-
// console.log(this.plugin.register_hook.args);
|
|
284
|
-
assert.equal(this.plugin.register_hook.args[3][1], 'all');
|
|
285
|
-
})
|
|
286
|
-
|
|
287
|
-
it('all hook always returns OK', (done) => {
|
|
288
|
-
this.plugin.cfg.relay = { all: true };
|
|
289
|
-
this.plugin.all((action) => {
|
|
290
|
-
assert.equal(action, OK);
|
|
291
|
-
done();
|
|
292
|
-
}, this.connection, ['foo@bar.com']);
|
|
293
|
-
})
|
|
294
|
-
|
|
295
|
-
it('all hook always sets connection.relaying to 1', (done) => {
|
|
296
|
-
this.plugin.cfg.relay = { all: true };
|
|
297
|
-
this.plugin.all((action) => {
|
|
298
|
-
assert.equal(this.connection.relaying, 1);
|
|
299
|
-
done();
|
|
300
|
-
}, this.connection, ['foo@bar.com']);
|
|
301
|
-
})
|
|
302
|
-
})
|
|
303
|
-
})
|
|
File without changes
|
|
File without changes
|
|
File without changes
|