Haraka 3.1.5 → 3.1.7

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.
Files changed (79) hide show
  1. package/.prettierignore +1 -1
  2. package/{Changes.md → CHANGELOG.md} +54 -3
  3. package/CONTRIBUTORS.md +26 -26
  4. package/Plugins.md +99 -99
  5. package/README.md +68 -93
  6. package/SECURITY.md +178 -0
  7. package/bin/haraka +7 -14
  8. package/config/plugins +0 -3
  9. package/config/smtp_forward.ini +10 -0
  10. package/config/smtp_proxy.ini +10 -0
  11. package/connection.js +25 -8
  12. package/docs/Connection.md +126 -39
  13. package/docs/CoreConfig.md +92 -74
  14. package/docs/HAProxy.md +41 -25
  15. package/docs/Logging.md +68 -38
  16. package/docs/Outbound.md +124 -179
  17. package/docs/Plugins.md +38 -59
  18. package/docs/Transaction.md +78 -83
  19. package/docs/Tutorial.md +122 -209
  20. package/docs/plugins/aliases.md +1 -141
  21. package/docs/plugins/auth/auth_ldap.md +2 -39
  22. package/docs/plugins/max_unrecognized_commands.md +4 -18
  23. package/docs/plugins/process_title.md +3 -3
  24. package/docs/plugins/queue/smtp_forward.md +19 -3
  25. package/docs/plugins/queue/smtp_proxy.md +10 -2
  26. package/docs/plugins/reseed_rng.md +11 -13
  27. package/docs/plugins/tls.md +7 -7
  28. package/docs/plugins/toobusy.md +10 -4
  29. package/docs/tutorials/SettingUpOutbound.md +40 -48
  30. package/endpoint.js +32 -2
  31. package/haraka.js +1 -1
  32. package/outbound/hmail.js +42 -41
  33. package/outbound/index.js +7 -4
  34. package/outbound/tls.js +2 -43
  35. package/package.json +51 -61
  36. package/plugins/auth/auth_base.js +9 -3
  37. package/plugins/auth/auth_proxy.js +14 -11
  38. package/plugins/block_me.js +4 -2
  39. package/plugins/prevent_credential_leaks.js +3 -1
  40. package/plugins/process_title.js +6 -6
  41. package/plugins/queue/qmail-queue.js +15 -19
  42. package/plugins/queue/smtp_forward.js +12 -4
  43. package/plugins/queue/smtp_proxy.js +14 -3
  44. package/plugins/tls.js +13 -5
  45. package/plugins/xclient.js +3 -1
  46. package/server.js +22 -10
  47. package/smtp_client.js +20 -11
  48. package/test/config/block_me.recipient +1 -0
  49. package/test/config/block_me.senders +1 -0
  50. package/test/connection.js +258 -0
  51. package/test/endpoint.js +27 -0
  52. package/test/outbound/bounce_net_errors.js +3 -2
  53. package/test/outbound/hmail.js +19 -0
  54. package/test/outbound/index.js +189 -0
  55. package/test/outbound/queue.js +92 -0
  56. package/test/plugins/auth/auth_bridge.js +80 -0
  57. package/test/plugins/auth/flat_file.js +128 -0
  58. package/test/plugins/block_me.js +157 -0
  59. package/test/plugins/data.signatures.js +114 -0
  60. package/test/plugins/delay_deny.js +263 -0
  61. package/test/plugins/prevent_credential_leaks.js +178 -0
  62. package/test/plugins/process_title.js +135 -0
  63. package/test/plugins/queue/deliver.js +99 -0
  64. package/test/plugins/queue/discard.js +79 -0
  65. package/test/plugins/queue/lmtp.js +138 -0
  66. package/test/plugins/queue/qmail-queue.js +99 -0
  67. package/test/plugins/queue/quarantine.js +81 -0
  68. package/test/plugins/queue/smtp_bridge.js +154 -0
  69. package/test/plugins/queue/smtp_forward.js +42 -6
  70. package/test/plugins/queue/smtp_proxy.js +139 -0
  71. package/test/plugins/reseed_rng.js +34 -0
  72. package/test/plugins/tarpit.js +91 -0
  73. package/test/plugins/tls.js +25 -0
  74. package/test/plugins/toobusy.js +21 -0
  75. package/test/plugins/xclient.js +14 -0
  76. package/test/server.js +231 -0
  77. package/test/smtp_client.js +45 -12
  78. package/test/tls_socket.js +220 -0
  79. package/tls_socket.js +52 -2
