Haraka 3.1.0 → 3.1.2

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 (160) hide show
  1. package/.prettierignore +4 -0
  2. package/CONTRIBUTORS.md +5 -5
  3. package/Changes.md +69 -50
  4. package/Plugins.md +3 -1
  5. package/README.md +1 -1
  6. package/bin/haraka +475 -478
  7. package/config/outbound.ini +3 -0
  8. package/connection.js +1072 -1108
  9. package/docs/Connection.md +29 -30
  10. package/docs/CoreConfig.md +38 -39
  11. package/docs/CustomReturnCodes.md +0 -1
  12. package/docs/HAProxy.md +2 -2
  13. package/docs/Header.md +1 -1
  14. package/docs/Logging.md +29 -5
  15. package/docs/Outbound.md +93 -78
  16. package/docs/Plugins.md +103 -108
  17. package/docs/Transaction.md +49 -51
  18. package/docs/Tutorial.md +127 -143
  19. package/docs/deprecated/access.md +0 -1
  20. package/docs/deprecated/backscatterer.md +2 -3
  21. package/docs/deprecated/connect.rdns_access.md +18 -27
  22. package/docs/deprecated/data.headers.md +0 -1
  23. package/docs/deprecated/data.nomsgid.md +1 -2
  24. package/docs/deprecated/data.noreceived.md +1 -2
  25. package/docs/deprecated/data.rfc5322_header_checks.md +1 -2
  26. package/docs/deprecated/dkim_sign.md +13 -17
  27. package/docs/deprecated/dkim_verify.md +9 -17
  28. package/docs/deprecated/dnsbl.md +36 -38
  29. package/docs/deprecated/dnswl.md +41 -43
  30. package/docs/deprecated/lookup_rdns.strict.md +21 -34
  31. package/docs/deprecated/mail_from.access.md +17 -25
  32. package/docs/deprecated/mail_from.blocklist.md +9 -12
  33. package/docs/deprecated/mail_from.nobounces.md +1 -2
  34. package/docs/deprecated/rcpt_to.access.md +20 -27
  35. package/docs/deprecated/rcpt_to.blocklist.md +10 -13
  36. package/docs/deprecated/rcpt_to.routes.md +0 -1
  37. package/docs/deprecated/rdns.regexp.md +13 -15
  38. package/docs/plugins/aliases.md +89 -89
  39. package/docs/plugins/auth/auth_bridge.md +5 -7
  40. package/docs/plugins/auth/auth_ldap.md +11 -14
  41. package/docs/plugins/auth/auth_proxy.md +10 -12
  42. package/docs/plugins/auth/auth_vpopmaild.md +5 -6
  43. package/docs/plugins/auth/flat_file.md +4 -4
  44. package/docs/plugins/block_me.md +3 -3
  45. package/docs/plugins/data.signatures.md +1 -2
  46. package/docs/plugins/delay_deny.md +3 -4
  47. package/docs/plugins/max_unrecognized_commands.md +4 -4
  48. package/docs/plugins/prevent_credential_leaks.md +6 -6
  49. package/docs/plugins/process_title.md +18 -18
  50. package/docs/plugins/queue/deliver.md +2 -3
  51. package/docs/plugins/queue/discard.md +4 -4
  52. package/docs/plugins/queue/lmtp.md +1 -3
  53. package/docs/plugins/queue/qmail-queue.md +7 -9
  54. package/docs/plugins/queue/quarantine.md +16 -21
  55. package/docs/plugins/queue/rabbitmq.md +8 -11
  56. package/docs/plugins/queue/rabbitmq_amqplib.md +43 -39
  57. package/docs/plugins/queue/smtp_bridge.md +7 -10
  58. package/docs/plugins/queue/smtp_forward.md +42 -34
  59. package/docs/plugins/queue/smtp_proxy.md +30 -29
  60. package/docs/plugins/queue/test.md +1 -3
  61. package/docs/plugins/rcpt_to.in_host_list.md +6 -6
  62. package/docs/plugins/rcpt_to.max_count.md +1 -1
  63. package/docs/plugins/record_envelope_addresses.md +3 -3
  64. package/docs/plugins/reseed_rng.md +6 -6
  65. package/docs/plugins/status.md +9 -8
  66. package/docs/plugins/tarpit.md +7 -11
  67. package/docs/plugins/tls.md +12 -17
  68. package/docs/plugins/toobusy.md +4 -4
  69. package/docs/plugins/xclient.md +3 -3
  70. package/docs/tutorials/Migrating_from_v1_to_v2.md +19 -41
  71. package/docs/tutorials/SettingUpOutbound.md +6 -9
  72. package/endpoint.js +35 -38
  73. package/eslint.config.mjs +22 -19
  74. package/haraka.js +42 -47
  75. package/host_pool.js +75 -79
  76. package/http/html/404.html +45 -49
  77. package/http/html/index.html +39 -28
  78. package/http/package.json +2 -4
  79. package/line_socket.js +27 -28
  80. package/logger.js +182 -201
  81. package/outbound/client_pool.js +34 -27
  82. package/outbound/config.js +64 -59
  83. package/outbound/fsync_writestream.js +24 -25
  84. package/outbound/hmail.js +888 -835
  85. package/outbound/index.js +194 -187
  86. package/outbound/qfile.js +49 -52
  87. package/outbound/queue.js +197 -190
  88. package/outbound/timer_queue.js +41 -43
  89. package/outbound/tls.js +68 -61
  90. package/outbound/todo.js +11 -11
  91. package/package.json +38 -33
  92. package/plugins/.eslintrc.yaml +0 -1
  93. package/plugins/auth/auth_base.js +123 -127
  94. package/plugins/auth/auth_bridge.js +7 -7
  95. package/plugins/auth/auth_proxy.js +121 -126
  96. package/plugins/auth/auth_vpopmaild.js +84 -85
  97. package/plugins/auth/flat_file.js +18 -17
  98. package/plugins/block_me.js +31 -31
  99. package/plugins/data.signatures.js +13 -13
  100. package/plugins/delay_deny.js +65 -61
  101. package/plugins/prevent_credential_leaks.js +23 -23
  102. package/plugins/process_title.js +125 -128
  103. package/plugins/profile.js +5 -5
  104. package/plugins/queue/deliver.js +3 -3
  105. package/plugins/queue/discard.js +13 -14
  106. package/plugins/queue/lmtp.js +16 -17
  107. package/plugins/queue/qmail-queue.js +54 -55
  108. package/plugins/queue/quarantine.js +68 -70
  109. package/plugins/queue/rabbitmq.js +80 -87
  110. package/plugins/queue/rabbitmq_amqplib.js +75 -54
  111. package/plugins/queue/smtp_bridge.js +16 -16
  112. package/plugins/queue/smtp_forward.js +175 -179
  113. package/plugins/queue/smtp_proxy.js +69 -71
  114. package/plugins/queue/test.js +9 -9
  115. package/plugins/rcpt_to.host_list_base.js +30 -34
  116. package/plugins/rcpt_to.in_host_list.js +19 -19
  117. package/plugins/record_envelope_addresses.js +4 -4
  118. package/plugins/reseed_rng.js +4 -4
  119. package/plugins/status.js +90 -97
  120. package/plugins/tarpit.js +25 -14
  121. package/plugins/tls.js +68 -68
  122. package/plugins/toobusy.js +21 -23
  123. package/plugins/xclient.js +51 -53
  124. package/plugins.js +276 -293
  125. package/rfc1869.js +30 -35
  126. package/server.js +308 -299
  127. package/smtp_client.js +244 -228
  128. package/test/.eslintrc.yaml +0 -1
  129. package/test/connection.js +127 -134
  130. package/test/endpoint.js +53 -47
  131. package/test/fixtures/line_socket.js +12 -12
  132. package/test/fixtures/util_hmailitem.js +89 -85
  133. package/test/host_pool.js +90 -92
  134. package/test/installation/plugins/base_plugin.js +2 -2
  135. package/test/installation/plugins/folder_plugin/index.js +2 -3
  136. package/test/installation/plugins/inherits.js +3 -3
  137. package/test/installation/plugins/load_first.js +2 -3
  138. package/test/installation/plugins/plugin.js +1 -3
  139. package/test/installation/plugins/tls.js +2 -4
  140. package/test/logger.js +135 -116
  141. package/test/outbound/hmail.js +49 -35
  142. package/test/outbound/index.js +118 -101
  143. package/test/outbound/qfile.js +51 -53
  144. package/test/outbound_bounce_net_errors.js +84 -69
  145. package/test/outbound_bounce_rfc3464.js +235 -165
  146. package/test/plugins/auth/auth_base.js +420 -279
  147. package/test/plugins/auth/auth_vpopmaild.js +38 -39
  148. package/test/plugins/queue/smtp_forward.js +126 -104
  149. package/test/plugins/rcpt_to.host_list_base.js +85 -67
  150. package/test/plugins/rcpt_to.in_host_list.js +159 -112
  151. package/test/plugins/status.js +71 -64
  152. package/test/plugins/tls.js +37 -34
  153. package/test/plugins.js +97 -92
  154. package/test/rfc1869.js +19 -26
  155. package/test/server.js +293 -272
  156. package/test/smtp_client.js +180 -176
  157. package/test/tls_socket.js +62 -66
  158. package/test/transaction.js +159 -160
  159. package/tls_socket.js +331 -333
  160. package/transaction.js +129 -137
