haraka-plugin-karma 1.0.12 → 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/test/karma.js CHANGED
@@ -1,777 +1,809 @@
1
- 'use strict';
2
-
3
- const Address = require('address-rfc2821').Address;
4
- const fixtures = require('haraka-test-fixtures');
5
- const constants = require('haraka-constants');
6
-
7
- const stub = fixtures.stub.stub;
8
-
9
- const _set_up = function (done) {
10
-
11
- this.plugin = new fixtures.plugin('karma');
12
-
13
- this.plugin.cfg = { main: {} };
14
- this.plugin.deny_hooks = {'connect': true};
15
- this.plugin.tarpit_hooks = ['connect'];
16
-
17
- this.connection = fixtures.connection.createConnection({}, { notes: {} });
18
-
19
- this.connection.transaction = fixtures.transaction.createTransaction();
20
- this.connection.transaction.results = new fixtures.result_store(this.plugin);
21
-
22
- done();
23
- };
24
-
25
- exports.karma_init = {
26
- setUp : _set_up,
27
- 'load_karma_ini': function (test) {
28
- test.expect(2);
29
- this.plugin.inherits('haraka-plugin-redis');
30
- this.plugin.load_karma_ini();
31
- test.ok(this.plugin.cfg.asn);
32
- test.ok(this.plugin.deny_hooks);
33
- test.done();
34
- },
35
- };
36
-
37
- exports.results_init = {
38
- setUp : _set_up,
39
- 'init, pre': function (test) {
40
- test.expect(1);
41
- const r = this.connection.results.get('karma');
42
- test.equal(undefined, r);
43
- test.done();
44
- },
45
- 'init, empty cfg': function (test) {
46
- this.plugin.results_init(stub, this.connection);
47
- const r = this.connection.results.get('karma');
48
- test.expect(1);
49
- test.ok(r);
50
- test.done();
51
- },
52
- 'init, cfg': function (test) {
53
- this.plugin.cfg.awards = { test: 1 };
54
- this.plugin.results_init(stub, this.connection);
55
- const r = this.connection.results.get('karma');
56
- test.expect(2);
57
- test.ok(r);
58
- test.ok(r.todo);
59
- test.done();
60
- },
61
- 'init, skip': function (test) {
62
- this.connection.remote.is_private = true;
63
- this.plugin.results_init(stub, this.connection);
64
- const r = this.connection.results.get('karma');
65
- test.expect(1);
66
- test.equal(undefined, r);
67
- test.done();
68
- },
69
- 'init, private skip': function (test) {
70
- this.connection.notes.disable_karma = true;
71
- this.plugin.results_init(stub, this.connection);
72
- const r = this.connection.results.get('karma');
73
- test.expect(1);
74
- test.equal(undefined, r);
75
- test.done();
76
- },
77
- };
78
-
79
- exports.assemble_note_obj = {
80
- setUp : _set_up,
81
- 'no auth fails': function (test) {
82
- test.expect(1);
83
- const obj = this.plugin.assemble_note_obj(this.connection, 'notes.auth_fails');
84
- test.equal(undefined, obj);
85
- test.done();
86
- },
87
- 'has auth fails': function (test) {
88
- test.expect(1);
89
- this.connection.notes.auth_fails=[1,2];
90
- const obj = this.plugin.assemble_note_obj(this.connection, 'notes.auth_fails');
91
- test.deepEqual([1,2], obj);
92
- test.done();
93
- },
94
- };
95
-
96
- exports.hook_deny = {
97
- setUp : _set_up,
98
- 'no params': function (test) {
99
- test.expect(1);
1
+ 'use strict'
2
+
3
+ const assert = require('assert')
4
+
5
+ const Address = require('address-rfc2821').Address
6
+ const fixtures = require('haraka-test-fixtures')
7
+ const constants = require('haraka-constants')
8
+
9
+ const stub = fixtures.stub.stub
10
+
11
+ function _set_up (done) {
12
+
13
+ this.plugin = new fixtures.plugin('karma')
14
+
15
+ this.plugin.cfg = { main: {} }
16
+ this.plugin.deny_hooks = {'connect': true}
17
+ this.plugin.tarpit_hooks = ['connect']
18
+
19
+ this.connection = fixtures.connection.createConnection({}, { notes: {} })
20
+ this.connection.transaction = fixtures.transaction.createTransaction()
21
+
22
+ done()
23
+ }
24
+
25
+
26
+ describe('karma_init', function () {
27
+ beforeEach(function (done) {
28
+ this.plugin = new fixtures.plugin('karma')
29
+ done()
30
+ })
31
+
32
+ it('load_karma_ini', function (done) {
33
+ this.plugin.inherits('haraka-plugin-redis')
34
+ this.plugin.load_karma_ini()
35
+ assert.ok(this.plugin.cfg.asn)
36
+ assert.ok(this.plugin.deny_hooks)
37
+ done()
38
+ })
39
+ })
40
+
41
+ describe('results_init', function () {
42
+ beforeEach(_set_up)
43
+
44
+ it('init, pre', function (done) {
45
+ const r = this.connection.results.get('karma')
46
+ assert.equal(undefined, r)
47
+ done()
48
+ })
49
+
50
+ it('init, empty cfg', function (done) {
51
+ this.plugin.results_init(stub, this.connection)
52
+ const r = this.connection.results.get('karma')
53
+ assert.ok(r)
54
+ done()
55
+ })
56
+
57
+ it('init, cfg', function (done) {
58
+ this.plugin.cfg.awards = { test: 1 }
59
+ this.plugin.results_init(stub, this.connection)
60
+ const r = this.connection.results.get('karma')
61
+ assert.ok(r)
62
+ assert.ok(r.todo)
63
+ done()
64
+ })
65
+
66
+ it('init, skip', function (done) {
67
+ this.connection.remote.is_private = true
68
+ this.plugin.results_init(stub, this.connection)
69
+ const r = this.connection.results.get('karma')
70
+ assert.equal(undefined, r)
71
+ done()
72
+ })
73
+
74
+ it('init, private skip', function (done) {
75
+ this.connection.notes.disable_karma = true
76
+ this.plugin.results_init(stub, this.connection)
77
+ const r = this.connection.results.get('karma')
78
+ assert.equal(undefined, r)
79
+ done()
80
+ })
81
+ })
82
+
83
+ describe('assemble_note_obj', function () {
84
+ beforeEach(_set_up)
85
+
86
+ it('no auth fails', function (done) {
87
+ const obj = this.plugin.assemble_note_obj(this.connection, 'notes.auth_fails')
88
+ assert.equal(undefined, obj)
89
+ done()
90
+ })
91
+
92
+ it('has auth fails', function (done) {
93
+ this.connection.notes.auth_fails=[1,2]
94
+ const obj = this.plugin.assemble_note_obj(this.connection, 'notes.auth_fails')
95
+ assert.deepEqual([1,2], obj)
96
+ done()
97
+ })
98
+ })
99
+
100
+ describe('hook_deny', function () {
101
+ beforeEach(_set_up)
102
+
103
+ it('no params', function (done) {
100
104
  const next = function (rc) {
101
- test.equal(constants.OK, rc, rc);
102
- test.done();
103
- };
104
- this.plugin.hook_deny(next, this.connection, ['','','','']);
105
- },
106
- 'pi_name=karma': function (test) {
107
- test.expect(1);
105
+ assert.equal(constants.OK, rc, rc)
106
+ done()
107
+ }
108
+ this.plugin.hook_deny(next, this.connection, ['','','',''])
109
+ })
110
+
111
+ it('pi_name=karma', function (done) {
108
112
  const next = function (rc) {
109
- test.equal(undefined, rc);
110
- test.done();
111
- };
112
- this.plugin.hook_deny(next, this.connection, ['','','karma','']);
113
- },
114
- 'pi_name=access': function (test) {
115
- test.expect(1);
113
+ assert.equal(undefined, rc)
114
+ done()
115
+ }
116
+ this.plugin.hook_deny(next, this.connection, ['','','karma',''])
117
+ })
118
+
119
+ it('pi_name=access', function (done) {
116
120
  const next = function (rc) {
117
- test.equal(undefined, rc);
118
- test.done();
119
- };
120
- this.plugin.deny_exclude_plugins = { access: true };
121
- this.plugin.hook_deny(next, this.connection, ['','','access','']);
122
- },
123
- 'pi_hook=rcpt_to': function (test) {
124
- test.expect(1);
121
+ assert.equal(undefined, rc)
122
+ done()
123
+ }
124
+ this.plugin.deny_exclude_plugins = { access: true }
125
+ this.plugin.hook_deny(next, this.connection, ['','','access',''])
126
+ })
127
+
128
+ it('pi_hook=rcpt_to', function (done) {
125
129
  const next = function (rc) {
126
- test.equal(undefined, rc);
127
- test.done();
128
- };
129
- this.plugin.deny_exclude_hooks = { rcpt_to: true };
130
+ assert.equal(undefined, rc)
131
+ done()
132
+ }
133
+ this.plugin.deny_exclude_hooks = { rcpt_to: true }
130
134
  this.plugin.hook_deny(next, this.connection,
131
- ['','','','','','rcpt_to']);
132
- },
133
- 'pi_hook=queue': function (test) {
134
- test.expect(1);
135
+ ['','','','','','rcpt_to'])
136
+ })
137
+
138
+ it('pi_hook=queue', function (done) {
135
139
  const next = function (rc) {
136
- test.equal(undefined, rc);
137
- test.done();
138
- };
139
- this.plugin.deny_exclude_hooks = { queue: true };
140
- this.plugin.hook_deny(next, this.connection, ['','','','','','queue']);
141
- },
142
- 'denysoft': function (test) {
143
- test.expect(1);
140
+ assert.equal(undefined, rc)
141
+ done()
142
+ }
143
+ this.plugin.deny_exclude_hooks = { queue: true }
144
+ this.plugin.hook_deny(next, this.connection, ['','','','','','queue'])
145
+ })
146
+
147
+ it('denysoft', function (done) {
144
148
  const next = function (rc) {
145
- test.equal(constants.OK, rc);
146
- test.done();
147
- };
148
- this.plugin.hook_deny(next, this.connection, [constants.DENYSOFT,'','','','','']);
149
- },
150
- };
151
-
152
- exports.get_award_location = {
153
- setUp : _set_up,
154
- 'relaying=false': function (test) {
155
- test.expect(1);
156
- this.connection.relaying=false;
157
- const r = this.plugin.get_award_location(this.connection, 'relaying');
158
- test.equal(false, r);
159
- test.done();
160
- },
161
- 'relaying=true': function (test) {
162
- test.expect(1);
163
- this.connection.relaying=true;
164
- const r = this.plugin.get_award_location(this.connection, 'relaying');
165
- test.equal(true, r);
166
- test.done();
167
- },
168
- 'notes.undef=2': function (test) {
169
- test.expect(1);
170
- const r = this.plugin.get_award_location(this.connection, 'notes.undef');
171
- test.equal(undefined, r);
172
- test.done();
173
- },
174
- 'notes.tarpit=2': function (test) {
175
- test.expect(1);
176
- this.connection.notes = { tarpit: 2 };
177
- const r = this.plugin.get_award_location(this.connection, 'notes.tarpit');
178
- test.equal(2, r);
179
- test.done();
180
- },
181
- 'results.geoip': function (test) {
182
- test.expect(1);
183
- this.connection.results.add('geoip', { country: 'US' });
184
- const r = this.plugin.get_award_location(this.connection, 'results.geoip');
149
+ assert.equal(constants.OK, rc)
150
+ done()
151
+ }
152
+ this.plugin.hook_deny(next, this.connection, [constants.DENYSOFT,'','','','',''])
153
+ })
154
+ })
155
+
156
+ describe('get_award_location', function () {
157
+ beforeEach(_set_up)
158
+
159
+ it('relaying=false', function (done) {
160
+ this.connection.relaying=false
161
+ const r = this.plugin.get_award_location(this.connection, 'relaying')
162
+ assert.equal(false, r)
163
+ done()
164
+ })
165
+
166
+ it('relaying=true', function (done) {
167
+ this.connection.relaying=true
168
+ const r = this.plugin.get_award_location(this.connection, 'relaying')
169
+ assert.equal(true, r)
170
+ done()
171
+ })
172
+
173
+ it('notes.undef=2', function (done) {
174
+ const r = this.plugin.get_award_location(this.connection, 'notes.undef')
175
+ assert.equal(undefined, r)
176
+ done()
177
+ })
178
+
179
+ it('notes.tarpit=2', function (done) {
180
+ this.connection.notes = { tarpit: 2 }
181
+ const r = this.plugin.get_award_location(this.connection, 'notes.tarpit')
182
+ assert.equal(2, r)
183
+ done()
184
+ })
185
+
186
+ it('results.geoip', function (done) {
187
+ this.connection.results.add('geoip', { country: 'US' })
188
+ const r = this.plugin.get_award_location(this.connection, 'results.geoip')
185
189
  // console.log(r);
186
- test.equal('US', r.country);
187
- test.done();
188
- },
189
- 'results.karma': function (test) {
190
- test.expect(1);
191
- this.connection.results.add('karma', { score: -1 });
192
- const r = this.plugin.get_award_location(this.connection, 'results.karma');
190
+ assert.equal('US', r.country)
191
+ done()
192
+ })
193
+
194
+ it('results.karma', function (done) {
195
+ this.connection.results.add('karma', { score: -1 })
196
+ const r = this.plugin.get_award_location(this.connection, 'results.karma')
193
197
  // console.log(r);
194
- test.equal(-1, r.score);
195
- test.done();
196
- },
197
- 'results.karma, txn': function (test) {
198
+ assert.equal(-1, r.score)
199
+ done()
200
+ })
201
+
202
+ it('results.karma, txn', function (done) {
198
203
  // results should be found in conn or txn
199
- test.expect(1);
200
- this.connection.transaction.results.add('karma', { score: -1 });
201
- const r = this.plugin.get_award_location(this.connection, 'results.karma');
204
+ this.connection.transaction.results.add('karma', { score: -1 })
205
+ const r = this.plugin.get_award_location(this.connection, 'results.karma')
202
206
  // console.log(r);
203
- test.equal(-1, r.score);
204
- test.done();
205
- },
206
- 'txn.results.karma': function (test) {
207
+ assert.equal(-1, r.score)
208
+ done()
209
+ })
210
+
211
+ it('txn.results.karma', function (done) {
207
212
  // these results shouldn't be found, b/c txn specified
208
- test.expect(1);
209
- this.connection.results.add('karma', { score: -1 });
210
- const r = this.plugin.get_award_location(this.connection, 'transaction.results.karma');
213
+ this.connection.results.add('karma', { score: -1 })
214
+ const r = this.plugin.get_award_location(this.connection, 'transaction.results.karma')
211
215
  // console.log(r);
212
- test.equal(undefined, r);
213
- test.done();
214
- },
215
- 'results.auth/auth_base': function (test) {
216
- test.expect(1);
217
- this.connection.results.add('auth/auth_base', { fail: 'PLAIN' });
218
- const r = this.plugin.get_award_location(this.connection, 'results.auth/auth_base');
219
- test.equal('PLAIN', r.fail[0]);
220
- test.done();
221
- },
222
- };
223
-
224
- exports.get_award_condition = {
225
- setUp : _set_up,
226
- 'geoip.distance': function (test) {
227
- test.expect(2);
228
- test.equal(4000, this.plugin.get_award_condition(
216
+ assert.equal(undefined, r)
217
+ done()
218
+ })
219
+
220
+ it('results.auth/auth_base', function (done) {
221
+ this.connection.results.add('auth/auth_base', { fail: 'PLAIN' })
222
+ const r = this.plugin.get_award_location(this.connection, 'results.auth/auth_base')
223
+ assert.equal('PLAIN', r.fail[0])
224
+ done()
225
+ })
226
+ })
227
+
228
+ describe('get_award_condition', function () {
229
+ beforeEach(_set_up)
230
+ it('geoip.distance', function (done) {
231
+ assert.equal(4000, this.plugin.get_award_condition(
229
232
  'results.geoip.distance@4000', '-1 if gt'
230
- ));
231
- test.equal(4000, this.plugin.get_award_condition(
233
+ ))
234
+ assert.equal(4000, this.plugin.get_award_condition(
232
235
  'results.geoip.distance@uniq', '-1 if gt 4000'
233
- ));
234
- test.done();
235
- },
236
- 'auth/auth_base': function (test) {
237
- test.expect(1);
238
- test.equal('plain', this.plugin.get_award_condition(
236
+ ))
237
+ done()
238
+ })
239
+
240
+ it('auth/auth_base', function (done) {
241
+ assert.equal('plain', this.plugin.get_award_condition(
239
242
  'results.auth/auth_base.fail@plain', '-1 if in'
240
- ));
241
- test.done();
242
- },
243
- };
244
-
245
- exports.check_awards = {
246
- setUp : _set_up,
247
- 'no results': function (test) {
248
- test.expect(1);
249
- const r = this.plugin.check_awards(this.connection);
250
- test.equal(undefined, r);
251
- test.done();
252
- },
253
- 'no todo': function (test) {
254
- test.expect(1);
255
- this.connection.results.add('karma', { todo: { } });
256
- const r = this.plugin.check_awards(this.connection);
257
- test.equal(undefined, r);
258
- test.done();
259
- },
260
- 'geoip gt': function (test) {
261
- test.expect(2);
243
+ ))
244
+ done()
245
+ })
246
+ })
247
+
248
+ describe('check_awards', function () {
249
+ beforeEach(_set_up)
250
+
251
+ it('no results', function (done) {
252
+ const r = this.plugin.check_awards(this.connection)
253
+ assert.equal(undefined, r)
254
+ done()
255
+ })
256
+
257
+ it('no todo', function (done) {
258
+ this.connection.results.add('karma', { todo: { } })
259
+ const r = this.plugin.check_awards(this.connection)
260
+ assert.equal(undefined, r)
261
+ done()
262
+ })
263
+
264
+ it('geoip gt', function (done) {
262
265
 
263
266
  // populate the karma result with a todo item
264
267
  this.connection.results.add('karma', {
265
268
  todo: { 'results.geoip.distance@4000': '-1 if gt 4000' }
266
- });
269
+ })
267
270
  // test a non-matching criteria
268
- this.connection.results.add('geoip', { distance: 4000 });
271
+ this.connection.results.add('geoip', { distance: 4000 })
269
272
  // check awards
270
- this.plugin.check_awards(this.connection);
271
- test.equal(undefined, this.connection.results.get('karma').fail[0]);
273
+ this.plugin.check_awards(this.connection)
274
+ assert.equal(undefined, this.connection.results.get('karma').fail[0])
272
275
 
273
276
  // test a matching criteria
274
- this.connection.results.add('geoip', { distance: 4001 });
277
+ this.connection.results.add('geoip', { distance: 4001 })
275
278
  // check awards
276
- this.plugin.check_awards(this.connection);
279
+ this.plugin.check_awards(this.connection)
277
280
  // test that the award was applied
278
- test.equal('geoip.distance', this.connection.results.get('karma').fail[0]);
281
+ assert.equal('geoip.distance', this.connection.results.get('karma').fail[0])
282
+
283
+ done()
284
+ })
279
285
 