@@ -230,4 +230,96 @@ describe('outbound/queue', () => {
230
230
  }
231
231
  })
232
232
  })
233
+
234
+ describe('queue maintenance', () => {
235
+ it('delete_dot_files removes leftover dot files only', async () => {
236
+ const tmpDir = path.join(os.tmpdir(), `haraka-dot-clean-${Date.now()}`)
237
+ fs.mkdirSync(tmpDir, { recursive: true })
238
+ const dotName = `${qfile.platformDOT}leftover`
239
+ const normalName = 'keep-me'
240
+ fs.writeFileSync(path.join(tmpDir, dotName), 'x')
241
+ fs.writeFileSync(path.join(tmpDir, normalName), 'x')
242
+
243
+ const originalQueueDir = queue.queue_dir
244
+ queue.queue_dir = tmpDir
245
+ try {
246
+ await queue.delete_dot_files()
247
+ assert.equal(fs.existsSync(path.join(tmpDir, dotName)), false)
248
+ assert.equal(fs.existsSync(path.join(tmpDir, normalName)), true)
249
+ } finally {
250
+ queue.queue_dir = originalQueueDir
251
+ fs.rmSync(tmpDir, { recursive: true, force: true })
252
+ }
253
+ })
254
+
255
+ it('_add_hmail pushes immediate items and schedules delayed ones', () => {
256
+ const originalPush = queue.delivery_queue.push
257
+ const originalAdd = queue.temp_fail_queue.add
258
+ const pushed = []
259
+ const delayed = []
260
+ let delayedCb
261
+
262
+ queue.delivery_queue.push = (item) => pushed.push(item)
263
+ queue.temp_fail_queue.add = (id, ms, cb) => {
264
+ delayed.push([id, ms])
265
+ delayedCb = cb
266
+ }
267
+ queue.cur_time = new Date()
268
+
269
+ const immediate = { filename: 'a', next_process: queue.cur_time - 1 }
270
+ const future = { filename: 'b', next_process: queue.cur_time.getTime() + 1000 }
271
+
272
+ try {
273
+ queue._add_hmail(immediate)
274
+ queue._add_hmail(future)
275
+ assert.equal(pushed.length, 1)
276
+ assert.equal(delayed.length, 1)
277
+ assert.equal(delayed[0][0], 'b')
278
+ delayedCb()
279
+ assert.equal(pushed.length, 2)
280
+ } finally {
281
+ queue.delivery_queue.push = originalPush
282
+ queue.temp_fail_queue.add = originalAdd
283
+ }
284
+ })
285
+
286
+ it('scan_queue_pids returns unique pids from queue files', async () => {
287
+ populateTestQueue()
288
+ const originalQueueDir = queue.queue_dir
289
+ queue.queue_dir = testQueueDir
290
+
291
+ try {
292
+ const pids = await queue.scan_queue_pids()
293
+ assert.ok(Array.isArray(pids))
294
+ assert.equal(pids.length >= 1, true)
295
+ } finally {
296
+ queue.queue_dir = originalQueueDir
297
+ clearTestQueue()
298
+ }
299
+ })
300
+
301
+ it('scan_queue_pids throws when queue dir cannot be read', async () => {
302
+ const originalQueueDir = queue.queue_dir
303
+ const badPath = path.join(os.tmpdir(), `queue-not-dir-${Date.now()}`)
304
+ fs.writeFileSync(badPath, 'x')
305
+ queue.queue_dir = badPath
306
+ try {
307
+ await assert.rejects(() => queue.scan_queue_pids())
308
+ } finally {
309
+ queue.queue_dir = originalQueueDir
310
+ fs.rmSync(badPath, { force: true })
311
+ }
312
+ })
313
+
314
+ it('delete_dot_files handles readdir errors without throwing', async () => {
315
+ const originalQueueDir = queue.queue_dir
316
+ queue.queue_dir = path.join(os.tmpdir(), `missing-dot-${Date.now()}`)
317
+ try {
318
+ await queue.delete_dot_files()
319
+ assert.ok(true)
320
+ } finally {
321
+ queue.queue_dir = originalQueueDir
322
+ }
323
+ })
324
+ })
233
325
  })