@@ -1,11 +1,11 @@
1
- 'use strict';
1
+ 'use strict'
2
2
 
3
3
  const assert = require('node:assert')
4
- const fs = require('fs');
5
- const path = require('path');
4
+ const fs = require('fs')
5
+ const path = require('path')
6
6
 
7
- const constants = require('haraka-constants');
8
- const logger = require('../../logger');
7
+ const constants = require('haraka-constants')
8
+ const logger = require('../../logger')
9
9
 
10
10
  const lines = [
11
11
  'From: John Johnson <john@example.com>',
@@ -14,95 +14,101 @@ const lines = [
14
14
  '',
15
15
  "I'm hungry.",
16
16
  '',
17
- ];
17
+ ]
18
18
 
19
19
  describe('outbound', () => {
20
-
21
- it('converts \\n and \\r\\n line endings to \\r\\n' , () => {
22
-
20
+ it('converts \\n and \\r\\n line endings to \\r\\n', () => {
23
21
  for (const ending of ['\n', '\r\n']) {
24
- let contents = lines.join(ending);
25
- let result = '';
22
+ let contents = lines.join(ending)
23
+ let result = ''
26
24
 
27
25
  // Set data_lines to lines in contents
28
- let match;
29
- const re = /^([^\n]*\n?)/;
26
+ let match
27
+ const re = /^([^\n]*\n?)/
30
28
  while ((match = re.exec(contents))) {
31
- let line = match[1];
32
- line = line.replace(/\r?\n?$/, '\r\n'); // assure \r\n ending
33
- result += line;
34
- contents = contents.substr(match[1].length);
29
+ let line = match[1]
30
+ line = line.replace(/\r?\n?$/, '\r\n') // assure \r\n ending
31
+ result += line
32
+ contents = contents.substr(match[1].length)
35
33
  if (contents.length === 0) {
36
- break;
34
+ break
37
35
  }
38
36
  }
39
37
 
40
- assert.deepEqual(lines.join('\r\n'), result);
38
+ assert.deepEqual(lines.join('\r\n'), result)
41
39
  }
42
40
  })
43
41
 
44
42
  it('log_methods added', () => {
45
- const levels = ['DATA','PROTOCOL','DEBUG','INFO','NOTICE','WARN','ERROR','CRIT','ALERT','EMERG']
43
+ const levels = ['DATA', 'PROTOCOL', 'DEBUG', 'INFO', 'NOTICE', 'WARN', 'ERROR', 'CRIT', 'ALERT', 'EMERG']
46
44
 
47
- const HMailItem = require('../../outbound/hmail');
45
+ const HMailItem = require('../../outbound/hmail')
48
46
 
49
47
  for (const level of levels) {
50
- assert.ok(HMailItem.prototype[`log${level.toLowerCase()}`], `Log method for level: ${level}`);
48
+ assert.ok(HMailItem.prototype[`log${level.toLowerCase()}`], `Log method for level: ${level}`)
51
49
  }
52
50
  })
53
51
 
54
52
  it('set_temp_fail_intervals coverage', () => {
55
-
56
- const config = require('../../outbound/config');
53
+ const config = require('../../outbound/config')
57
54
  // Test default configuration
58
- assert.deepEqual(config.cfg.temp_fail_intervals, [64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072]);
55
+ assert.deepEqual(
56
+ config.cfg.temp_fail_intervals,
57
+ [64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072],
58
+ )
59
59
  // Test a simple configuration
60
- config.cfg.temp_fail_intervals = '10s, 1m*2';
61
- config.set_temp_fail_intervals();
62
- assert.deepEqual(config.cfg.temp_fail_intervals, [10, 60, 60]);
60
+ config.cfg.temp_fail_intervals = '10s, 1m*2'
61
+ config.set_temp_fail_intervals()
62
+ assert.deepEqual(config.cfg.temp_fail_intervals, [10, 60, 60])
63
63
  // Test a complex configuration
64
- config.cfg.temp_fail_intervals = '30s, 1m, 5m, 9m, 15m*3, 30m*2, 1h*3, 2h*3, 1d';
65
- config.set_temp_fail_intervals();
66
- assert.deepEqual(config.cfg.temp_fail_intervals, [30,60,300,540,900,900,900,1800,1800,3600,3600,3600,7200,7200,7200,86400]);
64
+ config.cfg.temp_fail_intervals = '30s, 1m, 5m, 9m, 15m*3, 30m*2, 1h*3, 2h*3, 1d'
65
+ config.set_temp_fail_intervals()
66
+ assert.deepEqual(
67
+ config.cfg.temp_fail_intervals,
68
+ [30, 60, 300, 540, 900, 900, 900, 1800, 1800, 3600, 3600, 3600, 7200, 7200, 7200, 86400],
69
+ )
67
70
  // Test the "none" configuration
68
- config.cfg.temp_fail_intervals = 'none';
69
- config.set_temp_fail_intervals();
70
- assert.deepEqual(config.cfg.temp_fail_intervals, []);
71
+ config.cfg.temp_fail_intervals = 'none'
72
+ config.set_temp_fail_intervals()
73
+ assert.deepEqual(config.cfg.temp_fail_intervals, [])
71
74
  // Test bad config (should revert to default)
72
- config.cfg.temp_fail_intervals = '60 min';
73
- config.set_temp_fail_intervals();
74
- assert.deepEqual(config.cfg.temp_fail_intervals, [64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072]);
75
+ config.cfg.temp_fail_intervals = '60 min'
76
+ config.set_temp_fail_intervals()
77
+ assert.deepEqual(
78
+ config.cfg.temp_fail_intervals,
79
+ [64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072],
80
+ )
75
81
  })
76
82
 
77
83
  describe('get_tls_options', () => {
78
84
  beforeEach((done) => {
79
- process.env.HARAKA_TEST_DIR=path.resolve('test');
80
- this.outbound = require('../../outbound');
81
- this.obtls = require('../../outbound/tls');
82
- const tls_socket = require('../../tls_socket');
85
+ process.env.HARAKA_TEST_DIR = path.resolve('test')
86
+ this.outbound = require('../../outbound')
87
+ this.obtls = require('../../outbound/tls')
88
+ const tls_socket = require('../../tls_socket')
83
89
 
84
90
  // reset config to load from tests directory
85
- const testDir = path.resolve('test');
86
- this.outbound.config = this.outbound.config.module_config(testDir);
87
- this.obtls.test_config(tls_socket.config.module_config(testDir), this.outbound.config);
91
+ const testDir = path.resolve('test')
92
+ this.outbound.config = this.outbound.config.module_config(testDir)
93
+ this.obtls.test_config(tls_socket.config.module_config(testDir), this.outbound.config)
88
94
  this.obtls.init(done)
89
95
  })
90
96
 
91
97
  afterEach((done) => {
92
- delete process.env.HARAKA_TEST_DIR;
93
- done();
98
+ delete process.env.HARAKA_TEST_DIR
99
+ done()
94
100
  })
95
101
 
96
102
  it('gets TLS properties from tls.ini.outbound', () => {
97
- const tls_config = this.obtls.get_tls_options(
98
- { exchange: 'mail.example.com'}
99
- );
103
+ const tls_config = this.obtls.get_tls_options({
104
+ exchange: 'mail.example.com',
105
+ })
100
106
 
101
107
  assert.deepEqual(tls_config, {
102
108
  servername: 'mail.example.com',
103
- key: fs.readFileSync(path.resolve('test','config','outbound_tls_key.pem')),
104
- cert: fs.readFileSync(path.resolve('test','config','outbound_tls_cert.pem')),
105
- dhparam: fs.readFileSync(path.resolve('test','config','dhparams.pem')),
109
+ key: fs.readFileSync(path.resolve('test', 'config', 'outbound_tls_key.pem')),
110
+ cert: fs.readFileSync(path.resolve('test', 'config', 'outbound_tls_cert.pem')),
111
+ dhparam: fs.readFileSync(path.resolve('test', 'config', 'dhparams.pem')),
106
112
  ciphers: 'ECDHE-RSA-AES256-GCM-SHA384',
107
113
  minVersion: 'TLSv1',
108
114
  rejectUnauthorized: false,
@@ -110,111 +116,122 @@ describe('outbound', () => {
110
116
  honorCipherOrder: false,
111
117
  redis: { disable_for_failed_hosts: false },
112
118
  no_tls_hosts: ['127.0.0.2', '192.168.31.1/24'],
113
- force_tls_hosts: ['first.example.com', 'second.example.net']
119
+ force_tls_hosts: ['first.example.com', 'second.example.net'],
114
120
  })
115
121
  })
116
122
  })
117
123
 
118
124
  describe('build_todo', () => {
119
125
  beforeEach((done) => {
120
- this.outbound = require('../../outbound');
126
+ this.outbound = require('../../outbound')
121
127
  try {
122
- fs.unlinkSync('test/queue/multibyte');
123
- fs.unlinkSync('test/queue/plain');
124
- }
125
- catch (ignore) {}
126
- done();
128
+ fs.unlinkSync('test/queue/multibyte')
129
+ fs.unlinkSync('test/queue/plain')
130
+ } catch (ignore) {}
131
+ done()
127
132
  })
128
133
 
129
134
  it('saves a file', () => {
130
- const todo = JSON.parse('{"queue_time":1507509981169,"domain":"redacteed.com","rcpt_to":[{"original":"<postmaster@redacteed.com>","original_host":"redacteed.com","host":"redacteed.com","user":"postmaster"}],"mail_from":{"original":"<matt@tnpi.net>","original_host":"tnpi.net","host":"tnpi.net","user":"matt"},"notes":{"authentication_results":["spf=pass smtp.mailfrom=tnpi.net"],"spf_mail_result":"Pass","spf_mail_record":"v=spf1 a mx include:mx.theartfarm.com ?include:forwards._spf.tnpi.net include:lists._spf.tnpi.net -all","attachment_count":0,"attachments":[{"ctype":"application/pdf","filename":"FileWithoutAccent Chars.pdf","extension":".pdf","md5":"6c1d5f5c047cff3f6320b1210970bdf6"}],"attachment_ctypes":["application/pdf","multipart/mixed","text/plain","application/pdf"],"attachment_files":["FileWithoutaccent Chars.pdf"],"attachment_archive_files":[]},"uuid":"1D5483B0-3E00-4280-A961-3AFD2017B4FC.1"}');
131
- const fd = fs.openSync('test/queue/plain', 'w');
132
- const ws = new fs.createWriteStream('test/queue/plain', { fd, flags: constants.WRITE_EXCL });
135
+ const todo = JSON.parse(
136
+ '{"queue_time":1507509981169,"domain":"redacteed.com","rcpt_to":[{"original":"<postmaster@redacteed.com>","original_host":"redacteed.com","host":"redacteed.com","user":"postmaster"}],"mail_from":{"original":"<matt@tnpi.net>","original_host":"tnpi.net","host":"tnpi.net","user":"matt"},"notes":{"authentication_results":["spf=pass smtp.mailfrom=tnpi.net"],"spf_mail_result":"Pass","spf_mail_record":"v=spf1 a mx include:mx.theartfarm.com ?include:forwards._spf.tnpi.net include:lists._spf.tnpi.net -all","attachment_count":0,"attachments":[{"ctype":"application/pdf","filename":"FileWithoutAccent Chars.pdf","extension":".pdf","md5":"6c1d5f5c047cff3f6320b1210970bdf6"}],"attachment_ctypes":["application/pdf","multipart/mixed","text/plain","application/pdf"],"attachment_files":["FileWithoutaccent Chars.pdf"],"attachment_archive_files":[]},"uuid":"1D5483B0-3E00-4280-A961-3AFD2017B4FC.1"}',
137
+ )
138
+ const fd = fs.openSync('test/queue/plain', 'w')
139
+ const ws = new fs.createWriteStream('test/queue/plain', {
140
+ fd,
141
+ flags: constants.WRITE_EXCL,
142
+ })
133
143
  ws.on('close', () => {
134
144
  // console.log(arguments);
135
- assert.ok(1);
145
+ assert.ok(1)
136
146
  })
137
147
  ws.on('error', (e) => {
138
- console.error(e);
148
+ console.error(e)
139
149
  })
140
150
  this.outbound.build_todo(todo, ws, () => {
141
- ws.write(Buffer.from('This is the message body'));
142
- fs.fsync(fd, () => { ws.close(); })
151
+ ws.write(Buffer.from('This is the message body'))
152
+ fs.fsync(fd, () => {
153
+ ws.close()
154
+ })
143
155
  })
144
156
  })
145
157
 
146
158
  it('saves a file with multibyte chars', () => {
147
- const todo = JSON.parse('{"queue_time":1507509981169,"domain":"redacteed.com","rcpt_to":[{"original":"<postmaster@redacteed.com>","original_host":"redacteed.com","host":"redacteed.com","user":"postmaster"}],"mail_from":{"original":"<matt@tnpi.net>","original_host":"tnpi.net","host":"tnpi.net","user":"matt"},"notes":{"authentication_results":["spf=pass smtp.mailfrom=tnpi.net"],"spf_mail_result":"Pass","spf_mail_record":"v=spf1 a mx include:mx.theartfarm.com ?include:forwards._spf.tnpi.net include:lists._spf.tnpi.net -all","attachment_count":0,"attachments":[{"ctype":"application/pdf","filename":"FileWîthÁccent Chars.pdf","extension":".pdf","md5":"6c1d5f5c047cff3f6320b1210970bdf6"}],"attachment_ctypes":["application/pdf","multipart/mixed","text/plain","application/pdf"],"attachment_files":["FileWîthÁccent Chars.pdf"],"attachment_archive_files":[]},"uuid":"1D5483B0-3E00-4280-A961-3AFD2017B4FC.1"}');
148
- const fd = fs.openSync('test/queue/multibyte', 'w');
149
- const ws = new fs.WriteStream('test/queue/multibyte', { fd, flags: constants.WRITE_EXCL });
159
+ const todo = JSON.parse(
160
+ '{"queue_time":1507509981169,"domain":"redacteed.com","rcpt_to":[{"original":"<postmaster@redacteed.com>","original_host":"redacteed.com","host":"redacteed.com","user":"postmaster"}],"mail_from":{"original":"<matt@tnpi.net>","original_host":"tnpi.net","host":"tnpi.net","user":"matt"},"notes":{"authentication_results":["spf=pass smtp.mailfrom=tnpi.net"],"spf_mail_result":"Pass","spf_mail_record":"v=spf1 a mx include:mx.theartfarm.com ?include:forwards._spf.tnpi.net include:lists._spf.tnpi.net -all","attachment_count":0,"attachments":[{"ctype":"application/pdf","filename":"FileWîthÁccent Chars.pdf","extension":".pdf","md5":"6c1d5f5c047cff3f6320b1210970bdf6"}],"attachment_ctypes":["application/pdf","multipart/mixed","text/plain","application/pdf"],"attachment_files":["FileWîthÁccent Chars.pdf"],"attachment_archive_files":[]},"uuid":"1D5483B0-3E00-4280-A961-3AFD2017B4FC.1"}',
161
+ )
162
+ const fd = fs.openSync('test/queue/multibyte', 'w')
163
+ const ws = new fs.WriteStream('test/queue/multibyte', {
164
+ fd,
165
+ flags: constants.WRITE_EXCL,
166
+ })
150
167
  ws.on('close', () => {
151
- assert.ok(1);
168
+ assert.ok(1)
152
169
  })
153
170
  ws.on('error', (e) => {
154
- console.error(e);
171
+ console.error(e)
155
172
  })
156
173
  this.outbound.build_todo(todo, ws, () => {
157
- ws.write(Buffer.from('This is the message body'));
158
- fs.fsync(fd, () => { ws.close(); })
174
+ ws.write(Buffer.from('This is the message body'))
175
+ fs.fsync(fd, () => {
176
+ ws.close()
177
+ })
159
178
  })
160
179
  })
161
180
  })
162
181
 
163
182
  describe('timer_queue', () => {
164
183
  beforeEach((done) => {
165
- process.env.HARAKA_TEST_DIR=path.resolve('test');
166
- this.outbound = require('../../outbound');
167
- const TimerQueue = require('../../outbound/timer_queue');
168
- this.ob_timer_queue = new TimerQueue(500);
169
- done();
184
+ process.env.HARAKA_TEST_DIR = path.resolve('test')
185
+ this.outbound = require('../../outbound')
186
+ const TimerQueue = require('../../outbound/timer_queue')
187
+ this.ob_timer_queue = new TimerQueue(500)
188
+ done()
170
189
  })
171
190
 
172
191
  afterEach((done) => {
173
- delete process.env.HARAKA_TEST_DIR;
174
- this.ob_timer_queue.shutdown();
192
+ delete process.env.HARAKA_TEST_DIR
193
+ this.ob_timer_queue.shutdown()
175
194
  done()
176
195
  })
177
196
 
178
197
  it('has initial length of 0', () => {
179
- assert.equal(this.ob_timer_queue.length(), 0);
198
+ assert.equal(this.ob_timer_queue.length(), 0)
180
199
  })
181
200
 
182
201
  it('can add items', () => {
183
- this.ob_timer_queue.add("1", 1000);
184
- this.ob_timer_queue.add("2", 2000);
202
+ this.ob_timer_queue.add('1', 1000)
203
+ this.ob_timer_queue.add('2', 2000)
185
204
 
186
- assert.equal(this.ob_timer_queue.length(), 2);
205
+ assert.equal(this.ob_timer_queue.length(), 2)
187
206
  })
188
207
 
189
208
  it('can drain items', () => {
209
+ this.ob_timer_queue.add('1', 1000)
210
+ this.ob_timer_queue.add('2', 2000)
190
211
 
191
- this.ob_timer_queue.add("1", 1000);
192
- this.ob_timer_queue.add("2", 2000);
193
-
194
- let tq_length = this.ob_timer_queue.length();
212
+ let tq_length = this.ob_timer_queue.length()
195
213
 
196
- assert.equal(tq_length, 2);
214
+ assert.equal(tq_length, 2)
197
215
 
198
- this.ob_timer_queue.drain();
199
- tq_length = this.ob_timer_queue.length();
216
+ this.ob_timer_queue.drain()
217
+ tq_length = this.ob_timer_queue.length()
200
218
 
201
- assert.equal(tq_length, 0);
219
+ assert.equal(tq_length, 0)
202
220
  })
203
221
 
204
222
  it('can discard items by id', () => {
223
+ this.ob_timer_queue.add('1', 1000)
224
+ this.ob_timer_queue.add('2', 2000)
205
225
 
206
- this.ob_timer_queue.add("1", 1000);
207
- this.ob_timer_queue.add("2", 2000);
208
-
209
- let tq_length = this.ob_timer_queue.length();
226
+ let tq_length = this.ob_timer_queue.length()
210
227
 
211
- assert.equal(tq_length, 2);
228
+ assert.equal(tq_length, 2)
212
229
 
213
- this.ob_timer_queue.discard("2");
214
- tq_length = this.ob_timer_queue.length();
230
+ this.ob_timer_queue.discard('2')
231
+ tq_length = this.ob_timer_queue.length()
215
232
 
216
- assert.equal(tq_length, 1);
217
- assert.equal(this.ob_timer_queue.queue[0].id, "1");
233
+ assert.equal(tq_length, 1)
234
+ assert.equal(this.ob_timer_queue.queue[0].id, '1')
218
235
  })
219
236
  })
220
237
  })
@@ -1,80 +1,78 @@
1
1
  const assert = require('node:assert')
2
- const os = require('node:os');
2
+ const os = require('node:os')
3
3
 
4
4
  describe('qfile', () => {
5
-
6
5
  describe('qfile', () => {
7
6
  beforeEach((done) => {
8
7
  this.qfile = require('../../outbound/qfile')
9
- done();
8
+ done()
10
9
  })
11
10
 
12
11
  it('name() basic functions', () => {
13
- const name = this.qfile.name();
14
- const split = name.split('_');
15
- assert.equal(split.length, 7);
16
- assert.equal(split[2], 0);
17
- assert.equal(split[3], process.pid);
12
+ const name = this.qfile.name()
13
+ const split = name.split('_')
14
+ assert.equal(split.length, 7)
15
+ assert.equal(split[2], 0)
16
+ assert.equal(split[3], process.pid)
18
17
  })
19
18
 
20
19
  it('name() with overrides', () => {
21
20
  const overrides = {
22
- arrival : 12345,
23
- next_attempt : 12345,
24
- attempts : 15,
25
- pid : process.pid,
26
- uid : 'XXYYZZ',
27
- host : os.hostname(),
28
- };
29
- const name = this.qfile.name(overrides);
30
- const split = name.split('_');
31
- assert.equal(split.length, 7);
32
- assert.equal(split[0], overrides.arrival);
33
- assert.equal(split[1], overrides.next_attempt);
34
- assert.equal(split[2], overrides.attempts);
35
- assert.equal(split[3], overrides.pid);
36
- assert.equal(split[4], overrides.uid);
37
- assert.equal(split[6], overrides.host);
21
+ arrival: 12345,
22
+ next_attempt: 12345,
23
+ attempts: 15,
24
+ pid: process.pid,
25
+ uid: 'XXYYZZ',
26
+ host: os.hostname(),
27
+ }
28
+ const name = this.qfile.name(overrides)
29
+ const split = name.split('_')
30
+ assert.equal(split.length, 7)
31
+ assert.equal(split[0], overrides.arrival)
32
+ assert.equal(split[1], overrides.next_attempt)
33
+ assert.equal(split[2], overrides.attempts)
34
+ assert.equal(split[3], overrides.pid)
35
+ assert.equal(split[4], overrides.uid)
36
+ assert.equal(split[6], overrides.host)
38
37
  })
39
38
 
40
39
  it('rnd_unique() is unique-ish', () => {
41
- const repeats = 1000;
42
- const u = this.qfile.rnd_unique();
43
- for (let i = 0; i < repeats; i++){
44
- assert.notEqual(u, this.qfile.rnd_unique());
40
+ const repeats = 1000
41
+ const u = this.qfile.rnd_unique()
42
+ for (let i = 0; i < repeats; i++) {
43
+ assert.notEqual(u, this.qfile.rnd_unique())
45
44
  }
46
45
  })
47
46
  })
48
47
 
49
48
  describe('parts', () => {
50
-
51
49
  it('parts() updates previous queue filenames', () => {
52
50
  // $nextattempt_$attempts_$pid_$uniq.$host
53
- const name = "1111_0_2222_3333.foo.example.com"
54
- const parts = this.qfile.parts(name);
55
- assert.equal(parts.next_attempt, 1111);
56
- assert.equal(parts.attempts, 0);
57
- assert.equal(parts.pid, 2222);
58
- assert.equal(parts.host, 'foo.example.com');
51
+ const name = '1111_0_2222_3333.foo.example.com'
52
+ const parts = this.qfile.parts(name)
53
+ assert.equal(parts.next_attempt, 1111)
54
+ assert.equal(parts.attempts, 0)
55
+ assert.equal(parts.pid, 2222)
56
+ assert.equal(parts.host, 'foo.example.com')
59
57
  })
60
58
 
61
59
  it('parts() handles standard queue filenames', () => {
62
60
  const overrides = {
63
- arrival : 12345,
64
- next_attempt : 12345,
65
- attempts : 15,
66
- pid : process.pid,
67
- uid : 'XXYYZZ',
68
- host : os.hostname(),
69
- };
70
- const name = this.qfile.name(overrides);
71
- const parts = this.qfile.parts(name);
72
- assert.equal(parts.arrival, overrides.arrival);
73
- assert.equal(parts.next_attempt, overrides.next_attempt);
74
- assert.equal(parts.attempts, overrides.attempts);
75
- assert.equal(parts.pid, overrides.pid);
76
- assert.equal(parts.uid, overrides.uid);
77
- assert.equal(parts.host, overrides.host);
61
+ arrival: 12345,
62
+ next_attempt: 12345,
63
+ attempts: 15,
64
+ pid: process.pid,
65
+ uid: 'XXYYZZ',
66
+ host: os.hostname(),
67
+ }
68
+ const name = this.qfile.name(overrides)
69
+ const parts = this.qfile.parts(name)
70
+ assert.equal(parts.arrival, overrides.arrival)
71
+ assert.equal(parts.next_attempt, overrides.next_attempt)
72
+ assert.equal(parts.attempts, overrides.attempts)
73
+ assert.equal(parts.pid, overrides.pid)
74
+ assert.equal(parts.uid, overrides.uid)
75
+ assert.equal(parts.host, overrides.host)
78
76
  })
79
77
 
80
78
  it('handles 4', () => {
@@ -87,13 +85,13 @@ describe('qfile', () => {
87
85
  attempts: 0,
88
86
  pid: 12345,
89
87
  host: 'mta1.example.com',
90
- age: 0
88
+ age: 0,
91
89
  })
92
90
  })
93
91
 
94
92
  it('handles 7', () => {
95
93
  const r = this.qfile.parts('1516650518128_1516667073032_8_29538_TkPZWz_1_haraka')
96
- delete r.age;
94
+ delete r.age
97
95
  assert.deepEqual(r, {
98
96
  arrival: 1516650518128,
99
97
  next_attempt: 1516667073032,
@@ -123,4 +121,4 @@ describe('qfile', () => {
123
121
  assert.deepEqual(this.qfile.hostname('mt_a1.exam_ple.com'), 'mt\\137a1.exam\\137ple.com')
124
122
  })
125
123
  })
126
- })
124
+ })