280
- test.done();
281
- },
282
- 'auth failure': function (test) {
283
- test.expect(2);
286
+ it('auth failure', function (done) {
284
287
  this.connection.results.add('karma', {
285
288
  todo: { 'results.auth/auth_base.fail@PLAIN': '-1 if in' }
286
- });
289
+ })
287
290
  this.connection.results.add('auth/auth_base',
288
- {fail: 'PLAIN'});
289
- const r = this.plugin.check_awards(this.connection);
290
- test.equal(undefined, r);
291
- test.equal('auth/auth_base.fail', this.connection.results.get('karma').fail[0]);
292
- test.done();
293
- },
294
- 'valid recipient': function (test) {
295
- test.expect(2);
291
+ {fail: 'PLAIN'})
292
+ const r = this.plugin.check_awards(this.connection)
293
+ assert.equal(undefined, r)
294
+ assert.equal('auth/auth_base.fail', this.connection.results.get('karma').fail[0])
295
+ done()
296
+ })
297
+
298
+ it('valid recipient', function (done) {
296
299
  this.connection.results.add('karma', {
297
300
  todo: { 'results.rcpt_to.qmd.pass@exist': '1 if in' }
298
- });
299
- this.connection.results.add('rcpt_to.qmd', {pass: 'exist'});
300
- const r = this.plugin.check_awards(this.connection);
301
- test.equal(undefined, r);
302
- test.equal('qmd.pass', this.connection.results.get('karma').pass[0]);
303
- test.done();
304
- },
305
- };
306
-
307
- exports.apply_tarpit = {
308
- setUp : _set_up,
309
- 'tarpit=false': function (test) {
310
- test.expect(2);
301
+ })
302
+ this.connection.results.add('rcpt_to.qmd', {pass: 'exist'})
303
+ const r = this.plugin.check_awards(this.connection)
304
+ assert.equal(undefined, r)
305
+ assert.equal('qmd.pass', this.connection.results.get('karma').pass[0])
306
+ done()
307
+ })
308
+ })
309
+
310
+ describe('apply_tarpit', function () {
311
+ beforeEach(_set_up)
312
+
313
+ it('tarpit=false', function (done) {
311
314
  const next = function (rc, msg) {
312
- test.equal(undefined, rc);
313
- test.equal(undefined, msg);
314
- test.done();
315
- };
316
- this.plugin.apply_tarpit(this.connection, 'connect', 0, next);
317
- },
318
- 'tarpit=true, score=0': function (test) {
319
- test.expect(2);
315
+ assert.equal(undefined, rc)
316
+ assert.equal(undefined, msg)
317
+ done()
318
+ }
319
+ this.plugin.apply_tarpit(this.connection, 'connect', 0, next)
320
+ })
321
+
322
+ it('tarpit=true, score=0', function (done) {
320
323
  const next = function (rc, msg) {
321
- test.equal(undefined, rc);
322
- test.equal(undefined, msg);
323
- test.done();
324
- };
325
- this.plugin.cfg.tarpit = { max: 1, delay: 0 };
326
- this.plugin.apply_tarpit(this.connection, 'connect', 0, next);
327
- },
328
- 'tarpit=true, score=1': function (test) {
329
- test.expect(2);
324
+ assert.equal(undefined, rc)
325
+ assert.equal(undefined, msg)
326
+ done()
327
+ }
328
+ this.plugin.cfg.tarpit = { max: 1, delay: 0 }
329
+ this.plugin.apply_tarpit(this.connection, 'connect', 0, next)
330
+ })
331
+
332
+ it('tarpit=true, score=1', function (done) {
330
333
  const next = function (rc, msg) {
331
- test.equal(undefined, rc);
332
- test.equal(undefined, msg);
333
- test.done();
334
- };
335
- this.plugin.cfg.tarpit = { max: 1, delay: 0 };
336
- this.plugin.apply_tarpit(this.connection, 'connect', 1, next);
337
- },
338
- 'tarpit=true, score=-1': function (test) {
339
- test.expect(3);
340
- const before = Date.now();
334
+ assert.equal(undefined, rc)
335
+ assert.equal(undefined, msg)
336
+ done()
337
+ }
338
+ this.plugin.cfg.tarpit = { max: 1, delay: 0 }
339
+ this.plugin.apply_tarpit(this.connection, 'connect', 1, next)
340
+ })
341
+
342
+ it('tarpit=true, score=-1', function (done) {
343
+ const before = Date.now()
341
344
  const next = function (rc, msg) {
342
- test.ok(Date.now() >= before + 1);
343
- test.equal(undefined, rc);
344
- test.equal(undefined, msg);
345
- test.done();
346
- };
347
- this.plugin.cfg.tarpit = { max: 1, delay: 0 };
348
- this.plugin.apply_tarpit(this.connection, 'connect', -1, next);
349
- },
350
- 'tarpit=true, score=-2, max=1': function (test) {
351
- test.expect(3);
352
- const before = Date.now();
345
+ assert.ok(Date.now() >= before + 1)
346
+ assert.equal(undefined, rc)
347
+ assert.equal(undefined, msg)
348
+ done()
349
+ }
350
+ this.plugin.cfg.tarpit = { max: 1, delay: 0 }
351
+ this.plugin.apply_tarpit(this.connection, 'connect', -1, next)
352
+ })
353
+
354
+ it('tarpit=true, score=-2, max=1', function (done) {
355
+ const before = Date.now()
353
356
  const next = function (rc, msg) {
354
- test.ok(Date.now() >= before + 1);
355
- test.equal(undefined, rc);
356
- test.equal(undefined, msg);
357
- test.done();
358
- };
359
- this.plugin.cfg.tarpit = { max: 1, delay: 0 };
360
- this.plugin.apply_tarpit(this.connection, 'connect', -2, next);
361
- },
362
- 'tarpit=true, score=connect, max=1': function (test) {
363
- test.expect(3);
364
- const before = Date.now();
357
+ assert.ok(Date.now() >= before + 1)
358
+ assert.equal(undefined, rc)
359
+ assert.equal(undefined, msg)
360
+ done()
361
+ }
362
+ this.plugin.cfg.tarpit = { max: 1, delay: 0 }
363
+ this.plugin.apply_tarpit(this.connection, 'connect', -2, next)
364
+ })
365
+
366
+ it('tarpit=true, score=connect, max=1', function (done) {
367
+ const before = Date.now()
365
368
  const next = function (rc, msg) {
366
- test.ok(Date.now() >= before + 1);
367
- test.equal(undefined, rc);
368
- test.equal(undefined, msg);
369
- test.done();
370
- };
371
- this.plugin.cfg.tarpit = { max: 1, delay: 0 };
372
- this.connection.results.add(this.plugin, { score: -2 });
373
- this.plugin.apply_tarpit(this.connection, 'connect', -2, next);
374
- },
375
- };
376
-
377
- exports.should_we_deny = {
378
- setUp : _set_up,
379
- 'no results': function (test) {
380
- test.expect(2);
369
+ assert.ok(Date.now() >= before + 1)
370
+ assert.equal(undefined, rc)
371
+ assert.equal(undefined, msg)
372
+ done()
373
+ }
374
+ this.plugin.cfg.tarpit = { max: 1, delay: 0 }
375
+ this.connection.results.add(this.plugin, { score: -2 })
376
+ this.plugin.apply_tarpit(this.connection, 'connect', -2, next)
377
+ })
378
+ })
379
+
380
+ describe('should_we_deny', function () {
381
+ beforeEach(_set_up)
382
+
383
+ it('no results', function (done) {
381
384
  const next = function (rc, msg) {
382
- test.equal(undefined, rc);
383
- test.equal(undefined, msg);
384
- test.done();
385
- };
386
- this.plugin.should_we_deny(next, this.connection, 'connect');
387
- },
388
- 'no score': function (test) {
389
- test.expect(2);
385
+ assert.equal(undefined, rc)
386
+ assert.equal(undefined, msg)
387
+ done()
388
+ }
389
+ this.plugin.should_we_deny(next, this.connection, 'connect')
390
+ })
391
+
392
+ it('no score', function (done) {
390
393
  const next = function (rc, msg) {
391
- test.equal(undefined, rc);
392
- test.equal(undefined, msg);
393
- test.done();
394
- };
395
- this.connection.results.add(this.plugin, { test: 'blah' });
396
- this.plugin.should_we_deny(next, this.connection, 'connect');
397
- },
398
- 'invalid score': function (test) {
399
- test.expect(2);
394
+ assert.equal(undefined, rc)
395
+ assert.equal(undefined, msg)
396
+ done()
397
+ }
398
+ this.connection.results.add(this.plugin, { test: 'blah' })
399
+ this.plugin.should_we_deny(next, this.connection, 'connect')
400
+ })
401
+
402
+ it('invalid score', function (done) {
400
403
  const next = function (rc, msg) {
401
- test.equal(undefined, rc);
402
- test.equal(undefined, msg);
403
- test.done();
404
- };
405
- this.connection.results.add(this.plugin, { score: 'blah' });
406
- this.plugin.should_we_deny(next, this.connection, 'connect');
407
- },
408
- 'valid score, okay': function (test) {
409
- test.expect(2);
404
+ assert.equal(undefined, rc)
405
+ assert.equal(undefined, msg)
406
+ done()
407
+ }
408
+ this.connection.results.add(this.plugin, { score: 'blah' })
409
+ this.plugin.should_we_deny(next, this.connection, 'connect')
410
+ })
411
+
412
+ it('valid score, okay', function (done) {
410
413
  const next = function (rc, msg) {
411
- test.equal(undefined, rc);
412
- test.equal(undefined, msg);
413
- test.done();
414
- }.bind(this);
415
- this.plugin.cfg.tarpit = { max: 1, delay: 0 };
416
- this.connection.results.add(this.plugin, { score: -1 });
417
- this.plugin.should_we_deny(next, this.connection, 'connect');
418
- },
419
- 'valid score, -6, deny_hook': function (test) {
420
- test.expect(2);
414
+ assert.equal(undefined, rc)
415
+ assert.equal(undefined, msg)
416
+ done()
417
+ }.bind(this)
418
+ this.plugin.cfg.tarpit = { max: 1, delay: 0 }
419
+ this.connection.results.add(this.plugin, { score: -1 })
420
+ this.plugin.should_we_deny(next, this.connection, 'connect')
421
+ })
422
+
423
+ it('valid score, -6, deny_hook', function (done) {
421
424
  const next = function (rc, msg) {
422
- test.equal(constants.DENY, rc);
423
- test.ok(msg);
424
- test.done();
425
- }.bind(this);
426
- this.plugin.cfg.tarpit = { max: 1, delay: 0 };
427
- this.plugin.deny_hooks = { connect: true};
428
- this.connection.results.add(this.plugin, { score: -6 });
429
- this.plugin.should_we_deny(next, this.connection, 'connect');
430
- },
431
- 'valid score, -6, pass_hook': function (test) {
432
- test.expect(2);
425
+ assert.equal(constants.DENY, rc)
426
+ assert.ok(msg)
427
+ done()
428
+ }.bind(this)
429
+ this.plugin.cfg.tarpit = { max: 1, delay: 0 }
430
+ this.plugin.deny_hooks = { connect: true}
431
+ this.connection.results.add(this.plugin, { score: -6 })
432
+ this.plugin.should_we_deny(next, this.connection, 'connect')
433
+ })
434
+
435
+ it('valid score, -6, pass_hook', function (done) {
433
436
  const next = function (rc, msg) {
434
- test.equal(undefined, rc);
435
- test.equal(undefined, msg);
436
- test.done();
437
- }.bind(this);
438
- this.plugin.cfg.tarpit = { max: 1, delay: 0 };
439
- this.plugin.deny_hooks = { helo: true };
440
- this.connection.results.add(this.plugin, { score: -6 });
441
- this.plugin.should_we_deny(next, this.connection, 'connect');
442
- },
443
- };
444
-
445
- exports.check_result_equal = {
446
- setUp : _set_up,
447
- 'equal match is scored': function (test) {
448
- test.expect(2);
437
+ assert.equal(undefined, rc)
438
+ assert.equal(undefined, msg)
439
+ done()
440
+ }.bind(this)
441
+ this.plugin.cfg.tarpit = { max: 1, delay: 0 }
442
+ this.plugin.deny_hooks = { helo: true }
443
+ this.connection.results.add(this.plugin, { score: -6 })
444
+ this.plugin.should_we_deny(next, this.connection, 'connect')
445
+ })
446
+ })
447
+
448
+ describe('check_result_equal', function () {
449
+ beforeEach(_set_up)
450
+
451
+ it('equal match is scored', function (done) {
449
452
  const award = {
450
453
  id : 1, award : 2,
451
454
  operator : 'equals', value : 'clean',
452
455
  reason : 'testing', resolution : 'never',
453
- };
454
- this.plugin.check_result_equal(['clean'], award, this.connection);
455
- test.equals(this.connection.results.store.karma.score, 2);
456
- test.equals(this.connection.results.store.karma.awards[0], 1);
457
- test.done();
458
- },
459
- 'not equal match is not scored': function (test) {
460
- test.expect(1);
456
+ }
457
+ this.plugin.check_result_equal(['clean'], award, this.connection)
458
+ assert.equal(this.connection.results.store.karma.score, 2)
459
+ assert.equal(this.connection.results.store.karma.awards[0], 1)
460
+ done()
461
+ })
462
+
463
+ it('not equal match is not scored', function (done) {
461
464
  const award = {
462
465
  id : 1, award : 2,
463
466
  operator : 'equals', value : 'dirty',
464
467
  reason : 'testing', resolution : 'never',
465
- };
466
- this.plugin.check_result_equal(['clean'], award, this.connection);
467
- test.equals(this.connection.results.store.karma, undefined);
468
- test.done();
469
- }
470
- };
471
-
472
- exports.check_result_gt = {
473
- setUp : _set_up,
474
- 'gt match is scored': function (test) {
475
- test.expect(2);
468
+ }
469
+ this.plugin.check_result_equal(['clean'], award, this.connection)
470
+ assert.equal(this.connection.results.store.karma, undefined)
471
+ done()
472
+ })
473
+ })
474
+
475
+ describe('check_result_gt', function () {
476
+ beforeEach(_set_up)
477
+
478
+ it('gt match is scored', function (done) {
476
479
  const award = {
477
480
  id : 5, award : 3,
478
481
  operator : 'gt', value : 3,
479
482
  reason : 'testing', resolution : 'never',
480
- };
481
- this.plugin.check_result_gt([4], award, this.connection);
483
+ }
484
+ this.plugin.check_result_gt([4], award, this.connection)
482
485
  // console.log(this.connection.results.store);
483
- test.equals(this.connection.results.store.karma.score, 3);
484
- test.equals(this.connection.results.store.karma.awards[0], 5);
485
- test.done();
486
- }
487
- };
488
-
489
- exports.check_result_lt = {
490
- setUp : _set_up,
491
- 'lt match is scored': function (test) {
492
- test.expect(2);
486
+ assert.equal(this.connection.results.store.karma.score, 3)
487
+ assert.equal(this.connection.results.store.karma.awards[0], 5)
488
+ done()
489
+ })
490
+ })
491
+
492
+ describe('check_result_lt', function () {
493
+ beforeEach(_set_up)
494
+
495
+ it('lt match is scored', function (done) {
493
496
  const award = {
494
497
  id : 2, award : 3,
495
498
  operator : 'lt', value : 5,
496
499
  reason : 'testing', resolution : 'never',
497
- };
498
- this.plugin.check_result_lt([4], award, this.connection);
500
+ }
501
+ this.plugin.check_result_lt([4], award, this.connection)
499
502
  // console.log(this.connection.results.store);
500
- test.equals(this.connection.results.store.karma.score, 3);
501
- test.equals(this.connection.results.store.karma.awards[0], 2);
502
- test.done();
503
- },
504
- 'lt match not scored': function (test) {
505
- test.expect(1);
503
+ assert.equal(this.connection.results.store.karma.score, 3)
504
+ assert.equal(this.connection.results.store.karma.awards[0], 2)
505
+ done()
506
+ })
507
+
508
+ it('lt match not scored', function (done) {
506
509
  const award = {
507
510
  id : 3, award : 3,
508
511
  operator : 'lt', value : 3,
509
512
  reason : 'testing', resolution : 'never',
510
- };
511
- this.plugin.check_result_lt([4], award, this.connection);
513
+ }
514
+ this.plugin.check_result_lt([4], award, this.connection)
512
515
  // console.log(this.connection.results.store);
513
- test.equals(this.connection.results.store.karma, undefined);
514
- test.done();
515
- }
516
- };
517
-
518
- exports.check_result_match = {
519
- setUp : _set_up,
520
- 'match pattern is scored': function (test) {
521
- test.expect(2);
516
+ assert.equal(this.connection.results.store.karma, undefined)
517
+ done()
518
+ })
519
+ })
520
+
521
+ describe('check_result_match', function () {
522
+ beforeEach(_set_up)
523
+
524
+ it('match pattern is scored', function (done) {
522
525
  const award = {
523
526
  id : 1, award : 2,
524
527
  operator : 'match', value : 'phish',
525
528
  reason : 'testing', resolution : 'never',
526
- };
527
- this.plugin.check_result_match(['isphishing'], award, this.connection);
529
+ }
530
+ this.plugin.check_result_match(['isphishing'], award, this.connection)
528
531
  // console.log(this.connection.results.store);
529
- test.equals(this.connection.results.store.karma.score, 2);
530
- test.equals(this.connection.results.store.karma.awards[0], 1);
531
- test.done();
532
- },
533
- 'mismatch is not scored': function (test) {
534
- test.expect(1);
532
+ assert.equal(this.connection.results.store.karma.score, 2)
533
+ assert.equal(this.connection.results.store.karma.awards[0], 1)
534
+ done()
535
+ })
536
+
537
+ it('mismatch is not scored', function (done) {
535
538
  const award = {
536
539
  id : 1, award : 2,
537
540
  operator : 'match', value : 'dirty',
538
541
  reason : 'testing', resolution : 'never',
539
- };
540
- this.plugin.check_result_match(['clean'], award, this.connection);
542
+ }
543
+ this.plugin.check_result_match(['clean'], award, this.connection)
541
544
  // console.log(this.connection.results.store);
542
- test.equals(this.connection.results.store.karma, undefined);
543
- test.done();
544
- },
545
- 'FCrDNS match is scored': function (test) {
546
- test.expect(2);
545
+ assert.equal(this.connection.results.store.karma, undefined)
546
+ done()
547
+ })
548
+
549
+ it('FCrDNS match is scored', function (done) {
547
550
  const award = {
548
551
  id : 89, award : 2,
549
552
  operator : 'match', value : 'google.com',
550
553
  reason : 'testing', resolution : 'never',
551
- };
552
- this.plugin.check_result_match(['mail-yk0-f182.google.com'], award, this.connection);
554
+ }
555
+ this.plugin.check_result_match(['mail-yk0-f182.google.com'], award, this.connection)
553
556
  // console.log(this.connection.results.store);
554
- test.equals(this.connection.results.store.karma.score, 2);
555
- test.equals(this.connection.results.store.karma.awards[0], 89);
556
- test.done();
557
- },
558
- };
559
-
560
- exports.check_result_length = {
561
- setUp : _set_up,
562
- 'eq pattern is scored': function (test) {
563
- test.expect(2);
557
+ assert.equal(this.connection.results.store.karma.score, 2)
558
+ assert.equal(this.connection.results.store.karma.awards[0], 89)
559
+ done()
560
+ })
561
+ })
562
+
563
+ describe('check_result_length', function () {
564
+ beforeEach(_set_up)
565
+ it('eq pattern is scored', function (done) {
564
566
  const award = {
565
567
  id : 1, award : 2,
566
568
  operator : 'length', value : 'eq 3',
567
569
  reason : 'testing', resolution : 'hah',
568
- };
569
- this.plugin.check_result_length(['3'], award, this.connection);
570
+ }
571
+ this.plugin.check_result_length(['3'], award, this.connection)
570
572
  // console.log(this.connection.results.store);
571
- test.equals(this.connection.results.store.karma.score, 2);
572
- test.equals(this.connection.results.store.karma.awards[0], 1);
573
- test.done();
574
- },
575
- 'eq pattern is not scored': function (test) {
576
- test.expect(1);
573
+ assert.equal(this.connection.results.store.karma.score, 2)
574
+ assert.equal(this.connection.results.store.karma.awards[0], 1)
575
+ done()
576
+ })
577
+
578
+ it('eq pattern is not scored', function (done) {
577
579
  const award = {
578
580
  id : 1, award : 2,
579
581
  operator : 'length', value : 'eq 3',
580
582
  reason : 'testing', resolution : 'hah',
581
- };
582
- this.plugin.check_result_length(['4'], award, this.connection);
583
+ }
584
+ this.plugin.check_result_length(['4'], award, this.connection)
583
585
  // console.log(this.connection.results.store.karma);
584
- test.deepEqual(this.connection.results.store.karma, undefined);
585
- test.done();
586
- },
587
- 'gt pattern is scored': function (test) {
588
- test.expect(2);
586
+ assert.deepEqual(this.connection.results.store.karma, undefined)
587
+ done()
588
+ })
589
+
590
+ it('gt pattern is scored', function (done) {
589
591
  const award = {
590
592
  id : 1, award : 2,
591
593
  operator : 'length', value : 'gt 3',
592
594
  reason : 'testing', resolution : 'hah',
593
- };
594
- this.plugin.check_result_length(['5'], award, this.connection);
595
+ }
596
+ this.plugin.check_result_length(['5'], award, this.connection)
595
597
  // console.log(this.connection.results.store);
596
- test.equals(this.connection.results.store.karma.score, 2);
597
- test.equals(this.connection.results.store.karma.awards[0], 1);
598
- test.done();
599
- },
600
- 'gt pattern is not scored': function (test) {
601
- test.expect(1);
598
+ assert.equal(this.connection.results.store.karma.score, 2)
599
+ assert.equal(this.connection.results.store.karma.awards[0], 1)
600
+ done()
601
+ })
602
+
603
+ it('gt pattern is not scored', function (done) {
602
604
  const award = {
603
605
  id : 1, award : 2,
604
606
  operator : 'length', value : 'gt 3',
605
607
  reason : 'testing', resolution : 'hah',
606
- };
607
- this.plugin.check_result_length(['3'], award, this.connection);
608
+ }
609
+ this.plugin.check_result_length(['3'], award, this.connection)
608
610
  // console.log(this.connection.results.store.karma);
609
- test.deepEqual(this.connection.results.store.karma, undefined);
610
- test.done();
611
- },
612
- 'lt pattern is scored': function (test) {
613
- test.expect(2);
611
+ assert.deepEqual(this.connection.results.store.karma, undefined)
612
+ done()
613
+ })
614
+
615
+ it('lt pattern is scored', function (done) {
614
616
  const award = {
615
617
  id : 1, award : 2,
616
618
  operator : 'length', value : 'lt 3',
617
619
  reason : 'testing', resolution : 'hah',
618
- };
619
- this.plugin.check_result_length(['2'], award, this.connection);
620
+ }
621
+ this.plugin.check_result_length(['2'], award, this.connection)
620
622
  // console.log(this.connection.results.store);
621
- test.equals(this.connection.results.store.karma.score, 2);
622
- test.equals(this.connection.results.store.karma.awards[0], 1);
623
- test.done();
624
- },
625
- 'lt pattern is not scored': function (test) {
626
- test.expect(1);
623
+ assert.equal(this.connection.results.store.karma.score, 2)
624
+ assert.equal(this.connection.results.store.karma.awards[0], 1)
625
+ done()
626
+ })
627
+
628
+ it('lt pattern is not scored', function (done) {
627
629
  const award = {
628
630
  id : 1, award : 2,
629
631
  operator : 'length', value : 'lt 3',
630
632
  reason : 'testing', resolution : 'hah',
631
- };
632
- this.plugin.check_result_length(['3'], award, this.connection);
633
+ }
634
+ this.plugin.check_result_length(['3'], award, this.connection)
633
635
  // console.log(this.connection.results.store.karma);
634
- test.deepEqual(this.connection.results.store.karma, undefined);
635
- test.done();
636
- },
637
- };
638
-
639
- exports.check_result = {
640
- setUp : _set_up,
641
- 'geoip country is scored': function (test) {
642
- test.expect(2);
636
+ assert.deepEqual(this.connection.results.store.karma, undefined)
637
+ done()
638
+ })
639
+ })
640
+
641
+ describe('check_result_exists', function () {
642
+ beforeEach(_set_up)
643
+
644
+ it('exists pattern is scored', function (done) {
645
+ const award = {
646
+ id : 1, award : 2,
647
+ operator : 'exists', value : 'any',
648
+ reason : 'testing', resolution : 'high five',
649
+ }
650
+ this.plugin.check_result_exists(['3'], award, this.connection)
651
+ // console.log(this.connection.results.store);
652
+ assert.equal(this.connection.results.store.karma.score, 2)
653
+ assert.equal(this.connection.results.store.karma.awards[0], 1)
654
+ done()
655
+ })
656
+
657
+ it('not exists pattern is not scored', function (done) {
658
+ const award = {
659
+ id : 1, award : 3,
660
+ operator : 'exists', value : '',
661
+ reason : 'testing', resolution : 'misses',
662
+ }
663
+ this.plugin.check_result_exists([], award, this.connection)
664
+ // console.log(this.connection.results.store);
665
+ assert.equal(this.connection.results.store.karma, undefined)
666
+ assert.equal(this.connection.results.store.karma, undefined)
667
+ done()
668
+ })
669
+ })
670
+
671
+ describe('check_result', function () {
672
+ beforeEach(_set_up)
673
+
674
+ it('geoip country is scored', function (done) {
643
675
  this.plugin.cfg.result_awards = {
644
676
  1: 'geoip | country | equals | CN | 2',
645
- };
646
- this.plugin.preparse_result_awards();
647
- this.connection.results.add({name: 'geoip'}, {country: 'CN'});
677
+ }
678
+ this.plugin.preparse_result_awards()
679
+ this.connection.results.add({name: 'geoip'}, {country: 'CN'})
648
680
  this.plugin.check_result(this.connection,
649
- '{"plugin":"geoip","result":{"country":"CN"}}');
681
+ '{"plugin":"geoip","result":{"country":"CN"}}')
650
682
  // console.log(this.connection.results.store);
651
- test.equals(this.connection.results.store.karma.score, 2);
652
- test.equals(this.connection.results.store.karma.awards[0], 1);
653
- test.done();
654
- },
655
- 'dnsbl listing is scored': function (test) {
656
- test.expect(2);
683
+ assert.equal(this.connection.results.store.karma.score, 2)
684
+ assert.equal(this.connection.results.store.karma.awards[0], 1)
685
+ done()
686
+ })
687
+
688
+ it('dnsbl listing is scored', function (done) {
657
689
  this.plugin.cfg.result_awards = {
658
690
  2: 'dnsbl | fail | equals | dnsbl.sorbs.net | -5',
659
- };
660
- this.plugin.preparse_result_awards();
661
- this.connection.results.add({name: 'dnsbl'}, {fail: 'dnsbl.sorbs.net'});
691
+ }
692
+ this.plugin.preparse_result_awards()
693
+ this.connection.results.add({name: 'dnsbl'}, {fail: 'dnsbl.sorbs.net'})
662
694
  this.plugin.check_result(this.connection,
663
- '{"plugin":"dnsbl","result":{"fail":"dnsbl.sorbs.net"}}');
695
+ '{"plugin":"dnsbl","result":{"fail":"dnsbl.sorbs.net"}}')
664
696
  // console.log(this.connection.results.store);
