@haraka/test-fixtures 2.0.0 → 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 CHANGED
@@ -4,6 +4,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
4
4
 
5
5
  ### Unreleased
6
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
+
7
15
  ### [2.0.0] - 2026-12-04
8
16
 
9
17
  - change: renamed to @haraka/test-fixtures
@@ -335,3 +343,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
335
343
  [1.7.1]: https://github.com/haraka/test-fixtures/releases/tag/v1.7.1
336
344
  [1.7.2]: https://github.com/haraka/test-fixtures/releases/tag/v1.7.2
337
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/lib/connection.js CHANGED
@@ -12,6 +12,12 @@ import * as transaction from './transaction.js'
12
12
 
13
13
  const states = constants.connection.state
14
14
 
15
+ // Haraka passes the numeric return codes; their names ('deny', ...) work too
16
+ /** @param {number | string | undefined} retval */
17
+ function to_code(retval) {
18
+ return typeof retval === 'string' ? /** @type {any} */ (constants)[retval.toLowerCase()] : retval
19
+ }
20
+
15
21
  export class Connection {
16
22
  // installed by logger.add_log_methods(); declared for the types
17
23
  /** @type {LogMethod} */ logdata
@@ -242,6 +248,16 @@ export class Connection {
242
248
 
243
249
  auth_results() {}
244
250
 
251
+ /**
252
+ * @param {string} [err]
253
+ * @param {object} [err_data]
254
+ */
255
+ fail(err, err_data) {
256
+ if (err) this.logwarn(err, err_data)
257
+ this.hooks_to_run = []
258
+ this.disconnect()
259
+ }
260
+
245
261
  /**
246
262
  * @param {number} code
247
263
  * @param {string | string[]} msg
@@ -255,7 +271,7 @@ export class Connection {
255
271
 
256
272
  /** @param {() => void} [done] */
257
273
  init_transaction(done) {
258
- this.transaction = new transaction.createTransaction(null, this.cfg)
274
+ this.transaction = transaction.createTransaction(null, this.cfg)
259
275
  this.transaction.results = new ResultStore(this)
260
276
  if (done) done()
261
277
  }
@@ -351,10 +367,11 @@ export class Connection {
351
367
 
352
368
  // Hook Responder Methods
353
369
  /**
354
- * @param {number} [retval]
370
+ * @param {number | string} [retval] a return code, or its name ('deny', …)
355
371
  * @param {string} [msg]
356
372
  */
357
373
  mail_respond(retval, msg) {
374
+ retval = to_code(retval)
358
375
  if (!this.transaction) {
359
376
  this.logerror('mail_respond found no transaction!')
360
377
  return
@@ -379,25 +396,25 @@ export class Connection {
379
396
  }
380
397
 
381
398
  switch (retval) {
382
- case 'deny':
399
+ case constants.deny:
383
400
  this.respond(550, msg || `${dmsg} denied`, () => {
384
401
  store_results('reject')
385
402
  this.reset_transaction()
386
403
  })
387
404
  break
388
- case 'denydisconnect':
405
+ case constants.denydisconnect:
389
406
  this.respond(550, msg || `${dmsg} denied`, () => {
390
407
  store_results('reject')
391
408
  this.disconnect()
392
409
  })
393
410
  break
394
- case 'denysoft':
411
+ case constants.denysoft:
395
412
  this.respond(450, msg || `${dmsg} denied`, () => {
396
413
  store_results('tempfail')
397
414
  this.reset_transaction()
398
415
  })
399
416
  break
400
- case 'denysoftdisconnect':
417
+ case constants.denysoftdisconnect:
401
418
  this.respond(450, msg || `${dmsg} denied`, () => {
402
419
  store_results('tempfail')
403
420
  this.disconnect()
@@ -434,10 +451,11 @@ export class Connection {
434
451
  }
435
452
 
436
453
  /**
437
- * @param {number} [retval]
454
+ * @param {number | string} [retval] a return code, or its name ('deny', …)
438
455
  * @param {string} [msg]
439
456
  */
440
457
  rcpt_ok_respond(retval, msg) {
458
+ retval = to_code(retval)
441
459
  if (!this.transaction) {
442
460
  this.logerror('rcpt_ok_respond found no transaction')
443
461
  return
@@ -447,25 +465,25 @@ export class Connection {
447
465
  const dmsg = `recipient ${rcpt.format()}`
448
466
 
449
467
  switch (retval) {
450
- case 'deny':
468
+ case constants.deny:
451
469
  this.respond(550, msg || `${dmsg} denied`, () => {
452
470
  this.rcpt_incr(rcpt, 'reject', msg, retval)
453
471
  this.transaction.rcpt_to.pop()
454
472
  })
455
473
  break
456
- case 'denydisconnect':
474
+ case constants.denydisconnect:
457
475
  this.respond(550, msg || `${dmsg} denied`, () => {
458
476
  this.rcpt_incr(rcpt, 'reject', msg, retval)
459
477
  this.disconnect()
460
478
  })
461
479
  break
462
- case 'denysoft':
480
+ case constants.denysoft:
463
481
  this.respond(450, msg || `${dmsg} denied`, () => {
464
482
  this.rcpt_incr(rcpt, 'tempfail', msg, retval)
465
483
  this.transaction.rcpt_to.pop()
466
484
  })
467
485
  break
468
- case 'denysoftdisconnect':
486
+ case constants.denysoftdisconnect:
469
487
  this.respond(450, msg || `${dmsg} denied`, () => {
470
488
  this.rcpt_incr(rcpt, 'tempfail', msg, retval)
471
489
  this.disconnect()
@@ -479,10 +497,13 @@ export class Connection {
479
497
  }
480
498
 
481
499
  /**
482
- * @param {number} [retval]
500
+ * @param {number | string} [retval] a return code, or its name ('deny', …)
483
501
  * @param {string} [msg]
484
502
  */
485
503
  rcpt_respond(retval, msg) {
504
+ retval = to_code(retval)
505
+ if (retval === constants.cont && this.relaying) retval = constants.ok
506
+
486
507
  if (!this.transaction) {
487
508
  this.logerror('rcpt_respond found no transaction')
488
509
  return
@@ -492,31 +513,31 @@ export class Connection {
492
513
  const rej_msg = `I cannot deliver mail for ${rcpt.format()}`
493
514
 
494
515
  switch (retval) {
495
- case 'deny':
516
+ case constants.deny:
496
517
  this.respond(550, msg || `${dmsg} denied`, () => {
497
518
  this.rcpt_incr(rcpt, 'reject', msg, retval)
498
519
  this.transaction.rcpt_to.pop()
499
520
  })
500
521
  break
501
- case 'denydisconnect':
522
+ case constants.denydisconnect:
502
523
  this.respond(550, msg || `${dmsg} denied`, () => {
503
524
  this.rcpt_incr(rcpt, 'reject', msg, retval)
504
525
  this.disconnect()
505
526
  })
506
527
  break
507
- case 'denysoft':
528
+ case constants.denysoft:
508
529
  this.respond(450, msg || `${dmsg} denied`, () => {
509
530
  this.rcpt_incr(rcpt, 'tempfail', msg, retval)
510
531
  this.transaction.rcpt_to.pop()
511
532
  })
512
533
  break
513
- case 'denysoftdisconnect':
534
+ case constants.denysoftdisconnect:
514
535
  this.respond(450, msg || `${dmsg} denied`, () => {
515
536
  this.rcpt_incr(rcpt, 'tempfail', msg, retval)
516
537
  this.disconnect()
517
538
  })
518
539
  break
519
- case 'ok':
540
+ case constants.ok:
520
541
  this.last_rcpt_msg = msg
521
542
  break
522
543
  default:
@@ -528,28 +549,29 @@ export class Connection {
528
549
  }
529
550
 
530
551
  /**
531
- * @param {number} [retval]
552
+ * @param {number | string} [retval] a return code, or its name ('deny', …)
532
553
  * @param {string} [msg]
533
554
  */
534
555
  data_respond(retval, msg) {
556
+ retval = to_code(retval)
535
557
  let cont = 0
536
558
  switch (retval) {
537
- case 'deny':
559
+ case constants.deny:
538
560
  this.respond(554, msg || 'Message denied', () => {
539
561
  this.reset_transaction()
540
562
  })
541
563
  break
542
- case 'denydisconnect':
564
+ case constants.denydisconnect:
543
565
  this.respond(554, msg || 'Message denied', () => {
544
566
  this.disconnect()
545
567
  })
546
568
  break
547
- case 'denysoft':
569
+ case constants.denysoft:
548
570
  this.respond(451, msg || 'Message denied', () => {
549
571
  this.reset_transaction()
550
572
  })
551
573
  break
552
- case 'denysoftdisconnect':
574
+ case constants.denysoftdisconnect:
553
575
  this.respond(451, msg || 'Message denied', () => {
554
576
  this.disconnect()
555
577
  })
package/lib/plugin.js CHANGED
@@ -286,13 +286,7 @@ function fileExists(filePath) {
286
286
 
287
287
  // require(esm) loads an ES module plugin synchronously, as a package plugin is
288
288
  function require_code(target) {
289
- if (/^win(32|64)/.test(process.platform)) {
290
- // escape the c:\path\back\slashes else they disappear
291
- target = target.replace(/\\/g, '\\\\')
292
- }
293
- // escape quotes to prevent string-literal breakouts from unusual paths
294
- target = target.replace(/"/g, '\\"')
295
- return `const _p = require("${target}"); for (const k in _p) { exports[k] = _p[k] }`
289
+ return `const _p = require(${JSON.stringify(target)}); for (const k in _p) { exports[k] = _p[k] }`
296
290
  }
297
291
 
298
292
  // import/export can't compile as a script, which is how Node detects ES module syntax too
@@ -310,7 +304,6 @@ function load_and_compile(name) {
310
304
  if (!plugin.plugin_path) {
311
305
  throw `Loading plugin ${plugin.name} failed: No plugin with this name found`
312
306
  }
313
- plugin._compile()
314
307
  return plugin
315
308
  }
316
309
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haraka/test-fixtures",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Haraka Test Fixtures",
5
5
  "author": "Haraka Team <haraka.mail@gmail.com>",
6
6
  "license": "MIT",
@@ -1,5 +1,6 @@
1
1
  import Notes from '@haraka/notes';
2
2
  import ResultStore from '@haraka/results';
3
+ import * as transaction from './transaction.js';
3
4
  export type LogMethod = import('./logger.js').LogMethod;
4
5
  export declare class Connection {
5
6
  client: any;
@@ -45,7 +46,7 @@ export declare class Connection {
45
46
  loop_msg: any;
46
47
  uuid: string;
47
48
  notes: Notes;
48
- transaction: any;
49
+ transaction: transaction.Transaction | null;
49
50
  tran_count: number;
50
51
  capabilities: any;
51
52
  ehlo_hello_message: string;
@@ -94,9 +95,14 @@ export declare class Connection {
94
95
  setTLS(obj: any): void;
95
96
  set(prop_str: any, val: any): void;
96
97
  get(prop_str: any): any;
97
- set relaying(val: any);
98
- get relaying(): any;
98
+ set relaying(val: unknown);
99
+ get relaying(): unknown;
99
100
  auth_results(): void;
101
+ /**
102
+ * @param {string} [err]
103
+ * @param {object} [err_data]
104
+ */
105
+ fail(err?: string, err_data?: object): void;
100
106
  /**
101
107
  * @param {number} code
102
108
  * @param {string | string[]} msg
@@ -115,10 +121,10 @@ export declare class Connection {
115
121
  disconnect(): void;
116
122
  get_capabilities(): string[];
117
123
  /**
118
- * @param {number} [retval]
124
+ * @param {number | string} [retval] a return code, or its name ('deny', …)
119
125
  * @param {string} [msg]
120
126
  */
121
- mail_respond(retval?: number, msg?: string): void;
127
+ mail_respond(retval?: number | string, msg?: string): void;
122
128
  /**
123
129
  * @param {any} rcpt
124
130
  * @param {string} action
@@ -126,19 +132,19 @@ export declare class Connection {
126
132
  */
127
133
  rcpt_incr(rcpt: any, action: string, msg?: string): void;
128
134
  /**
129
- * @param {number} [retval]
135
+ * @param {number | string} [retval] a return code, or its name ('deny', …)
130
136
  * @param {string} [msg]
131
137
  */
132
- rcpt_ok_respond(retval?: number, msg?: string): void;
138
+ rcpt_ok_respond(retval?: number | string, msg?: string): void;
133
139
  /**
134
- * @param {number} [retval]
140
+ * @param {number | string} [retval] a return code, or its name ('deny', …)
135
141
  * @param {string} [msg]
136
142
  */
137
- rcpt_respond(retval?: number, msg?: string): void;
143
+ rcpt_respond(retval?: number | string, msg?: string): void;
138
144
  /**
139
- * @param {number} [retval]
145
+ * @param {number | string} [retval] a return code, or its name ('deny', …)
140
146
  * @param {string} [msg]
141
147
  */
142
- data_respond(retval?: number, msg?: string): void;
148
+ data_respond(retval?: number | string, msg?: string): void;
143
149
  }
144
150
  export declare function createConnection(client?: {}, server?: {}, cfg?: {}): Connection;