@@ -0,0 +1,80 @@
1
+ 'use strict'
2
+
3
+ const assert = require('node:assert')
4
+ const { describe, it, beforeEach } = require('node:test')
5
+
6
+ const fixtures = require('haraka-test-fixtures')
7
+
8
+ describe('auth/auth_bridge', () => {
9
+ let plugin
10
+
11
+ beforeEach(() => {
12
+ plugin = new fixtures.plugin('auth/auth_bridge')
13
+ plugin.load_flat_ini()
14
+ })
15
+
16
+ describe('load_flat_ini', () => {
17
+ it('loads smtp_bridge.ini config', () => {
18
+ assert.ok(plugin.cfg)
19
+ assert.ok(plugin.cfg.main)
20
+ })
21
+
22
+ it('cfg.main.host defaults to localhost', () => {
23
+ assert.equal(plugin.cfg.main.host, 'localhost')
24
+ })
25
+ })
26
+
27
+ describe('check_plain_passwd', () => {
28
+ let conn
29
+
30
+ beforeEach(() => {
31
+ conn = fixtures.connection.createConnection()
32
+ })
33
+
34
+ it('calls try_auth_proxy with just host when no port configured', (t, done) => {
35
+ plugin.cfg.main = { host: 'mail.example.com' }
36
+ plugin.try_auth_proxy = (connection, host, user, passwd, cb) => {
37
+ assert.equal(host, 'mail.example.com')
38
+ assert.equal(user, 'testuser')
39
+ assert.equal(passwd, 'testpass')
40
+ cb(true)
41
+ }
42
+ plugin.check_plain_passwd(conn, 'testuser', 'testpass', (result) => {
43
+ assert.equal(result, true)
44
+ done()
45
+ })
46
+ })
47
+
48
+ it('calls try_auth_proxy with host:port when port is configured', (t, done) => {
49
+ plugin.cfg.main = { host: 'mail.example.com', port: '587' }
50
+ plugin.try_auth_proxy = (connection, host, user, passwd, cb) => {
51
+ assert.equal(host, 'mail.example.com:587')
52
+ cb(true)
53
+ }
54
+ plugin.check_plain_passwd(conn, 'testuser', 'testpass', (result) => {
55
+ assert.equal(result, true)
56
+ done()
57
+ })
58
+ })
59
+
60
+ it('passes authentication failure through to callback', (t, done) => {
61
+ plugin.cfg.main = { host: 'mail.example.com' }
62
+ plugin.try_auth_proxy = (connection, host, user, passwd, cb) => {
63
+ cb(false)
64
+ }
65
+ plugin.check_plain_passwd(conn, 'baduser', 'badpass', (result) => {
66
+ assert.equal(result, false)
67
+ done()
68
+ })
69
+ })
70
+
71
+ it('passes the connection object to try_auth_proxy', (t, done) => {
72
+ plugin.cfg.main = { host: 'mail.example.com' }
73
+ plugin.try_auth_proxy = (connection, host, user, passwd, cb) => {
74
+ assert.equal(connection, conn)
75
+ cb(true)
76
+ }
77
+ plugin.check_plain_passwd(conn, 'user', 'pass', () => done())
78
+ })
79
+ })
80
+ })
@@ -0,0 +1,128 @@
1
+ 'use strict'
2
+
3
+ const assert = require('node:assert')
4
+ const { describe, it, beforeEach } = require('node:test')
5
+
6
+ const fixtures = require('haraka-test-fixtures')
7
+
8
+ function makeConnection(opts = {}) {
9
+ const conn = fixtures.connection.createConnection()
10
+ conn.capabilities = []
11
+ conn.notes.allowed_auth_methods = []
12
+ conn.remote = { is_private: opts.is_private ?? false }
13
+ conn.tls = { enabled: opts.tls_enabled ?? false }
14
+ return conn
15
+ }
16
+
17
+ describe('auth/flat_file', () => {
18
+ let plugin
19
+
20
+ beforeEach(() => {
21
+ plugin = new fixtures.plugin('auth/flat_file')
22
+ plugin.inherits('auth/auth_base')
23
+ plugin.load_flat_ini()
24
+ })
25
+
26
+ describe('load_flat_ini', () => {
27
+ it('populates cfg.users as an object', () => {
28
+ assert.ok(typeof plugin.cfg.users === 'object')
29
+ })
30
+
31
+ it('cfg.users defaults to empty object when not configured', () => {
32
+ // default config has no real users
33
+ assert.deepEqual(plugin.cfg.users, {})
34
+ })
35
+ })
36
+
37
+ describe('hook_capabilities', () => {
38
+ let conn
39
+
40
+ beforeEach(() => {
41
+ conn = makeConnection()
42
+ })
43
+
44
+ it('skips for public non-TLS connection', (t, done) => {
45
+ plugin.hook_capabilities((rc) => {
46
+ assert.equal(rc, undefined)
47
+ assert.equal(conn.capabilities.length, 0)
48
+ done()
49
+ }, conn)
50
+ })
51
+
52
+ it('adds AUTH methods for private connection (non-TLS)', (t, done) => {
53
+ conn.remote.is_private = true
54
+ plugin.cfg.core.methods = 'PLAIN,LOGIN'
55
+ plugin.hook_capabilities((rc) => {
56
+ assert.equal(rc, undefined)
57
+ assert.ok(
58
+ conn.capabilities.some((c) => c.startsWith('AUTH ')),
59
+ 'AUTH capability should be present',
60
+ )
61
+ done()
62
+ }, conn)
63
+ })
64
+
65
+ it('adds AUTH methods when TLS is enabled', (t, done) => {
66
+ conn.tls.enabled = true
67
+ plugin.cfg.core.methods = 'PLAIN,LOGIN'
68
+ plugin.hook_capabilities((rc) => {
69
+ assert.equal(rc, undefined)
70
+ assert.ok(conn.capabilities.some((c) => c.startsWith('AUTH ')))
71
+ done()
72
+ }, conn)
73
+ })
74
+
75
+ it('sets allowed_auth_methods on connection notes', (t, done) => {
76
+ conn.tls.enabled = true
77
+ plugin.cfg.core.methods = 'PLAIN,LOGIN'
78
+ plugin.hook_capabilities(() => {
79
+ assert.deepEqual(conn.notes.allowed_auth_methods, ['PLAIN', 'LOGIN'])
80
+ done()
81
+ }, conn)
82
+ })
83
+
84
+ it('does not add AUTH when no methods configured', (t, done) => {
85
+ conn.tls.enabled = true
86
+ plugin.cfg.core.methods = null
87
+ plugin.hook_capabilities(() => {
88
+ assert.equal(conn.capabilities.length, 0)
89
+ done()
90
+ }, conn)
91
+ })
92
+ })
93
+
94
+ describe('get_plain_passwd', () => {
95
+ beforeEach(() => {
96
+ plugin.cfg.users = { alice: 'secret', bob: 'hunter2' }
97
+ })
98
+
99
+ it('returns password for known user', (t, done) => {
100
+ plugin.get_plain_passwd('alice', {}, (pw) => {
101
+ assert.equal(pw, 'secret')
102
+ done()
103
+ })
104
+ })
105
+
106
+ it('calls cb with no args for unknown user', (t, done) => {
107
+ plugin.get_plain_passwd('unknown', {}, (pw) => {
108
+ assert.equal(pw, undefined)
109
+ done()
110
+ })
111
+ })
112
+
113
+ it('handles multiple users', (t, done) => {
114
+ plugin.get_plain_passwd('bob', {}, (pw) => {
115
+ assert.equal(pw, 'hunter2')
116
+ done()
117
+ })
118
+ })
119
+
120
+ it('coerces password to string via toString()', (t, done) => {
121
+ plugin.cfg.users.numericuser = 12345
122
+ plugin.get_plain_passwd('numericuser', {}, (pw) => {
123
+ assert.equal(pw, '12345')
124
+ done()
125
+ })
126
+ })
127
+ })
128
+ })
@@ -0,0 +1,157 @@
1
+ 'use strict'
2
+
3
+ const fs = require('node:fs')
4
+ const path = require('node:path')
5
+ const assert = require('node:assert/strict')
6
+ const { describe, it, beforeEach, after } = require('node:test')
7
+
8
+ const fixtures = require('haraka-test-fixtures')
9
+ const { Address } = require('address-rfc2821')
10
+ require('haraka-constants').import(global)
11
+
12
+ // block_me appends to <config>/mail_from.blocklist when a sender is blocked;
13
+ // remove the artifact the 'sets block_me note' test produces.
14
+ after(() => {
15
+ fs.rmSync(path.resolve('test/config/mail_from.blocklist'), { force: true })
16
+ })
17
+
18
+ function makeConnection({
19
+ relaying = false,
20
+ mailFrom = 'sender@example.com',
21
+ rcptTo = ['blocklist@example.com'],
22
+ } = {}) {
23
+ const conn = fixtures.connection.createConnection()
24
+ conn.init_transaction()
25
+ conn.relaying = relaying
26
+ conn.transaction.mail_from = new Address(`<${mailFrom}>`)
27
+ conn.transaction.rcpt_to = rcptTo.map((r) => new Address(`<${r}>`))
28
+ conn.transaction.body = { bodytext: '', children: [] }
29
+ return conn
30
+ }
31
+
32
+ describe('block_me', () => {
33
+ let plugin
34
+
35
+ // Read config (block_me.recipient, block_me.senders) from test/config rather
36
+ // than the real config dir. block_me also appends matched senders to
37
+ // mail_from.blocklist; with this override that write lands in test/config too.
38
+ beforeEach(() => {
39
+ plugin = new fixtures.plugin('block_me')
40
+ plugin.config = plugin.config.module_config(path.resolve('test'))
41
+ })
42
+
43
+ describe('hook_data', () => {
44
+ it('enables body parsing and calls next', (t, done) => {
45
+ const conn = makeConnection()
46
+ conn.transaction.parse_body = false
47
+ plugin.hook_data((rc) => {
48
+ assert.equal(rc, undefined)
49
+ assert.equal(conn.transaction.parse_body, true)
50
+ done()
51
+ }, conn)
52
+ })
53
+ })
54
+
55
+ describe('hook_data_post', () => {
56
+ it('calls next when not relaying', (t, done) => {
57
+ const conn = makeConnection({ relaying: false })
58
+ plugin.hook_data_post((rc) => {
59
+ assert.equal(rc, undefined)
60
+ done()
61
+ }, conn)
62
+ })
63
+
64
+ it('calls next when transaction is missing', (t, done) => {
65
+ const conn = fixtures.connection.createConnection()
66
+ conn.relaying = true
67
+ conn.transaction = null
68
+ plugin.hook_data_post((rc) => {
69
+ assert.equal(rc, undefined)
70
+ done()
71
+ }, conn)
72
+ })
73
+
74
+ it('calls next when more than one recipient', (t, done) => {
75
+ const conn = makeConnection({
76
+ relaying: true,
77
+ rcptTo: ['blocklist@example.com', 'other@example.com'],
78
+ })
79
+ plugin.hook_data_post((rc) => {
80
+ assert.equal(rc, undefined)
81
+ done()
82
+ }, conn)
83
+ })
84
+
85
+ it('calls next when recipient does not match configured address', (t, done) => {
86
+ const conn = makeConnection({ relaying: true, rcptTo: ['other@example.com'] })
87
+ plugin.hook_data_post((rc) => {
88
+ assert.equal(rc, undefined)
89
+ done()
90
+ }, conn)
91
+ })
92
+
93
+ it('denies when sender is not in the allowed senders list', (t, done) => {
94
+ const conn = makeConnection({
95
+ relaying: true,
96
+ mailFrom: 'notallowed@example.com',
97
+ rcptTo: ['blocklist@example.com'],
98
+ })
99
+ plugin.hook_data_post((rc, msg) => {
100
+ assert.equal(rc, DENY)
101
+ assert.ok(msg.includes('not allowed'))
102
+ done()
103
+ }, conn)
104
+ })
105
+
106
+ it('calls next when no From header found in body', (t, done) => {
107
+ const conn = makeConnection({
108
+ relaying: true,
109
+ mailFrom: 'sender@example.com',
110
+ rcptTo: ['blocklist@example.com'],
111
+ })
112
+ conn.transaction.body = { bodytext: 'No from header here', children: [] }
113
+ plugin.hook_data_post((rc) => {
114
+ assert.equal(rc, undefined)
115
+ // note should not be set since no From header
116
+ assert.equal(conn.transaction.notes.block_me, undefined)
117
+ done()
118
+ }, conn)
119
+ })
120
+
121
+ it('sets block_me note and calls next when From is extracted', (t, done) => {
122
+ const conn = makeConnection({
123
+ relaying: true,
124
+ mailFrom: 'sender@example.com',
125
+ rcptTo: ['blocklist@example.com'],
126
+ })
127
+ conn.transaction.body = {
128
+ bodytext: 'From: Test User <block_target@example.com>',
129
+ children: [],
130
+ }
131
+ plugin.hook_data_post((rc) => {
132
+ assert.equal(rc, undefined)
133
+ assert.equal(conn.transaction.notes.block_me, 1)
134
+ done()
135
+ }, conn)
136
+ })
137
+ })
138
+
139
+ describe('hook_queue', () => {
140
+ it('returns OK when block_me note is set on transaction', (t, done) => {
141
+ const conn = makeConnection()
142
+ conn.transaction.notes.block_me = 1
143
+ plugin.hook_queue((rc) => {
144
+ assert.equal(rc, OK)
145
+ done()
146
+ }, conn)
147
+ })
148
+
149
+ it('calls next when block_me note is not set', (t, done) => {
150
+ const conn = makeConnection()
151
+ plugin.hook_queue((rc) => {
152
+ assert.equal(rc, undefined)
153
+ done()
154
+ }, conn)
155
+ })
156
+ })
157
+ })
@@ -0,0 +1,114 @@
1
+ 'use strict'
2
+
3
+ const assert = require('node:assert/strict')
4
+ const { describe, it, beforeEach } = require('node:test')
5
+
6
+ const fixtures = require('haraka-test-fixtures')
7
+ require('haraka-constants').import(global)
8
+
9
+ function makeConnection(bodytext = '', children = []) {
10
+ const conn = fixtures.connection.createConnection()
11
+ conn.init_transaction()
12
+ conn.transaction.body = { bodytext, children }
13
+ return conn
14
+ }
15
+
16
+ describe('data.signatures', () => {
17
+ let plugin
18
+
19
+ beforeEach(() => {
20
+ plugin = new fixtures.plugin('data.signatures')
21
+ })
22
+
23
+ describe('hook_data', () => {
24
+ it('enables body parsing', (t, done) => {
25
+ const conn = makeConnection()
26
+ conn.transaction.parse_body = false
27
+ plugin.hook_data((rc) => {
28
+ assert.equal(rc, undefined)
29
+ assert.equal(conn.transaction.parse_body, true)
30
+ done()
31
+ }, conn)
32
+ })
33
+
34
+ it('calls next when there is no transaction', (t, done) => {
35
+ const conn = fixtures.connection.createConnection()
36
+ conn.transaction = null
37
+ plugin.hook_data((rc) => {
38
+ assert.equal(rc, undefined)
39
+ done()
40
+ }, conn)
41
+ })
42
+ })
43
+
44
+ describe('hook_data_post', () => {
45
+ it('calls next when there is no transaction', (t, done) => {
46
+ const conn = fixtures.connection.createConnection()
47
+ conn.transaction = null
48
+ plugin.hook_data_post((rc) => {
49
+ assert.equal(rc, undefined)
50
+ done()
51
+ }, conn)
52
+ })
53
+
54
+ it('calls next when signature list is empty', (t, done) => {
55
+ plugin.config.get = (name, type) => (type === 'list' ? [] : {})
56
+ const conn = makeConnection('This is some email body text')
57
+ plugin.hook_data_post((rc) => {
58
+ assert.equal(rc, undefined)
59
+ done()
60
+ }, conn)
61
+ })
62
+
63
+ it('denies when body matches a signature', (t, done) => {
64
+ plugin.config.get = (name, type) => (type === 'list' ? ['spam_signature_text'] : {})
65
+ const conn = makeConnection('Buy cheap meds! spam_signature_text here')
66
+ plugin.hook_data_post((rc, msg) => {
67
+ assert.equal(rc, DENY)
68
+ assert.ok(msg.includes('spam'))
69
+ done()
70
+ }, conn)
71
+ })
72
+
73
+ it('calls next when body does not match any signature', (t, done) => {
74
+ plugin.config.get = (name, type) => (type === 'list' ? ['bad_pattern'] : {})
75
+ const conn = makeConnection('Totally normal email body')
76
+ plugin.hook_data_post((rc) => {
77
+ assert.equal(rc, undefined)
78
+ done()
79
+ }, conn)
80
+ })
81
+
82
+ it('denies when a child body part matches a signature', (t, done) => {
83
+ plugin.config.get = (name, type) => (type === 'list' ? ['spam_in_child'] : {})
84
+ const conn = fixtures.connection.createConnection()
85
+ conn.init_transaction()
86
+ conn.transaction.body = {
87
+ bodytext: 'clean parent text',
88
+ children: [{ bodytext: 'spam_in_child content here', children: [] }],
89
+ }
90
+ plugin.hook_data_post((rc, msg) => {
91
+ assert.equal(rc, DENY)
92
+ done()
93
+ }, conn)
94
+ })
95
+
96
+ it('calls next when multiple signatures do not match', (t, done) => {
97
+ plugin.config.get = (name, type) => (type === 'list' ? ['sig_one', 'sig_two', 'sig_three'] : {})
98
+ const conn = makeConnection('No matching signatures here at all')
99
+ plugin.hook_data_post((rc) => {
100
+ assert.equal(rc, undefined)
101
+ done()
102
+ }, conn)
103
+ })
104
+
105
+ it('matches the first of multiple signatures', (t, done) => {
106
+ plugin.config.get = (name, type) => (type === 'list' ? ['no_match', 'buy_cheap_pills'] : {})
107
+ const conn = makeConnection('This message has buy_cheap_pills for you')
108
+ plugin.hook_data_post((rc) => {
109
+ assert.equal(rc, DENY)
110
+ done()
111
+ }, conn)
112
+ })
113
+ })
114
+ })