665
- test.equals(this.connection.results.store.karma.score, -5);
666
- test.equals(this.connection.results.store.karma.awards[0], 2);
667
- test.done();
668
- },
669
- };
670
-
671
- exports.check_spammy_tld = {
672
- setUp : _set_up,
673
- 'spammy TLD is scored: top': function (test) {
674
- test.expect(2);
675
- this.plugin.cfg.spammy_tlds = { top: -3 };
676
- const mfrom = new Address('spamy@er7diogt.rrnsale.top');
677
- this.plugin.check_spammy_tld(mfrom, this.connection);
697
+ assert.equal(this.connection.results.store.karma.score, -5)
698
+ assert.equal(this.connection.results.store.karma.awards[0], 2)
699
+ done()
700
+ })
701
+ })
702
+
703
+ describe('check_spammy_tld', function () {
704
+ beforeEach(_set_up)
705
+
706
+ it('spammy TLD is scored: top', function (done) {
707
+ this.plugin.cfg.spammy_tlds = { top: -3 }
708
+ const mfrom = new Address('spamy@er7diogt.rrnsale.top')
709
+ this.plugin.check_spammy_tld(mfrom, this.connection)
678
710
  // console.log(this.connection.results.store);
679
- test.equals(this.connection.results.store.karma.score, -3);
680
- test.equals(this.connection.results.store.karma.fail[0], 'spammy.TLD');
681
- test.done();
682
- },
683
- 'spammy TLD is scored: rocks': function (test) {
684
- test.expect(2);
685
- this.plugin.cfg.spammy_tlds = { rocks: '-2' };
686
- const mfrom = new Address('spamy@foo.rocks');
687
- this.plugin.check_spammy_tld(mfrom, this.connection);
711
+ assert.equal(this.connection.results.store.karma.score, -3)
712
+ assert.equal(this.connection.results.store.karma.fail[0], 'spammy.TLD')
713
+ done()
714
+ })
715
+
716
+ it('spammy TLD is scored: rocks', function (done) {
717
+ this.plugin.cfg.spammy_tlds = { rocks: '-2' }
718
+ const mfrom = new Address('spamy@foo.rocks')
719
+ this.plugin.check_spammy_tld(mfrom, this.connection)
688
720
  // console.log(this.connection.results.store);
689
- test.equals(this.connection.results.store.karma.score, -2);
690
- test.equals(this.connection.results.store.karma.fail[0], 'spammy.TLD');
691
- test.done();
692
- },
693
- }
721
+ assert.equal(this.connection.results.store.karma.score, -2)
722
+ assert.equal(this.connection.results.store.karma.fail[0], 'spammy.TLD')
723
+ done()
724
+ })
725
+ })
726
+
727
+ describe('tls', function () {
728
+ beforeEach(_set_up)
694
729
 
695
- exports.tls = {
696
- setUp : _set_up,
697
- 'unconfigured TLS does nothing': function (test) {
698
- test.expect(1);
699
- this.connection.tls.enabled=true;
700
- const mfrom = new Address('spamy@er7diogt.rrnsale.top');
701
- this.connection.current_line="MAIL FROM:<foo@test.com>";
730
+ it('unconfigured TLS does nothing', function (done) {
731
+ this.connection.tls.enabled=true
732
+ const mfrom = new Address('spamy@er7diogt.rrnsale.top')
733
+ this.connection.current_line="MAIL FROM:<foo@test.com>"
702
734
  this.plugin.hook_mail(() => {
703
- test.equals(this.connection.results.store.karma, undefined);
704
- test.done();
705
- }, this.connection, [mfrom]);
706
- },
707
- 'TLS is scored': function (test) {
708
- test.expect(1);
709
- this.plugin.cfg.tls = { set: 2, unset: -4 };
710
- this.connection.tls.enabled=true;
711
- const mfrom = new Address('spamy@er7diogt.rrnsale.top');
712
- this.connection.current_line="MAIL FROM:<foo@test.com>";
735
+ assert.equal(this.connection.results.store.karma, undefined)
736
+ done()
737
+ }, this.connection, [mfrom])
738
+ })
739
+
740
+ it('TLS is scored', function (done) {
741
+ this.plugin.cfg.tls = { set: 2, unset: -4 }
742
+ this.connection.tls.enabled=true
743
+ const mfrom = new Address('spamy@er7diogt.rrnsale.top')
744
+ this.connection.current_line="MAIL FROM:<foo@test.com>"
713
745
  this.plugin.hook_mail(() => {
714
746
  // console.log(this.connection.results.store);
715
- test.equals(this.connection.results.store.karma.score, 2);
716
- test.done();
717
- }, this.connection, [mfrom]);
718
- },
719
- 'no TLS is scored': function (test) {
720
- test.expect(1);
721
- this.plugin.cfg.tls = { set: 2, unset: -4 };
722
- this.connection.tls.enabled=false;
723
- const mfrom = new Address('spamy@er7diogt.rrnsale.top');
724
- this.connection.current_line="MAIL FROM:<foo@test.com>";
747
+ assert.equal(this.connection.results.store.karma.score, 2)
748
+ done()
749
+ }, this.connection, [mfrom])
750
+ })
751
+
752
+ it('no TLS is scored', function (done) {
753
+ this.plugin.cfg.tls = { set: 2, unset: -4 }
754
+ this.connection.tls.enabled=false
755
+ const mfrom = new Address('spamy@er7diogt.rrnsale.top')
756
+ this.connection.current_line="MAIL FROM:<foo@test.com>"
725
757
  this.plugin.hook_mail(() => {
726
758
  // console.log(this.connection.results.store);
727
- test.equals(this.connection.results.store.karma.score, -4);
728
- test.done();
729
- }, this.connection, [mfrom]);
730
- },
731
- }
759
+ assert.equal(this.connection.results.store.karma.score, -4)
760
+ done()
761
+ }, this.connection, [mfrom])
762
+ })
763
+ })
732
764
 
