@haraka/test-fixtures 0.0.0-stage → 2.0.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,346 @@
1
+ # Changelog
2
+
3
+ The format is based on [Keep a Changelog](https://keepachangelog.com/).
4
+
5
+ ### Unreleased
6
+
7
+ ### [2.0.1] - 2026-12-04
8
+
9
+ - fix: responders take numeric return codes
10
+ - fix: rcpt_respond: CONT is OK when relaying
11
+ - fix: add Connection.fail() for client close
12
+ - fix: inherits() compiles the parent once
13
+ - fix: quote package plugin paths safely
14
+
15
+ ### [2.0.0] - 2026-12-04
16
+
17
+ - change: renamed to @haraka/test-fixtures
18
+ - change: ESM; .d.ts generated from JSDoc
19
+ - change: require Node 24+
20
+ - change: remove util_hmailitem
21
+ - feat: load ES module plugins
22
+ - dep: use the @haraka/* libraries
23
+ - fix: HARAKA env no longer breaks plugin config
24
+
25
+ ### [1.7.2] - 2026-06-20
26
+
27
+ - fix: strip `haraka-plugin-` prefix from `plugin.name`, matching Haraka
28
+ - refactor: replace a few == with ===
29
+
30
+ ### [1.7.1] - 2026-06-02
31
+
32
+ - feat: makeConnection server option (second arg)
33
+ - feat: makeConnection host option (sets remote.host)
34
+ - feat: makeConnection silent + stubLogs options
35
+
36
+ ### [1.7.0] - 2026-05-28
37
+
38
+ - feat: helpers — makePlugin, makeConnection, getResult, callHook
39
+ - feat: typed call<Hook> helpers
40
+ - feat: assertion helpers — assertCont, assertOk, assertDeny, assertResult
41
+ - feat: makePlugin configDir; makeConnection mailFrom/rcptTo/notes/txNotes
42
+ - feat: dispatcher accepts both 3.x callback and 4.0 async/return hooks
43
+
44
+ ### [1.6.2] - 2026-05-28
45
+
46
+ - fix(plugin): restored not-redundant \_compile()
47
+
48
+ ### [1.6.1] - 2026-05-28
49
+
50
+ - doc(README): update example to use node:test imports and scoped let
51
+ - fix(connection): return → continue in setTLS() loop
52
+ - fix(connection): guarded server.address() with typeof + fallback
53
+ - fix(plugin): removed redundant \_compile()
54
+ - fix(plugin): `"use strict";\n` so trailing // comments can't swallow the rest
55
+ - fix(plugin): escape " in packageDir before interpolation
56
+ - deps: bumped to latest
57
+
58
+ ### [1.6.0] - 2026-05-17
59
+
60
+ - feat(dns): add configurable DNS server fixture (`fixtures.dns`)
61
+ - fix(connection): respond() no longer throws when called w/o a cb
62
+ - test: test runner is now node:test
63
+ - test: raise coverage of connection/logger/stub responders
64
+
65
+ ### [1.5.1] - 2026-05-15
66
+
67
+ - fix(plugin): treat unresolved core plugin as noop
68
+
69
+ ### [1.5.0] - 2026-05-15
70
+
71
+ - dep(address-rfc2821): upgraded to @haraka/email-message
72
+
73
+ ### [1.4.3] - 2026-05-10
74
+
75
+ - dep(email-message): update to 1.3.3
76
+
77
+ ### [1.4.2] - 2026-05-06
78
+
79
+ - ci: tighten up GHA workflow files permissions
80
+ - deps: bump versions
81
+
82
+ ### [1.4.1] - 2026-03-23
83
+
84
+ - fix(plugin): use correct config in setup #76
85
+ - chore(plugin): refactor || into for loop
86
+ - break: delete vm_harness (no longer used)
87
+ - style: add some node: prefixes
88
+
89
+ ### [1.4.0] - 2026-03-17
90
+
91
+ - plugin: imported more plugin functions
92
+ - plugin: sync closer to Haraka/plugin.js
93
+ - added more fns, run code in current context
94
+ - conn: add ipaddr dep, used in setupClient #74
95
+ - test: remove done callbacks in synchronous tests #73
96
+ - test: add coverage to get_plugin_path
97
+ - conn: imported more SMTP state machine functions
98
+ - pause, resume, process_data|line, disconnect
99
+ - conn: add ipaddr dep, used in setupClient
100
+ - line_socket: added event emitters, still needs TLS
101
+ - logger: synced closer to Haraka/logger
102
+ - deps: bump all versions to latest
103
+
104
+ ### [1.3.10] - 2025-06-15
105
+
106
+ - dep(all): bump versions
107
+ - logger: only check for PROTOCOL once #71
108
+
109
+ ### [1.3.9] - 2025-01-31
110
+
111
+ - vm_harness: access local files in plugin directory #68
112
+ - dep(all): bump versions
113
+ - dep(eslint): upgrade to v9
114
+
115
+ ### [1.3.8] - 2024-09-27
116
+
117
+ - bumped dep versions:
118
+ - haraka-config: 1.4.0
119
+ - haraka-constants: 1.0.7
120
+ - haraka-email-message: 1.2.4
121
+ - haraka-notes: 1.1.0
122
+ - haraka-results: 2.2.4
123
+ - haraka-utils: 1.1.3
124
+ - @haraka/eslint-config: 1.1.5
125
+
126
+ ### [1.3.7] - 2024-04-14
127
+
128
+ - transaction: sync with haraka/Haraka
129
+ - connection: import more from haraka/Haraka/connection
130
+ - test(conn): expect more connection properties
131
+ - doc(README): added example setup
132
+
133
+ ### [1.3.6] - 2024-04-09
134
+
135
+ - doc(CONTRIBUTING): added
136
+
137
+ ### [1.3.5] - 2024-04-07
138
+
139
+ - update package.json scripts
140
+ - dep: eslint-plugin-haraka -> @haraka/eslint-config
141
+ - update .eslintrc
142
+
143
+ ### [1.3.4] - 2024-04-05
144
+
145
+ - populate [files] in package.json
146
+ - plugin: fix comment typo
147
+ - doc(README): verbiage improvements
148
+ - dep(address-rfc2821): bump from 2.1.1 to 2.1.2 #61
149
+ - deps: bump to latest
150
+
151
+ ### [1.3.3] - 2023-12-12
152
+
153
+ - deps(\*): pin versions to latest
154
+
155
+ ### [1.3.2] - 2023-12-12
156
+
157
+ - dep(haraka-results): bump version to 2.2.3
158
+
159
+ ### [1.3.1] - 2023-12-03
160
+
161
+ - transaction: update Buffer syntax (sync with Haraka) #56
162
+
163
+ ### [1.3.0] - 2023-06-08
164
+
165
+ - dep(haraka-results): require at least 2.2 (due to redis dep)
166
+
167
+ ### [1.2.1] - 2022-07-07
168
+
169
+ - ci: use windows & ubuntu workflows in haraka/.github
170
+
171
+ ### [1.2.0] - 2022-06-27
172
+
173
+ - dep: replace message-stream with email-message
174
+ - transaction: replace Header and Body stubs with email-message
175
+ - lint: string concatenation
176
+
177
+ ### [1.1.0] - 2022-06-23
178
+
179
+ - dep: add haraka-message-stream
180
+ - transaction: added Body
181
+ - transaction: added MessageStream
182
+
183
+ ### [1.0.35] - 2022-06-05
184
+
185
+ - ci: update GHA workflow with shared
186
+ - doc(changes): add Unreleased marker
187
+ - ci: add submodule .release
188
+
189
+ ### [1.0.34] - 2022-05-23
190
+
191
+ - dep(eslint): 6 -> 8
192
+ - ci(node): add v18 testing
193
+
194
+ ### 1.0.33 - 2020-12-17
195
+
196
+ - conn: pass config to new transactions
197
+
198
+ ### 1.0.32 - 2020-07-28
199
+
200
+ - transaction: add logging methods
201
+
202
+ ### 1.0.31 - 2020-07-28
203
+
204
+ - transaction: lowercase the keys in class Header
205
+
206
+ ### 1.0.30 - 2019-10-14
207
+
208
+ - codeclimate: update eslint to v6
209
+ - convert eslintrc from json to yaml
210
+ - replace node 6 with node 12 CI testing
211
+ - lib/plugin: update with es6 class
212
+ - es6: object-shorthand
213
+ - coverage: replace deprecated istanbul with nyc
214
+ - test runner: replace deprecated nodeunit with mocha
215
+
216
+ ### 1.0.29 - 2019-04-11
217
+
218
+ - put results in transaction. This time for real.
219
+
220
+ ### 1.0.28 - 2019-04-01
221
+
222
+ - transaction: populate this.results
223
+
224
+ ### 1.0.27 - 2018-11-15
225
+
226
+ - transaction: have header.add() populate header_decoded too
227
+
228
+ ### 1.0.26 - 2018-11-15
229
+
230
+ - transaction: add header.get_decoded()
231
+
232
+ ### 1.0.25 - 2018-05-10
233
+
234
+ - transaction: make t.header a class (as it is in Haraka). Making transaction
235
+ into an es6 class (in 1.0.24) changed how 'this' resolves.
236
+
237
+ ### 1.0.24 - 2018-05-10
238
+
239
+ - connection: add get() and improved set()
240
+ - connection: add init_transaction()
241
+ - connection: use es6 classes
242
+ - transaction: use es6 classes
243
+
244
+ ### 1.0.23 - 2018-04-04
245
+
246
+ - added array values to transaction.header and header.get_all support
247
+
248
+ ### 1.0.22 - 2017-09-22
249
+
250
+ - plugins: provide haraka_require
251
+
252
+ ### 1.0.21 - 2017-09-14
253
+
254
+ - lint updates
255
+
256
+ ### 1.0.20 - 2017-09-04
257
+
258
+ - use [haraka-notes](https://github.com/haraka/haraka-notes)
259
+
260
+ ### 1.0.19 - 2017-06-16
261
+
262
+ - remove version from haraka-results, fixes #21
263
+
264
+ ### 1.0.18 - 2017-05-25
265
+
266
+ - replace local rules with eslint-plugin-haraka
267
+ - add server and setImmedate to the plugin sandbox
268
+
269
+ ### 1.0.17 - 2017-01-26
270
+
271
+ - add alias of haraka-results at fixtures.results (finger friendly)
272
+
273
+ ### 1.0.16 - Jan 26, 2017
274
+
275
+ - replace copied results_store with freshly packaged haraka-results
276
+
277
+ ### 1.0.15 - Jan 25, 2017
278
+
279
+ - update result_store, adding get(plugin) syntax.
280
+
281
+ ### 1.0.14 - Jan 24, 2017
282
+
283
+ - add path for npm packaged plugin inheriting an npm packaged plugin
284
+
285
+ ### 1.0.13 - Jan 03, 2017
286
+
287
+ - use path.join in place of path/to/stuff
288
+ - remove grunt
289
+ - add Appveyor badge
290
+
291
+ ### 1.0.11 - Jan 01, 2017
292
+
293
+ - lint fixes
294
+ - packaging updates
295
+
296
+ ### 1.0.8 - Sep 02, 2016
297
+
298
+ - add connection.set()
299
+
300
+ ### 1.0.7 - Jul 20, 2016
301
+
302
+ - normalized connection properties (haraka/Haraka#1098)
303
+
304
+ ### 1.0.6 - Mar 26, 2016
305
+
306
+ - more reliable package.json detection
307
+ - encapsulate package.json detection in \_has_package_json
308
+ - don't reset plugin.name when a plugin inherits
309
+
310
+ ### 1.0.5 - Mar 19, 2016
311
+
312
+ - inheritance tests and package support
313
+ - enable more Haraka tests to depend on this
314
+ - updates for compat with Haraka/tests/plugins
315
+ - better plugin path resolution
316
+
317
+ [1.0.34]: https://github.com/haraka/test-fixtures/releases/tag/1.0.34
318
+ [1.0.35]: https://github.com/haraka/test-fixtures/releases/tag/1.0.35
319
+ [1.1.0]: https://github.com/haraka/test-fixtures/releases/tag/v1.1.0
320
+ [1.2.0]: https://github.com/haraka/test-fixtures/releases/tag/v1.2.0
321
+ [1.2.1]: https://github.com/haraka/test-fixtures/releases/tag/v1.2.1
322
+ [1.3.0]: https://github.com/haraka/test-fixtures/releases/tag/v1.3.0
323
+ [1.3.1]: https://github.com/haraka/test-fixtures/releases/tag/v1.3.1
324
+ [1.3.2]: https://github.com/haraka/test-fixtures/releases/tag/v1.3.2
325
+ [1.3.3]: https://github.com/haraka/test-fixtures/releases/tag/v1.3.3
326
+ [1.3.4]: https://github.com/haraka/test-fixtures/releases/tag/v1.3.4
327
+ [1.3.5]: https://github.com/haraka/test-fixtures/releases/tag/v1.3.5
328
+ [1.3.6]: https://github.com/haraka/test-fixtures/releases/tag/v1.3.6
329
+ [1.3.7]: https://github.com/haraka/test-fixtures/releases/tag/v1.3.7
330
+ [1.3.8]: https://github.com/haraka/test-fixtures/releases/tag/v1.3.8
331
+ [1.3.9]: https://github.com/haraka/test-fixtures/releases/tag/v1.3.9
332
+ [1.3.10]: https://github.com/haraka/test-fixtures/releases/tag/v1.3.10
333
+ [1.4.0]: https://github.com/haraka/test-fixtures/releases/tag/v1.4.0
334
+ [1.4.1]: https://github.com/haraka/test-fixtures/releases/tag/v1.4.1
335
+ [1.4.2]: https://github.com/haraka/test-fixtures/releases/tag/v1.4.2
336
+ [1.4.3]: https://github.com/haraka/test-fixtures/releases/tag/v1.4.3
337
+ [1.5.0]: https://github.com/haraka/test-fixtures/releases/tag/v1.5.0
338
+ [1.5.1]: https://github.com/haraka/test-fixtures/releases/tag/v1.5.1
339
+ [1.6.0]: https://github.com/haraka/test-fixtures/releases/tag/v1.6.0
340
+ [1.6.1]: https://github.com/haraka/test-fixtures/releases/tag/v1.6.1
341
+ [1.6.2]: https://github.com/haraka/test-fixtures/releases/tag/v1.6.2
342
+ [1.7.0]: https://github.com/haraka/test-fixtures/releases/tag/v1.7.0
343
+ [1.7.1]: https://github.com/haraka/test-fixtures/releases/tag/v1.7.1
344
+ [1.7.2]: https://github.com/haraka/test-fixtures/releases/tag/v1.7.2
345
+ [2.0.0]: https://github.com/haraka/test-fixtures/releases/tag/v2.0.0
346
+ [2.0.1]: https://github.com/haraka/test-fixtures/releases/tag/v2.0.1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Haraka
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,264 @@
1
- # Temporary Holding Version
1
+ [![Test][ci-img]][ci-url] [![Cover][cov-img]][cov-url] [![Qlty][qlty-img]][qlty-url]
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # @haraka/test-fixtures
4
+
5
+ Fixtures for testing Haraka and plugins. Requires Node.js 24 or later.
6
+
7
+ ## Usage
8
+
9
+ ```js
10
+ import * as fixtures from '@haraka/test-fixtures'
11
+ ```
12
+
13
+ ### Quick-start
14
+
15
+ ```js
16
+ import { beforeEach, describe, it } from 'node:test'
17
+
18
+ import { makePlugin, makeConnection, callRcpt, assertDeny, assertResult } from '@haraka/test-fixtures'
19
+
20
+ describe('my-plugin', () => {
21
+ let plugin, conn
22
+
23
+ beforeEach(() => {
24
+ plugin = makePlugin('my-plugin', { configDir: import.meta.dirname })
25
+ conn = makeConnection({ ip: '1.2.3.4', mailFrom: 'sender@example.com' })
26
+ })
27
+
28
+ it('rejects relay attempts', async () => {
29
+ const r = await callRcpt(plugin, conn, 'rcpt@other.com')
30
+ assertDeny(r, /relay/)
31
+ assertResult(conn, plugin, 'fail', /^no_relay/)
32
+ })
33
+ })
34
+ ```
35
+
36
+ That's the whole pattern: `makePlugin` + `makeConnection` + a typed `call<Hook>` +
37
+ optional `assert<...>` helpers. Compose into domain-specific helpers per test
38
+ file when it pays off (see `plugin/aliases/test/index.js` for a good example).
39
+
40
+ ## Exports
41
+
42
+ - connection
43
+ - dns
44
+ - helpers, hooks, assertions _(see below)_
45
+ - line_socket
46
+ - logger
47
+ - plugin
48
+ - [results](https://github.com/haraka/haraka-results)
49
+ - stub
50
+ - transaction
51
+
52
+ These fixtures are analogs of their like-named siblings in Haraka with varying levels of completeness. If there are functions necessary to enhance your ability to test, please do add them.
53
+
54
+ ## Plugin loading
55
+
56
+ `makePlugin(name)` and `new fixtures.plugin(name)` load a plugin, then copy its exports onto the Plugin:
57
+
58
+ - an ES module, as a single file or a package, is loaded with `require()`
59
+ - a legacy plugin script (`exports.hook_mail = function …`) runs in a vm sandbox
60
+
61
+ ---
62
+
63
+ ## helpers — `makePlugin`, `makeConnection`, `getResult`, `callHook`
64
+
65
+ ### `makePlugin(name, opts?)` → Plugin
66
+
67
+ ```js
68
+ makePlugin('helo.checks') // + register()
69
+ makePlugin('helo.checks', { register: false }) // skip register()
70
+ makePlugin('access', { configDir: import.meta.dirname }) // override plugin.config root
71
+ ```
72
+
73
+ `configDir` runs `plugin.config.module_config(path.resolve(configDir))` _before_
74
+ `register()`, replacing the very common idiom
75
+ `plugin.config = plugin.config.module_config(path.resolve('test'))`.
76
+
77
+ ### `makeConnection(opts?)` → Connection
78
+
79
+ | Option | Default | Description |
80
+ | ---------- | ------------- | ------------------------------------------------------------------------------------------------- |
81
+ | `ip` | `'127.0.0.1'` | `remote.ip` |
82
+ | `relaying` | `false` | `connection._relaying` |
83
+ | `helo` | _(unset)_ | sets `hello.host` + `hello.verb = 'EHLO'` |
84
+ | `withTxn` | `false` | calls `init_transaction()` |
85
+ | `mailFrom` | — | string \| Address; coerced and assigned to `transaction.mail_from`. Implies a transaction. |
86
+ | `rcptTo` | — | array of string \| Address; coerced and assigned to `transaction.rcpt_to`. Implies a transaction. |
87
+ | `notes` | — | object merged into `connection.notes` |
88
+ | `txNotes` | — | object merged into `transaction.notes`. Implies a transaction. |
89
+ | `server` | `{}` | becomes `connection.server`; use for `server.notes.*` injection (e.g. shared redis handle). |
90
+ | `host` | — | `remote.host` (rDNS hostname) |
91
+ | `silent` | `false` | replace every log method (`loginfo`, `logwarn`, etc.) with a no-op |
92
+ | `stubLogs` | `false` | replace every log method with a recording `stub()`; assert on `conn.loginfo.args` etc. |
93
+
94
+ ```js
95
+ const conn = makeConnection({
96
+ ip: '1.2.3.4',
97
+ mailFrom: 'sender@example.com',
98
+ rcptTo: ['rcpt@example.com'],
99
+ txNotes: { spamd_user: 'tx' },
100
+ })
101
+ ```
102
+
103
+ ### `getResult(connection, pluginOrName)` → result object
104
+
105
+ Returns `connection.results.get(plugin)` with an empty-bucket fallback so callers
106
+ can read `.pass.length` etc. without null checks.
107
+
108
+ ### `callHook(plugin, method, connection, ...args)` → `Promise<{rc, msg}>`
109
+
110
+ The generic Promise-wrap of a hook callback. **Prefer the typed `callXxx` helpers
111
+ below** when one fits — they're more readable and resolve the method name
112
+ automatically. Reach for `callHook` for hooks without a typed wrapper, or to
113
+ target a specific method by name.
114
+
115
+ ---
116
+
117
+ ## hooks — typed `call<Hook>` helpers
118
+
119
+ Each helper accepts natural args (string addresses instead of `[new Address('<x>'), {}]`),
120
+ resolves the method name automatically via `plugin.hooks[hookName]` (with `hook_<name>`
121
+ and bare `<name>` fallbacks), and returns `Promise<{rc, msg}>`.
122
+
123
+ ```js
124
+ const { rc, msg } = await callMail(plugin, conn, 'sender@example.com')
125
+ const { rc } = await callRcpt(plugin, conn, 'rcpt@example.com')
126
+ const { rc } = await callConnect(plugin, conn)
127
+ const { rc } = await callHelo(plugin, conn, 'mail.example.com')
128
+ const { rc } = await callDataPost(plugin, conn)
129
+ ```
130
+
131
+ | Helper | Hook | Hook args |
132
+ | ------------------------------- | ------------ | ------------------------------ |
133
+ | `callConnect(p, c)` | `connect` | `(next, c)` |
134
+ | `callHelo(p, c, host)` | `helo` | `(next, c, host)` |
135
+ | `callEhlo(p, c, host)` | `ehlo` | `(next, c, host)` |
136
+ | `callMail(p, c, from, params?)` | `mail` | `(next, c, [Address, params])` |
137
+ | `callRcpt(p, c, rcpt, params?)` | `rcpt` | `(next, c, [Address, params])` |
138
+ | `callRcptOk(p, c, rcpt)` | `rcpt_ok` | `(next, c, Address)` |
139
+ | `callData(p, c)` | `data` | `(next, c)` |
140
+ | `callDataPost(p, c)` | `data_post` | `(next, c)` |
141
+ | `callQueue(p, c)` | `queue` | `(next, c)` |
142
+ | `callQueueOk(p, c, msg)` | `queue_ok` | `(next, c, msg)` |
143
+ | `callDisconnect(p, c)` | `disconnect` | `(next, c)` |
144
+
145
+ All `callXxx` helpers (and `callHook`) accept an explicit method-name override as
146
+ their last argument — useful when a plugin registers multiple methods on one hook.
147
+
148
+ ### Forward-compat with Haraka 4.0 promise hooks
149
+
150
+ The dispatcher under the hood accepts both the 3.x callback style and an
151
+ async/return-value style anticipated for 4.0. A plugin author can write either:
152
+
153
+ ```js
154
+ // 3.x
155
+ exports.hook_mail = function (next, connection, params) {
156
+ next(DENY, 'no thanks')
157
+ }
158
+
159
+ // 4.0 (any of these forms work today through the test helpers)
160
+ exports.hook_mail = async function (connection, params) {
161
+ return DENY // bare rc
162
+ }
163
+ exports.hook_mail = async function (connection, params) {
164
+ return { rc: DENY, msg: 'no thanks' }
165
+ }
166
+ exports.hook_mail = async function (connection, params) {
167
+ return [DENY, 'no thanks']
168
+ }
169
+ ```
170
+
171
+ …and the test code stays identical:
172
+
173
+ ```js
174
+ const r = await callMail(plugin, conn, 'sender@example.com')
175
+ assertDeny(r, /no thanks/)
176
+ ```
177
+
178
+ When Haraka 4 ships, the test suites you write today migrate without changes.
179
+
180
+ ---
181
+
182
+ ## assertions
183
+
184
+ Small wrappers around the most common assertion patterns. All accept either a raw
185
+ `rc` or the `{rc, msg}` result object returned by `callXxx`, so destructuring is
186
+ optional.
187
+
188
+ ```js
189
+ import { assertCont, assertOk, assertDeny, assertResult } from '@haraka/test-fixtures'
190
+
191
+ assertCont(r) // rc is undefined or CONT
192
+ assertOk(r, /accepted/) // rc === OK + optional msg match
193
+ assertDeny(r) // rc is any DENY* code
194
+ assertDeny(r, /no thanks/) // + msg matches
195
+ assertDeny(r, /no thanks/, DENYSOFT) // + specific code
196
+
197
+ assertResult(conn, plugin, 'pass') // results.get(plugin).pass non-empty
198
+ assertResult(conn, plugin, 'pass', /^connect:/)
199
+ ```
200
+
201
+ Anything more specific (e.g. "asserts an alias mapped to the right address")
202
+ belongs as a test-local helper, not in this library. See
203
+ `plugin/aliases/test/index.js` for the pattern.
204
+
205
+ ---
206
+
207
+ ## stub
208
+
209
+ `fixtures.stub` creates a stub function that records all calls.
210
+
211
+ ```js
212
+ import { stub } from '@haraka/test-fixtures'
213
+
214
+ const s = stub('return-value')
215
+ s('arg1', 'arg2')
216
+
217
+ s.called // true
218
+ s.callCount // 1
219
+ s.args // ['arg1', 'arg2'] (last call)
220
+ s.calls // [['arg1', 'arg2']] (every call)
221
+ s.reset() // clears all tracking state
222
+ ```
223
+
224
+ ---
225
+
226
+ ### dns
227
+
228
+ A tiny, zero-dependency test DNS server (UDP) for exercising the real
229
+ `node:dns` → `@haraka/net-utils` → plugin path.
230
+ Configure per-name records and failure modes, then point a resolver at it.
231
+
232
+ ```js
233
+ import * as fixtures from '@haraka/test-fixtures'
234
+
235
+ const dns = await fixtures.dns.start({
236
+ 'good.example': {
237
+ a: ['1.2.3.4'],
238
+ mx: [{ preference: 10, exchange: 'mx.good.example' }],
239
+ },
240
+ 'broken.example': { rcode: 'SERVFAIL' }, // also NXDOMAIN | REFUSED | NOERROR
241
+ 'slow.example': { a: ['1.2.3.4'], delayMs: 200 },
242
+ 'gone.example': { drop: true }, // never answers -> resolver timeout
243
+ })
244
+
245
+ // a fresh node:dns Resolver pointed at the test server
246
+ const resolver = dns.resolver({ timeout: 500 })
247
+ await resolver.resolveMx('good.example')
248
+
249
+ // or point an existing Resolver, or anything with getDnsResolver(), at it:
250
+ import * as net_utils from '@haraka/net-utils'
251
+ const restore = dns.patch(net_utils)
252
+ // ... run code that calls net_utils.get_mx() ...
253
+ restore()
254
+
255
+ dns.setZone('good.example', { rcode: 'SERVFAIL' }) // mutate at runtime
256
+ await dns.close()
257
+ ```
258
+
259
+ [ci-img]: https://github.com/haraka/test-fixtures/actions/workflows/ci.yml/badge.svg
260
+ [ci-url]: https://github.com/haraka/test-fixtures/actions/workflows/ci.yml
261
+ [cov-img]: https://codecov.io/github/haraka/test-fixtures/graph/badge.svg?token=YmOC83OqCH
262
+ [cov-url]: https://codecov.io/github/haraka/test-fixtures
263
+ [qlty-img]: https://qlty.sh/gh/haraka/projects/haraka-test-fixtures/maintainability.svg
264
+ [qlty-url]: https://qlty.sh/gh/haraka/projects/haraka-test-fixtures
@@ -0,0 +1,64 @@
1
+ ; address to listen on (default: all IPv6 and IPv4 addresses, port 25)
2
+ ; use "[::0]:25" to listen on IPv6 and IPv4 (not all OSes)
3
+ ;listen=[::0]:25
4
+
5
+ ; Note you can listen on multiple IPs/ports using commas:
6
+ ;listen=127.0.0.1:2529,127.0.0.2:2529,127.0.0.3:2530
7
+
8
+ ; public IP address (default: none)
9
+ ; If your machine is behind a NAT, some plugins (SPF, GeoIP) gain features
10
+ ; if they know the servers public IP. If 'stun' is installed, Haraka will
11
+ ; try to figure it out. If that doesn't work, set it here.
12
+ ;public_ip=N.N.N.N
13
+
14
+ ; Time in seconds to let sockets be idle with no activity
15
+ ;inactivity_timeout=300
16
+
17
+ ; Drop privileges to this user/group
18
+ ;user=smtp
19
+ ;group=smtp
20
+
21
+ ; Don't stop Haraka if plugins fail to compile
22
+ ;ignore_bad_plugins=0
23
+
24
+ ; Run using cluster to fork multiple backend processes
25
+ ;nodes=cpus
26
+
27
+ ; Daemonize
28
+ ;daemonize=true
29
+ ;daemon_log_file=/var/log/haraka.log
30
+ ;daemon_pid_file=/var/run/haraka.pid
31
+
32
+ ; Spooling
33
+ ; Save memory by spooling large messages to disk
34
+ ;spool_dir=/var/spool/haraka
35
+ ; Specify -1 to never spool to disk
36
+ ; Specify 0 to always spool to disk
37
+ ; Otherwise specify a size in bytes, once reached the
38
+ ; message will be spooled to disk to save memory.
39
+ ;spool_after=
40
+
41
+ ; Force Shutdown Timeout
42
+ ; - Haraka tries to close down gracefully, but if everything is shut down
43
+ ; after this time it will hard close. 30s is usually long enough to
44
+ ; wait for outbound connections to finish.
45
+ ;force_shutdown_timeout=30
46
+
47
+ ; SMTP service extensions: https://tools.ietf.org/html/rfc1869
48
+ ; strict_rfc1869 = false
49
+
50
+ ; Advertise support for SMTPTUF8 (RFC-6531)
51
+ ;smtputf8=true
52
+
53
+ [headers]
54
+ ;add_received=true
55
+ ;clean_auth_results=true
56
+
57
+ ; replace header_hide_version
58
+ ;show_version=true
59
+
60
+ ; replace max_header_lines
61
+ max_lines=1000
62
+
63
+ ; replace max_received_count
64
+ max_received=100