@haraka/test-fixtures 0.0.0-stage → 2.0.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/CHANGELOG.md +337 -0
- package/LICENSE +21 -0
- package/README.md +263 -2
- package/config/smtp.ini +64 -0
- package/index.js +41 -0
- package/lib/assertions.js +111 -0
- package/lib/connection.js +579 -0
- package/lib/dns.js +206 -0
- package/lib/helpers.js +150 -0
- package/lib/hooks.js +123 -0
- package/lib/invoke.js +55 -0
- package/lib/line_socket.js +68 -0
- package/lib/logger.js +125 -0
- package/lib/plugin.js +320 -0
- package/lib/stub.js +50 -0
- package/lib/transaction.js +270 -0
- package/package.json +72 -4
- package/types/index.d.ts +19 -0
- package/types/lib/assertions.d.ts +54 -0
- package/types/lib/connection.d.ts +144 -0
- package/types/lib/dns.d.ts +15 -0
- package/types/lib/helpers.d.ts +98 -0
- package/types/lib/hooks.d.ts +54 -0
- package/types/lib/invoke.d.ts +26 -0
- package/types/lib/line_socket.d.ts +14 -0
- package/types/lib/logger.d.ts +42 -0
- package/types/lib/plugin.d.ts +30 -0
- package/types/lib/stub.d.ts +38 -0
- package/types/lib/transaction.d.ts +72 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/).
|
|
4
|
+
|
|
5
|
+
### Unreleased
|
|
6
|
+
|
|
7
|
+
### [2.0.0] - 2026-12-04
|
|
8
|
+
|
|
9
|
+
- change: renamed to @haraka/test-fixtures
|
|
10
|
+
- change: ESM; .d.ts generated from JSDoc
|
|
11
|
+
- change: require Node 24+
|
|
12
|
+
- change: remove util_hmailitem
|
|
13
|
+
- feat: load ES module plugins
|
|
14
|
+
- dep: use the @haraka/* libraries
|
|
15
|
+
- fix: HARAKA env no longer breaks plugin config
|
|
16
|
+
|
|
17
|
+
### [1.7.2] - 2026-06-20
|
|
18
|
+
|
|
19
|
+
- fix: strip `haraka-plugin-` prefix from `plugin.name`, matching Haraka
|
|
20
|
+
- refactor: replace a few == with ===
|
|
21
|
+
|
|
22
|
+
### [1.7.1] - 2026-06-02
|
|
23
|
+
|
|
24
|
+
- feat: makeConnection server option (second arg)
|
|
25
|
+
- feat: makeConnection host option (sets remote.host)
|
|
26
|
+
- feat: makeConnection silent + stubLogs options
|
|
27
|
+
|
|
28
|
+
### [1.7.0] - 2026-05-28
|
|
29
|
+
|
|
30
|
+
- feat: helpers — makePlugin, makeConnection, getResult, callHook
|
|
31
|
+
- feat: typed call<Hook> helpers
|
|
32
|
+
- feat: assertion helpers — assertCont, assertOk, assertDeny, assertResult
|
|
33
|
+
- feat: makePlugin configDir; makeConnection mailFrom/rcptTo/notes/txNotes
|
|
34
|
+
- feat: dispatcher accepts both 3.x callback and 4.0 async/return hooks
|
|
35
|
+
|
|
36
|
+
### [1.6.2] - 2026-05-28
|
|
37
|
+
|
|
38
|
+
- fix(plugin): restored not-redundant \_compile()
|
|
39
|
+
|
|
40
|
+
### [1.6.1] - 2026-05-28
|
|
41
|
+
|
|
42
|
+
- doc(README): update example to use node:test imports and scoped let
|
|
43
|
+
- fix(connection): return → continue in setTLS() loop
|
|
44
|
+
- fix(connection): guarded server.address() with typeof + fallback
|
|
45
|
+
- fix(plugin): removed redundant \_compile()
|
|
46
|
+
- fix(plugin): `"use strict";\n` so trailing // comments can't swallow the rest
|
|
47
|
+
- fix(plugin): escape " in packageDir before interpolation
|
|
48
|
+
- deps: bumped to latest
|
|
49
|
+
|
|
50
|
+
### [1.6.0] - 2026-05-17
|
|
51
|
+
|
|
52
|
+
- feat(dns): add configurable DNS server fixture (`fixtures.dns`)
|
|
53
|
+
- fix(connection): respond() no longer throws when called w/o a cb
|
|
54
|
+
- test: test runner is now node:test
|
|
55
|
+
- test: raise coverage of connection/logger/stub responders
|
|
56
|
+
|
|
57
|
+
### [1.5.1] - 2026-05-15
|
|
58
|
+
|
|
59
|
+
- fix(plugin): treat unresolved core plugin as noop
|
|
60
|
+
|
|
61
|
+
### [1.5.0] - 2026-05-15
|
|
62
|
+
|
|
63
|
+
- dep(address-rfc2821): upgraded to @haraka/email-message
|
|
64
|
+
|
|
65
|
+
### [1.4.3] - 2026-05-10
|
|
66
|
+
|
|
67
|
+
- dep(email-message): update to 1.3.3
|
|
68
|
+
|
|
69
|
+
### [1.4.2] - 2026-05-06
|
|
70
|
+
|
|
71
|
+
- ci: tighten up GHA workflow files permissions
|
|
72
|
+
- deps: bump versions
|
|
73
|
+
|
|
74
|
+
### [1.4.1] - 2026-03-23
|
|
75
|
+
|
|
76
|
+
- fix(plugin): use correct config in setup #76
|
|
77
|
+
- chore(plugin): refactor || into for loop
|
|
78
|
+
- break: delete vm_harness (no longer used)
|
|
79
|
+
- style: add some node: prefixes
|
|
80
|
+
|
|
81
|
+
### [1.4.0] - 2026-03-17
|
|
82
|
+
|
|
83
|
+
- plugin: imported more plugin functions
|
|
84
|
+
- plugin: sync closer to Haraka/plugin.js
|
|
85
|
+
- added more fns, run code in current context
|
|
86
|
+
- conn: add ipaddr dep, used in setupClient #74
|
|
87
|
+
- test: remove done callbacks in synchronous tests #73
|
|
88
|
+
- test: add coverage to get_plugin_path
|
|
89
|
+
- conn: imported more SMTP state machine functions
|
|
90
|
+
- pause, resume, process_data|line, disconnect
|
|
91
|
+
- conn: add ipaddr dep, used in setupClient
|
|
92
|
+
- line_socket: added event emitters, still needs TLS
|
|
93
|
+
- logger: synced closer to Haraka/logger
|
|
94
|
+
- deps: bump all versions to latest
|
|
95
|
+
|
|
96
|
+
### [1.3.10] - 2025-06-15
|
|
97
|
+
|
|
98
|
+
- dep(all): bump versions
|
|
99
|
+
- logger: only check for PROTOCOL once #71
|
|
100
|
+
|
|
101
|
+
### [1.3.9] - 2025-01-31
|
|
102
|
+
|
|
103
|
+
- vm_harness: access local files in plugin directory #68
|
|
104
|
+
- dep(all): bump versions
|
|
105
|
+
- dep(eslint): upgrade to v9
|
|
106
|
+
|
|
107
|
+
### [1.3.8] - 2024-09-27
|
|
108
|
+
|
|
109
|
+
- bumped dep versions:
|
|
110
|
+
- haraka-config: 1.4.0
|
|
111
|
+
- haraka-constants: 1.0.7
|
|
112
|
+
- haraka-email-message: 1.2.4
|
|
113
|
+
- haraka-notes: 1.1.0
|
|
114
|
+
- haraka-results: 2.2.4
|
|
115
|
+
- haraka-utils: 1.1.3
|
|
116
|
+
- @haraka/eslint-config: 1.1.5
|
|
117
|
+
|
|
118
|
+
### [1.3.7] - 2024-04-14
|
|
119
|
+
|
|
120
|
+
- transaction: sync with haraka/Haraka
|
|
121
|
+
- connection: import more from haraka/Haraka/connection
|
|
122
|
+
- test(conn): expect more connection properties
|
|
123
|
+
- doc(README): added example setup
|
|
124
|
+
|
|
125
|
+
### [1.3.6] - 2024-04-09
|
|
126
|
+
|
|
127
|
+
- doc(CONTRIBUTING): added
|
|
128
|
+
|
|
129
|
+
### [1.3.5] - 2024-04-07
|
|
130
|
+
|
|
131
|
+
- update package.json scripts
|
|
132
|
+
- dep: eslint-plugin-haraka -> @haraka/eslint-config
|
|
133
|
+
- update .eslintrc
|
|
134
|
+
|
|
135
|
+
### [1.3.4] - 2024-04-05
|
|
136
|
+
|
|
137
|
+
- populate [files] in package.json
|
|
138
|
+
- plugin: fix comment typo
|
|
139
|
+
- doc(README): verbiage improvements
|
|
140
|
+
- dep(address-rfc2821): bump from 2.1.1 to 2.1.2 #61
|
|
141
|
+
- deps: bump to latest
|
|
142
|
+
|
|
143
|
+
### [1.3.3] - 2023-12-12
|
|
144
|
+
|
|
145
|
+
- deps(\*): pin versions to latest
|
|
146
|
+
|
|
147
|
+
### [1.3.2] - 2023-12-12
|
|
148
|
+
|
|
149
|
+
- dep(haraka-results): bump version to 2.2.3
|
|
150
|
+
|
|
151
|
+
### [1.3.1] - 2023-12-03
|
|
152
|
+
|
|
153
|
+
- transaction: update Buffer syntax (sync with Haraka) #56
|
|
154
|
+
|
|
155
|
+
### [1.3.0] - 2023-06-08
|
|
156
|
+
|
|
157
|
+
- dep(haraka-results): require at least 2.2 (due to redis dep)
|
|
158
|
+
|
|
159
|
+
### [1.2.1] - 2022-07-07
|
|
160
|
+
|
|
161
|
+
- ci: use windows & ubuntu workflows in haraka/.github
|
|
162
|
+
|
|
163
|
+
### [1.2.0] - 2022-06-27
|
|
164
|
+
|
|
165
|
+
- dep: replace message-stream with email-message
|
|
166
|
+
- transaction: replace Header and Body stubs with email-message
|
|
167
|
+
- lint: string concatenation
|
|
168
|
+
|
|
169
|
+
### [1.1.0] - 2022-06-23
|
|
170
|
+
|
|
171
|
+
- dep: add haraka-message-stream
|
|
172
|
+
- transaction: added Body
|
|
173
|
+
- transaction: added MessageStream
|
|
174
|
+
|
|
175
|
+
### [1.0.35] - 2022-06-05
|
|
176
|
+
|
|
177
|
+
- ci: update GHA workflow with shared
|
|
178
|
+
- doc(changes): add Unreleased marker
|
|
179
|
+
- ci: add submodule .release
|
|
180
|
+
|
|
181
|
+
### [1.0.34] - 2022-05-23
|
|
182
|
+
|
|
183
|
+
- dep(eslint): 6 -> 8
|
|
184
|
+
- ci(node): add v18 testing
|
|
185
|
+
|
|
186
|
+
### 1.0.33 - 2020-12-17
|
|
187
|
+
|
|
188
|
+
- conn: pass config to new transactions
|
|
189
|
+
|
|
190
|
+
### 1.0.32 - 2020-07-28
|
|
191
|
+
|
|
192
|
+
- transaction: add logging methods
|
|
193
|
+
|
|
194
|
+
### 1.0.31 - 2020-07-28
|
|
195
|
+
|
|
196
|
+
- transaction: lowercase the keys in class Header
|
|
197
|
+
|
|
198
|
+
### 1.0.30 - 2019-10-14
|
|
199
|
+
|
|
200
|
+
- codeclimate: update eslint to v6
|
|
201
|
+
- convert eslintrc from json to yaml
|
|
202
|
+
- replace node 6 with node 12 CI testing
|
|
203
|
+
- lib/plugin: update with es6 class
|
|
204
|
+
- es6: object-shorthand
|
|
205
|
+
- coverage: replace deprecated istanbul with nyc
|
|
206
|
+
- test runner: replace deprecated nodeunit with mocha
|
|
207
|
+
|
|
208
|
+
### 1.0.29 - 2019-04-11
|
|
209
|
+
|
|
210
|
+
- put results in transaction. This time for real.
|
|
211
|
+
|
|
212
|
+
### 1.0.28 - 2019-04-01
|
|
213
|
+
|
|
214
|
+
- transaction: populate this.results
|
|
215
|
+
|
|
216
|
+
### 1.0.27 - 2018-11-15
|
|
217
|
+
|
|
218
|
+
- transaction: have header.add() populate header_decoded too
|
|
219
|
+
|
|
220
|
+
### 1.0.26 - 2018-11-15
|
|
221
|
+
|
|
222
|
+
- transaction: add header.get_decoded()
|
|
223
|
+
|
|
224
|
+
### 1.0.25 - 2018-05-10
|
|
225
|
+
|
|
226
|
+
- transaction: make t.header a class (as it is in Haraka). Making transaction
|
|
227
|
+
into an es6 class (in 1.0.24) changed how 'this' resolves.
|
|
228
|
+
|
|
229
|
+
### 1.0.24 - 2018-05-10
|
|
230
|
+
|
|
231
|
+
- connection: add get() and improved set()
|
|
232
|
+
- connection: add init_transaction()
|
|
233
|
+
- connection: use es6 classes
|
|
234
|
+
- transaction: use es6 classes
|
|
235
|
+
|
|
236
|
+
### 1.0.23 - 2018-04-04
|
|
237
|
+
|
|
238
|
+
- added array values to transaction.header and header.get_all support
|
|
239
|
+
|
|
240
|
+
### 1.0.22 - 2017-09-22
|
|
241
|
+
|
|
242
|
+
- plugins: provide haraka_require
|
|
243
|
+
|
|
244
|
+
### 1.0.21 - 2017-09-14
|
|
245
|
+
|
|
246
|
+
- lint updates
|
|
247
|
+
|
|
248
|
+
### 1.0.20 - 2017-09-04
|
|
249
|
+
|
|
250
|
+
- use [haraka-notes](https://github.com/haraka/haraka-notes)
|
|
251
|
+
|
|
252
|
+
### 1.0.19 - 2017-06-16
|
|
253
|
+
|
|
254
|
+
- remove version from haraka-results, fixes #21
|
|
255
|
+
|
|
256
|
+
### 1.0.18 - 2017-05-25
|
|
257
|
+
|
|
258
|
+
- replace local rules with eslint-plugin-haraka
|
|
259
|
+
- add server and setImmedate to the plugin sandbox
|
|
260
|
+
|
|
261
|
+
### 1.0.17 - 2017-01-26
|
|
262
|
+
|
|
263
|
+
- add alias of haraka-results at fixtures.results (finger friendly)
|
|
264
|
+
|
|
265
|
+
### 1.0.16 - Jan 26, 2017
|
|
266
|
+
|
|
267
|
+
- replace copied results_store with freshly packaged haraka-results
|
|
268
|
+
|
|
269
|
+
### 1.0.15 - Jan 25, 2017
|
|
270
|
+
|
|
271
|
+
- update result_store, adding get(plugin) syntax.
|
|
272
|
+
|
|
273
|
+
### 1.0.14 - Jan 24, 2017
|
|
274
|
+
|
|
275
|
+
- add path for npm packaged plugin inheriting an npm packaged plugin
|
|
276
|
+
|
|
277
|
+
### 1.0.13 - Jan 03, 2017
|
|
278
|
+
|
|
279
|
+
- use path.join in place of path/to/stuff
|
|
280
|
+
- remove grunt
|
|
281
|
+
- add Appveyor badge
|
|
282
|
+
|
|
283
|
+
### 1.0.11 - Jan 01, 2017
|
|
284
|
+
|
|
285
|
+
- lint fixes
|
|
286
|
+
- packaging updates
|
|
287
|
+
|
|
288
|
+
### 1.0.8 - Sep 02, 2016
|
|
289
|
+
|
|
290
|
+
- add connection.set()
|
|
291
|
+
|
|
292
|
+
### 1.0.7 - Jul 20, 2016
|
|
293
|
+
|
|
294
|
+
- normalized connection properties (haraka/Haraka#1098)
|
|
295
|
+
|
|
296
|
+
### 1.0.6 - Mar 26, 2016
|
|
297
|
+
|
|
298
|
+
- more reliable package.json detection
|
|
299
|
+
- encapsulate package.json detection in \_has_package_json
|
|
300
|
+
- don't reset plugin.name when a plugin inherits
|
|
301
|
+
|
|
302
|
+
### 1.0.5 - Mar 19, 2016
|
|
303
|
+
|
|
304
|
+
- inheritance tests and package support
|
|
305
|
+
- enable more Haraka tests to depend on this
|
|
306
|
+
- updates for compat with Haraka/tests/plugins
|
|
307
|
+
- better plugin path resolution
|
|
308
|
+
|
|
309
|
+
[1.0.34]: https://github.com/haraka/test-fixtures/releases/tag/1.0.34
|
|
310
|
+
[1.0.35]: https://github.com/haraka/test-fixtures/releases/tag/1.0.35
|
|
311
|
+
[1.1.0]: https://github.com/haraka/test-fixtures/releases/tag/v1.1.0
|
|
312
|
+
[1.2.0]: https://github.com/haraka/test-fixtures/releases/tag/v1.2.0
|
|
313
|
+
[1.2.1]: https://github.com/haraka/test-fixtures/releases/tag/v1.2.1
|
|
314
|
+
[1.3.0]: https://github.com/haraka/test-fixtures/releases/tag/v1.3.0
|
|
315
|
+
[1.3.1]: https://github.com/haraka/test-fixtures/releases/tag/v1.3.1
|
|
316
|
+
[1.3.2]: https://github.com/haraka/test-fixtures/releases/tag/v1.3.2
|
|
317
|
+
[1.3.3]: https://github.com/haraka/test-fixtures/releases/tag/v1.3.3
|
|
318
|
+
[1.3.4]: https://github.com/haraka/test-fixtures/releases/tag/v1.3.4
|
|
319
|
+
[1.3.5]: https://github.com/haraka/test-fixtures/releases/tag/v1.3.5
|
|
320
|
+
[1.3.6]: https://github.com/haraka/test-fixtures/releases/tag/v1.3.6
|
|
321
|
+
[1.3.7]: https://github.com/haraka/test-fixtures/releases/tag/v1.3.7
|
|
322
|
+
[1.3.8]: https://github.com/haraka/test-fixtures/releases/tag/v1.3.8
|
|
323
|
+
[1.3.9]: https://github.com/haraka/test-fixtures/releases/tag/v1.3.9
|
|
324
|
+
[1.3.10]: https://github.com/haraka/test-fixtures/releases/tag/v1.3.10
|
|
325
|
+
[1.4.0]: https://github.com/haraka/test-fixtures/releases/tag/v1.4.0
|
|
326
|
+
[1.4.1]: https://github.com/haraka/test-fixtures/releases/tag/v1.4.1
|
|
327
|
+
[1.4.2]: https://github.com/haraka/test-fixtures/releases/tag/v1.4.2
|
|
328
|
+
[1.4.3]: https://github.com/haraka/test-fixtures/releases/tag/v1.4.3
|
|
329
|
+
[1.5.0]: https://github.com/haraka/test-fixtures/releases/tag/v1.5.0
|
|
330
|
+
[1.5.1]: https://github.com/haraka/test-fixtures/releases/tag/v1.5.1
|
|
331
|
+
[1.6.0]: https://github.com/haraka/test-fixtures/releases/tag/v1.6.0
|
|
332
|
+
[1.6.1]: https://github.com/haraka/test-fixtures/releases/tag/v1.6.1
|
|
333
|
+
[1.6.2]: https://github.com/haraka/test-fixtures/releases/tag/v1.6.2
|
|
334
|
+
[1.7.0]: https://github.com/haraka/test-fixtures/releases/tag/v1.7.0
|
|
335
|
+
[1.7.1]: https://github.com/haraka/test-fixtures/releases/tag/v1.7.1
|
|
336
|
+
[1.7.2]: https://github.com/haraka/test-fixtures/releases/tag/v1.7.2
|
|
337
|
+
[2.0.0]: https://github.com/haraka/test-fixtures/releases/tag/v2.0.0
|
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
|
-
|
|
1
|
+
[![Test][ci-img]][ci-url] [![Cover][cov-img]][cov-url] [![Qlty][qlty-img]][qlty-url]
|
|
2
2
|
|
|
3
|
-
|
|
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
|
package/config/smtp.ini
ADDED
|
@@ -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
|