733
- exports.skiping_hooks = {
734
- setUp : _set_up,
735
- 'notes.disable_karma': function (test) {
736
- test.expect(9);
737
- const next = function (rc) {
738
- test.equal(undefined, rc);
739
- };
740
- const last = function (rc) {
741
- test.equal(undefined, rc);
742
- test.done();
743
- };
744
- this.connection.notes.disable_karma = true;
745
-
746
- this.plugin.hook_deny(next, this.connection);
747
- this.plugin.hook_connect(next, this.connection);
748
- this.plugin.hook_ehlo(next, this.connection);
749
- this.plugin.hook_vrfy(next, this.connection);
750
- this.plugin.hook_noop(next, this.connection);
751
- this.plugin.hook_data(next, this.connection);
752
- this.plugin.hook_queue(next, this.connection);
753
- this.plugin.hook_reset_transaction(next, this.connection);
754
- this.plugin.hook_unrecognized_command(last, this.connection);
755
- },
756
- 'private skip': function (test) {
757
- test.expect(9);
758
- const next = function (rc) {
759
- test.equal(undefined, rc);
760
- };
761
- const last = function (rc) {
762
- test.equal(undefined, rc);
763
- test.done();
764
- };
765
- this.connection.remote.is_private = true;
766
-
767
- this.plugin.hook_deny(next, this.connection);
768
- this.plugin.hook_connect(next, this.connection);
769
- this.plugin.hook_ehlo(next, this.connection);
770
- this.plugin.hook_vrfy(next, this.connection);
771
- this.plugin.hook_noop(next, this.connection);
772
- this.plugin.hook_data(next, this.connection);
773
- this.plugin.hook_queue(next, this.connection);
774
- this.plugin.hook_reset_transaction(next, this.connection);
775
- this.plugin.hook_unrecognized_command(last, this.connection);
776
- },
777
- };
765
+ describe('skiping_hooks', function () {
766
+ beforeEach(_set_up)
767
+
768
+ it('notes.disable_karma', function (done) {
769
+ function next (rc) {
770
+ assert.equal(undefined, rc)
771
+ }
772
+ function last (rc) {
773
+ assert.equal(undefined, rc)
774
+ done()
775
+ }
776
+ this.connection.notes.disable_karma = true
777
+
778
+ this.plugin.hook_deny(next, this.connection)
779
+ this.plugin.hook_connect(next, this.connection)
780
+ this.plugin.hook_ehlo(next, this.connection)
781
+ this.plugin.hook_vrfy(next, this.connection)
782
+ this.plugin.hook_noop(next, this.connection)
783
+ this.plugin.hook_data(next, this.connection)
784
+ this.plugin.hook_queue(next, this.connection)
785
+ this.plugin.hook_reset_transaction(next, this.connection)
786
+ this.plugin.hook_unrecognized_command(last, this.connection)
787
+ })
788
+
789
+ it('private skip', function (done) {
790
+ function next (rc) {
791
+ assert.equal(undefined, rc)
792
+ }
793
+ function last (rc) {
794
+ assert.equal(undefined, rc)
795
+ done()
796
+ }
797
+ this.connection.remote.is_private = true
798
+
799
+ this.plugin.hook_deny(next, this.connection)
800
+ this.plugin.hook_connect(next, this.connection)
801
+ this.plugin.hook_ehlo(next, this.connection)
802
+ this.plugin.hook_vrfy(next, this.connection)
803
+ this.plugin.hook_noop(next, this.connection)
804
+ this.plugin.hook_data(next, this.connection)
805
+ this.plugin.hook_queue(next, this.connection)
806
+ this.plugin.hook_reset_transaction(next, this.connection)
807
+ this.plugin.hook_unrecognized_command(last, this.connection)
808
+ })
809
+ })