haraka-plugin-karma 1.0.13 → 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/test/karma.js CHANGED
@@ -1,25 +1,25 @@
1
- 'use strict';
1
+ 'use strict'
2
2
 
3
3
  const assert = require('assert')
4
4
 
5
- const Address = require('address-rfc2821').Address;
6
- const fixtures = require('haraka-test-fixtures');
7
- const constants = require('haraka-constants');
5
+ const Address = require('address-rfc2821').Address
6
+ const fixtures = require('haraka-test-fixtures')
7
+ const constants = require('haraka-constants')
8
8
 
9
- const stub = fixtures.stub.stub;
9
+ const stub = fixtures.stub.stub
10
10
 
11
11
  function _set_up (done) {
12
12
 
13
- this.plugin = new fixtures.plugin('karma');
13
+ this.plugin = new fixtures.plugin('karma')
14
14
 
15
- this.plugin.cfg = { main: {} };
16
- this.plugin.deny_hooks = {'connect': true};
17
- this.plugin.tarpit_hooks = ['connect'];
15
+ this.plugin.cfg = { main: {} }
16
+ this.plugin.deny_hooks = {'connect': true}
17
+ this.plugin.tarpit_hooks = ['connect']
18
18
 
19
- this.connection = fixtures.connection.createConnection({}, { notes: {} });
20
- this.connection.transaction = fixtures.transaction.createTransaction();
19
+ this.connection = fixtures.connection.createConnection({}, { notes: {} })
20
+ this.connection.transaction = fixtures.transaction.createTransaction()
21
21
 
22
- done();
22
+ done()
23
23
  }
24
24
 
25
25
 
@@ -42,40 +42,40 @@ describe('results_init', function () {
42
42
  beforeEach(_set_up)
43
43
 
44
44
  it('init, pre', function (done) {
45
- const r = this.connection.results.get('karma');
46
- assert.equal(undefined, r);
45
+ const r = this.connection.results.get('karma')
46
+ assert.equal(undefined, r)
47
47
  done()
48
48
  })
49
49
 
50
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);
51
+ this.plugin.results_init(stub, this.connection)
52
+ const r = this.connection.results.get('karma')
53
+ assert.ok(r)
54
54
  done()
55
55
  })
56
56
 
57
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);
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
63
  done()
64
64
  })
65
65
 
66
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);
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
71
  done()
72
72
  })
73
73
 
74
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);
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
79
  done()
80
80
  })
81
81
  })
@@ -84,15 +84,15 @@ describe('assemble_note_obj', function () {
84
84
  beforeEach(_set_up)
85
85
 
86
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);
87
+ const obj = this.plugin.assemble_note_obj(this.connection, 'notes.auth_fails')
88
+ assert.equal(undefined, obj)
89
89
  done()
90
90
  })
91
91
 
92
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);
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
96
  done()
97
97
  })
98
98
  })
@@ -102,54 +102,54 @@ describe('hook_deny', function () {
102
102
 
103
103
  it('no params', function (done) {
104
104
  const next = function (rc) {
105
- assert.equal(constants.OK, rc, rc);
105
+ assert.equal(constants.OK, rc, rc)
106
106
  done()
107
- };
108
- this.plugin.hook_deny(next, this.connection, ['','','','']);
107
+ }
108
+ this.plugin.hook_deny(next, this.connection, ['','','',''])
109
109
  })
110
110
 
111
111
  it('pi_name=karma', function (done) {
112
112
  const next = function (rc) {
113
- assert.equal(undefined, rc);
113
+ assert.equal(undefined, rc)
114
114
  done()
115
- };
116
- this.plugin.hook_deny(next, this.connection, ['','','karma','']);
115
+ }
116
+ this.plugin.hook_deny(next, this.connection, ['','','karma',''])
117
117
  })
118
118
 
119
119
  it('pi_name=access', function (done) {
120
120
  const next = function (rc) {
121
- assert.equal(undefined, rc);
121
+ assert.equal(undefined, rc)
122
122
  done()
123
- };
124
- this.plugin.deny_exclude_plugins = { access: true };
125
- this.plugin.hook_deny(next, this.connection, ['','','access','']);
123
+ }
124
+ this.plugin.deny_exclude_plugins = { access: true }
125
+ this.plugin.hook_deny(next, this.connection, ['','','access',''])
126
126
  })
127
127
 
128
128
  it('pi_hook=rcpt_to', function (done) {
129
129
  const next = function (rc) {
130
- assert.equal(undefined, rc);
130
+ assert.equal(undefined, rc)
131
131
  done()
132
- };
133
- this.plugin.deny_exclude_hooks = { rcpt_to: true };
132
+ }
133
+ this.plugin.deny_exclude_hooks = { rcpt_to: true }
134
134
  this.plugin.hook_deny(next, this.connection,
135
- ['','','','','','rcpt_to']);
135
+ ['','','','','','rcpt_to'])
136
136
  })
137
137
 
138
138
  it('pi_hook=queue', function (done) {
139
139
  const next = function (rc) {
140
- assert.equal(undefined, rc);
140
+ assert.equal(undefined, rc)
141
141
  done()
142
- };
143
- this.plugin.deny_exclude_hooks = { queue: true };
144
- this.plugin.hook_deny(next, this.connection, ['','','','','','queue']);
142
+ }
143
+ this.plugin.deny_exclude_hooks = { queue: true }
144
+ this.plugin.hook_deny(next, this.connection, ['','','','','','queue'])
145
145
  })
146
146
 
147
147
  it('denysoft', function (done) {
148
148
  const next = function (rc) {
149
- assert.equal(constants.OK, rc);
149
+ assert.equal(constants.OK, rc)
150
150
  done()
151
- };
152
- this.plugin.hook_deny(next, this.connection, [constants.DENYSOFT,'','','','','']);
151
+ }
152
+ this.plugin.hook_deny(next, this.connection, [constants.DENYSOFT,'','','','',''])
153
153
  })
154
154
  })
155
155
 
@@ -157,70 +157,70 @@ describe('get_award_location', function () {
157
157
  beforeEach(_set_up)
158
158
 
159
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);
160
+ this.connection.relaying=false
161
+ const r = this.plugin.get_award_location(this.connection, 'relaying')
162
+ assert.equal(false, r)
163
163
  done()
164
164
  })
165
165
 
166
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);
167
+ this.connection.relaying=true
168
+ const r = this.plugin.get_award_location(this.connection, 'relaying')
169
+ assert.equal(true, r)
170
170
  done()
171
171
  })
172
172
 
173
173
  it('notes.undef=2', function (done) {
174
- const r = this.plugin.get_award_location(this.connection, 'notes.undef');
175
- assert.equal(undefined, r);
174
+ const r = this.plugin.get_award_location(this.connection, 'notes.undef')
175
+ assert.equal(undefined, r)
176
176
  done()
177
177
  })
178
178
 
179
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);
180
+ this.connection.notes = { tarpit: 2 }
181
+ const r = this.plugin.get_award_location(this.connection, 'notes.tarpit')
182
+ assert.equal(2, r)
183
183
  done()
184
184
  })
185
185
 
186
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');
187
+ this.connection.results.add('geoip', { country: 'US' })
188
+ const r = this.plugin.get_award_location(this.connection, 'results.geoip')
189
189
  // console.log(r);
190
- assert.equal('US', r.country);
190
+ assert.equal('US', r.country)
191
191
  done()
192
192
  })
193
193
 
194
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');
195
+ this.connection.results.add('karma', { score: -1 })
196
+ const r = this.plugin.get_award_location(this.connection, 'results.karma')
197
197
  // console.log(r);
198
- assert.equal(-1, r.score);
198
+ assert.equal(-1, r.score)
199
199
  done()
200
200
  })
201
201
 
202
202
  it('results.karma, txn', function (done) {
203
203
  // results should be found in conn or txn
204
- this.connection.transaction.results.add('karma', { score: -1 });
205
- 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')
206
206
  // console.log(r);
207
- assert.equal(-1, r.score);
207
+ assert.equal(-1, r.score)
208
208
  done()
209
209
  })
210
210
 
211
211
  it('txn.results.karma', function (done) {
212
212
  // these results shouldn't be found, b/c txn specified
213
- this.connection.results.add('karma', { score: -1 });
214
- 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')
215
215
  // console.log(r);
216
- assert.equal(undefined, r);
216
+ assert.equal(undefined, r)
217
217
  done()
218
218
  })
219
219
 
220
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]);
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
224
  done()
225
225
  })
226
226
  })
@@ -230,17 +230,17 @@ describe('get_award_condition', function () {
230
230
  it('geoip.distance', function (done) {
231
231
  assert.equal(4000, this.plugin.get_award_condition(
232
232
  'results.geoip.distance@4000', '-1 if gt'
233
- ));
233
+ ))
234
234
  assert.equal(4000, this.plugin.get_award_condition(
235
235
  'results.geoip.distance@uniq', '-1 if gt 4000'
236
- ));
236
+ ))
237
237
  done()
238
238
  })
239
239
 
240
240
  it('auth/auth_base', function (done) {
241
241
  assert.equal('plain', this.plugin.get_award_condition(
242
242
  'results.auth/auth_base.fail@plain', '-1 if in'
243
- ));
243
+ ))
244
244
  done()
245
245
  })
246
246
  })
@@ -249,15 +249,15 @@ describe('check_awards', function () {
249
249
  beforeEach(_set_up)
250
250
 
251
251
  it('no results', function (done) {
252
- const r = this.plugin.check_awards(this.connection);
253
- assert.equal(undefined, r);
252
+ const r = this.plugin.check_awards(this.connection)
253
+ assert.equal(undefined, r)
254
254
  done()
255
255
  })
256
256
 
257
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);
258
+ this.connection.results.add('karma', { todo: { } })
259
+ const r = this.plugin.check_awards(this.connection)
260
+ assert.equal(undefined, r)
261
261
  done()
262
262
  })
263
263
 
@@ -266,19 +266,19 @@ describe('check_awards', function () {
266
266
  // populate the karma result with a todo item
267
267
  this.connection.results.add('karma', {
268
268
  todo: { 'results.geoip.distance@4000': '-1 if gt 4000' }
269
- });
269
+ })
270
270
  // test a non-matching criteria
271
- this.connection.results.add('geoip', { distance: 4000 });
271
+ this.connection.results.add('geoip', { distance: 4000 })
272
272
  // check awards
273
- this.plugin.check_awards(this.connection);
274
- assert.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])
275
275
 
276
276
  // test a matching criteria
277
- this.connection.results.add('geoip', { distance: 4001 });
277
+ this.connection.results.add('geoip', { distance: 4001 })
278
278
  // check awards
279
- this.plugin.check_awards(this.connection);
279
+ this.plugin.check_awards(this.connection)
280
280
  // test that the award was applied
281
- assert.equal('geoip.distance', this.connection.results.get('karma').fail[0]);
281
+ assert.equal('geoip.distance', this.connection.results.get('karma').fail[0])
282
282
 
283
283
  done()
284
284
  })
@@ -286,23 +286,23 @@ describe('check_awards', function () {
286
286
  it('auth failure', function (done) {
287
287
  this.connection.results.add('karma', {
288
288
  todo: { 'results.auth/auth_base.fail@PLAIN': '-1 if in' }
289
- });
289
+ })
290
290
  this.connection.results.add('auth/auth_base',
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]);
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
295
  done()
296
296
  })
297
297
 
298
298
  it('valid recipient', function (done) {
299
299
  this.connection.results.add('karma', {
300
300
  todo: { 'results.rcpt_to.qmd.pass@exist': '1 if in' }
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]);
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
306
  done()
307
307
  })
308
308
  })
@@ -312,68 +312,68 @@ describe('apply_tarpit', function () {
312
312
 
313
313
  it('tarpit=false', function (done) {
314
314
  const next = function (rc, msg) {
315
- assert.equal(undefined, rc);
316
- assert.equal(undefined, msg);
315
+ assert.equal(undefined, rc)
316
+ assert.equal(undefined, msg)
317
317
  done()
318
- };
319
- this.plugin.apply_tarpit(this.connection, 'connect', 0, next);
318
+ }
319
+ this.plugin.apply_tarpit(this.connection, 'connect', 0, next)
320
320
  })
321
321
 
322
322
  it('tarpit=true, score=0', function (done) {
323
323
  const next = function (rc, msg) {
324
- assert.equal(undefined, rc);
325
- assert.equal(undefined, msg);
324
+ assert.equal(undefined, rc)
325
+ assert.equal(undefined, msg)
326
326
  done()
327
- };
328
- this.plugin.cfg.tarpit = { max: 1, delay: 0 };
329
- this.plugin.apply_tarpit(this.connection, 'connect', 0, next);
327
+ }
328
+ this.plugin.cfg.tarpit = { max: 1, delay: 0 }
329
+ this.plugin.apply_tarpit(this.connection, 'connect', 0, next)
330
330
  })
331
331
 
332
332
  it('tarpit=true, score=1', function (done) {
333
333
  const next = function (rc, msg) {
334
- assert.equal(undefined, rc);
335
- assert.equal(undefined, msg);
334
+ assert.equal(undefined, rc)
335
+ assert.equal(undefined, msg)
336
336
  done()
337
- };
338
- this.plugin.cfg.tarpit = { max: 1, delay: 0 };
339
- this.plugin.apply_tarpit(this.connection, 'connect', 1, next);
337
+ }
338
+ this.plugin.cfg.tarpit = { max: 1, delay: 0 }
339
+ this.plugin.apply_tarpit(this.connection, 'connect', 1, next)
340
340
  })
341
341
 
342
342
  it('tarpit=true, score=-1', function (done) {
343
- const before = Date.now();
343
+ const before = Date.now()
344
344
  const next = function (rc, msg) {
345
- assert.ok(Date.now() >= before + 1);
346
- assert.equal(undefined, rc);
347
- assert.equal(undefined, msg);
345
+ assert.ok(Date.now() >= before + 1)
346
+ assert.equal(undefined, rc)
347
+ assert.equal(undefined, msg)
348
348
  done()
349
- };
350
- this.plugin.cfg.tarpit = { max: 1, delay: 0 };
351
- this.plugin.apply_tarpit(this.connection, 'connect', -1, next);
349
+ }
350
+ this.plugin.cfg.tarpit = { max: 1, delay: 0 }
351
+ this.plugin.apply_tarpit(this.connection, 'connect', -1, next)
352
352
  })
353
353
 
354
354
  it('tarpit=true, score=-2, max=1', function (done) {
355
- const before = Date.now();
355
+ const before = Date.now()
356
356
  const next = function (rc, msg) {
357
- assert.ok(Date.now() >= before + 1);
358
- assert.equal(undefined, rc);
359
- assert.equal(undefined, msg);
357
+ assert.ok(Date.now() >= before + 1)
358
+ assert.equal(undefined, rc)
359
+ assert.equal(undefined, msg)
360
360
  done()
361
- };
362
- this.plugin.cfg.tarpit = { max: 1, delay: 0 };
363
- this.plugin.apply_tarpit(this.connection, 'connect', -2, next);
361
+ }
362
+ this.plugin.cfg.tarpit = { max: 1, delay: 0 }
363
+ this.plugin.apply_tarpit(this.connection, 'connect', -2, next)
364
364
  })
365
365
 
366
366
  it('tarpit=true, score=connect, max=1', function (done) {
367
- const before = Date.now();
367
+ const before = Date.now()
368
368
  const next = function (rc, msg) {
369
- assert.ok(Date.now() >= before + 1);
370
- assert.equal(undefined, rc);
371
- assert.equal(undefined, msg);
369
+ assert.ok(Date.now() >= before + 1)
370
+ assert.equal(undefined, rc)
371
+ assert.equal(undefined, msg)
372
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);
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
377
  })
378
378
  })
379
379
 
@@ -382,66 +382,66 @@ describe('should_we_deny', function () {
382
382
 
383
383
  it('no results', function (done) {
384
384
  const next = function (rc, msg) {
385
- assert.equal(undefined, rc);
386
- assert.equal(undefined, msg);
385
+ assert.equal(undefined, rc)
386
+ assert.equal(undefined, msg)
387
387
  done()
388
- };
389
- this.plugin.should_we_deny(next, this.connection, 'connect');
388
+ }
389
+ this.plugin.should_we_deny(next, this.connection, 'connect')
390
390
  })
391
391
 
392
392
  it('no score', function (done) {
393
393
  const next = function (rc, msg) {
394
- assert.equal(undefined, rc);
395
- assert.equal(undefined, msg);
394
+ assert.equal(undefined, rc)
395
+ assert.equal(undefined, msg)
396
396
  done()
397
- };
398
- this.connection.results.add(this.plugin, { test: 'blah' });
399
- this.plugin.should_we_deny(next, this.connection, 'connect');
397
+ }
398
+ this.connection.results.add(this.plugin, { test: 'blah' })
399
+ this.plugin.should_we_deny(next, this.connection, 'connect')
400
400
  })
401
401
 
402
402
  it('invalid score', function (done) {
403
403
  const next = function (rc, msg) {
404
- assert.equal(undefined, rc);
405
- assert.equal(undefined, msg);
404
+ assert.equal(undefined, rc)
405
+ assert.equal(undefined, msg)
406
406
  done()
407
- };
408
- this.connection.results.add(this.plugin, { score: 'blah' });
409
- this.plugin.should_we_deny(next, this.connection, 'connect');
407
+ }
408
+ this.connection.results.add(this.plugin, { score: 'blah' })
409
+ this.plugin.should_we_deny(next, this.connection, 'connect')
410
410
  })
411
411
 
412
412
  it('valid score, okay', function (done) {
413
413
  const next = function (rc, msg) {
414
- assert.equal(undefined, rc);
415
- assert.equal(undefined, msg);
414
+ assert.equal(undefined, rc)
415
+ assert.equal(undefined, msg)
416
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');
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
421
  })
422
422
 
423
423
  it('valid score, -6, deny_hook', function (done) {
424
424
  const next = function (rc, msg) {
425
- assert.equal(constants.DENY, rc);
426
- assert.ok(msg);
425
+ assert.equal(constants.DENY, rc)
426
+ assert.ok(msg)
427
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');
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
433
  })
434
434
 
435
435
  it('valid score, -6, pass_hook', function (done) {
436
436
  const next = function (rc, msg) {
437
- assert.equal(undefined, rc);
438
- assert.equal(undefined, msg);
437
+ assert.equal(undefined, rc)
438
+ assert.equal(undefined, msg)
439
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');
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
445
  })
446
446
  })
447
447
 
@@ -453,10 +453,10 @@ describe('check_result_equal', function () {
453
453
  id : 1, award : 2,
454
454
  operator : 'equals', value : 'clean',
455
455
  reason : 'testing', resolution : 'never',
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);
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
460
  done()
461
461
  })
462
462
 
@@ -465,9 +465,9 @@ describe('check_result_equal', function () {
465
465
  id : 1, award : 2,
466
466
  operator : 'equals', value : 'dirty',
467
467
  reason : 'testing', resolution : 'never',
468
- };
469
- this.plugin.check_result_equal(['clean'], award, this.connection);
470
- assert.equal(this.connection.results.store.karma, undefined);
468
+ }
469
+ this.plugin.check_result_equal(['clean'], award, this.connection)
470
+ assert.equal(this.connection.results.store.karma, undefined)
471
471
  done()
472
472
  })
473
473
  })
@@ -480,11 +480,11 @@ describe('check_result_gt', function () {
480
480
  id : 5, award : 3,
481
481
  operator : 'gt', value : 3,
482
482
  reason : 'testing', resolution : 'never',
483
- };
484
- this.plugin.check_result_gt([4], award, this.connection);
483
+ }
484
+ this.plugin.check_result_gt([4], award, this.connection)
485
485
  // console.log(this.connection.results.store);
486
- assert.equal(this.connection.results.store.karma.score, 3);
487
- assert.equal(this.connection.results.store.karma.awards[0], 5);
486
+ assert.equal(this.connection.results.store.karma.score, 3)
487
+ assert.equal(this.connection.results.store.karma.awards[0], 5)
488
488
  done()
489
489
  })
490
490
  })
@@ -497,11 +497,11 @@ describe('check_result_lt', function () {
497
497
  id : 2, award : 3,
498
498
  operator : 'lt', value : 5,
499
499
  reason : 'testing', resolution : 'never',
500
- };
501
- this.plugin.check_result_lt([4], award, this.connection);
500
+ }
501
+ this.plugin.check_result_lt([4], award, this.connection)
502
502
  // console.log(this.connection.results.store);
503
- assert.equal(this.connection.results.store.karma.score, 3);
504
- assert.equal(this.connection.results.store.karma.awards[0], 2);
503
+ assert.equal(this.connection.results.store.karma.score, 3)
504
+ assert.equal(this.connection.results.store.karma.awards[0], 2)
505
505
  done()
506
506
  })
507
507
 
@@ -510,10 +510,10 @@ describe('check_result_lt', function () {
510
510
  id : 3, award : 3,
511
511
  operator : 'lt', value : 3,
512
512
  reason : 'testing', resolution : 'never',
513
- };
514
- this.plugin.check_result_lt([4], award, this.connection);
513
+ }
514
+ this.plugin.check_result_lt([4], award, this.connection)
515
515
  // console.log(this.connection.results.store);
516
- assert.equal(this.connection.results.store.karma, undefined);
516
+ assert.equal(this.connection.results.store.karma, undefined)
517
517
  done()
518
518
  })
519
519
  })
@@ -526,11 +526,11 @@ describe('check_result_match', function () {
526
526
  id : 1, award : 2,
527
527
  operator : 'match', value : 'phish',
528
528
  reason : 'testing', resolution : 'never',
529
- };
530
- this.plugin.check_result_match(['isphishing'], award, this.connection);
529
+ }
530
+ this.plugin.check_result_match(['isphishing'], award, this.connection)
531
531
  // console.log(this.connection.results.store);
532
- assert.equal(this.connection.results.store.karma.score, 2);
533
- assert.equal(this.connection.results.store.karma.awards[0], 1);
532
+ assert.equal(this.connection.results.store.karma.score, 2)
533
+ assert.equal(this.connection.results.store.karma.awards[0], 1)
534
534
  done()
535
535
  })
536
536
 
@@ -539,10 +539,10 @@ describe('check_result_match', function () {
539
539
  id : 1, award : 2,
540
540
  operator : 'match', value : 'dirty',
541
541
  reason : 'testing', resolution : 'never',
542
- };
543
- this.plugin.check_result_match(['clean'], award, this.connection);
542
+ }
543
+ this.plugin.check_result_match(['clean'], award, this.connection)
544
544
  // console.log(this.connection.results.store);
545
- assert.equal(this.connection.results.store.karma, undefined);
545
+ assert.equal(this.connection.results.store.karma, undefined)
546
546
  done()
547
547
  })
548
548
 
@@ -551,11 +551,11 @@ describe('check_result_match', function () {
551
551
  id : 89, award : 2,
552
552
  operator : 'match', value : 'google.com',
553
553
  reason : 'testing', resolution : 'never',
554
- };
555
- 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)
556
556
  // console.log(this.connection.results.store);
557
- assert.equal(this.connection.results.store.karma.score, 2);
558
- assert.equal(this.connection.results.store.karma.awards[0], 89);
557
+ assert.equal(this.connection.results.store.karma.score, 2)
558
+ assert.equal(this.connection.results.store.karma.awards[0], 89)
559
559
  done()
560
560
  })
561
561
  })
@@ -567,11 +567,11 @@ describe('check_result_length', function () {
567
567
  id : 1, award : 2,
568
568
  operator : 'length', value : 'eq 3',
569
569
  reason : 'testing', resolution : 'hah',
570
- };
571
- this.plugin.check_result_length(['3'], award, this.connection);
570
+ }
571
+ this.plugin.check_result_length(['3'], award, this.connection)
572
572
  // console.log(this.connection.results.store);
573
- assert.equal(this.connection.results.store.karma.score, 2);
574
- assert.equal(this.connection.results.store.karma.awards[0], 1);
573
+ assert.equal(this.connection.results.store.karma.score, 2)
574
+ assert.equal(this.connection.results.store.karma.awards[0], 1)
575
575
  done()
576
576
  })
577
577
 
@@ -580,10 +580,10 @@ describe('check_result_length', function () {
580
580
  id : 1, award : 2,
581
581
  operator : 'length', value : 'eq 3',
582
582
  reason : 'testing', resolution : 'hah',
583
- };
584
- this.plugin.check_result_length(['4'], award, this.connection);
583
+ }
584
+ this.plugin.check_result_length(['4'], award, this.connection)
585
585
  // console.log(this.connection.results.store.karma);
586
- assert.deepEqual(this.connection.results.store.karma, undefined);
586
+ assert.deepEqual(this.connection.results.store.karma, undefined)
587
587
  done()
588
588
  })
589
589
 
@@ -592,11 +592,11 @@ describe('check_result_length', function () {
592
592
  id : 1, award : 2,
593
593
  operator : 'length', value : 'gt 3',
594
594
  reason : 'testing', resolution : 'hah',
595
- };
596
- this.plugin.check_result_length(['5'], award, this.connection);
595
+ }
596
+ this.plugin.check_result_length(['5'], award, this.connection)
597
597
  // console.log(this.connection.results.store);
598
- assert.equal(this.connection.results.store.karma.score, 2);
599
- assert.equal(this.connection.results.store.karma.awards[0], 1);
598
+ assert.equal(this.connection.results.store.karma.score, 2)
599
+ assert.equal(this.connection.results.store.karma.awards[0], 1)
600
600
  done()
601
601
  })
602
602
 
@@ -605,10 +605,10 @@ describe('check_result_length', function () {
605
605
  id : 1, award : 2,
606
606
  operator : 'length', value : 'gt 3',
607
607
  reason : 'testing', resolution : 'hah',
608
- };
609
- this.plugin.check_result_length(['3'], award, this.connection);
608
+ }
609
+ this.plugin.check_result_length(['3'], award, this.connection)
610
610
  // console.log(this.connection.results.store.karma);
611
- assert.deepEqual(this.connection.results.store.karma, undefined);
611
+ assert.deepEqual(this.connection.results.store.karma, undefined)
612
612
  done()
613
613
  })
614
614
 
@@ -617,11 +617,11 @@ describe('check_result_length', function () {
617
617
  id : 1, award : 2,
618
618
  operator : 'length', value : 'lt 3',
619
619
  reason : 'testing', resolution : 'hah',
620
- };
621
- this.plugin.check_result_length(['2'], award, this.connection);
620
+ }
621
+ this.plugin.check_result_length(['2'], award, this.connection)
622
622
  // console.log(this.connection.results.store);
623
- assert.equal(this.connection.results.store.karma.score, 2);
624
- assert.equal(this.connection.results.store.karma.awards[0], 1);
623
+ assert.equal(this.connection.results.store.karma.score, 2)
624
+ assert.equal(this.connection.results.store.karma.awards[0], 1)
625
625
  done()
626
626
  })
627
627
 
@@ -630,10 +630,10 @@ describe('check_result_length', function () {
630
630
  id : 1, award : 2,
631
631
  operator : 'length', value : 'lt 3',
632
632
  reason : 'testing', resolution : 'hah',
633
- };
634
- this.plugin.check_result_length(['3'], award, this.connection);
633
+ }
634
+ this.plugin.check_result_length(['3'], award, this.connection)
635
635
  // console.log(this.connection.results.store.karma);
636
- assert.deepEqual(this.connection.results.store.karma, undefined);
636
+ assert.deepEqual(this.connection.results.store.karma, undefined)
637
637
  done()
638
638
  })
639
639
  })
@@ -646,11 +646,11 @@ describe('check_result_exists', function () {
646
646
  id : 1, award : 2,
647
647
  operator : 'exists', value : 'any',
648
648
  reason : 'testing', resolution : 'high five',
649
- };
650
- this.plugin.check_result_exists(['3'], award, this.connection);
649
+ }
650
+ this.plugin.check_result_exists(['3'], award, this.connection)
651
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);
652
+ assert.equal(this.connection.results.store.karma.score, 2)
653
+ assert.equal(this.connection.results.store.karma.awards[0], 1)
654
654
  done()
655
655
  })
656
656
 
@@ -659,11 +659,11 @@ describe('check_result_exists', function () {
659
659
  id : 1, award : 3,
660
660
  operator : 'exists', value : '',
661
661
  reason : 'testing', resolution : 'misses',
662
- };
663
- this.plugin.check_result_exists([], award, this.connection);
662
+ }
663
+ this.plugin.check_result_exists([], award, this.connection)
664
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);
665
+ assert.equal(this.connection.results.store.karma, undefined)
666
+ assert.equal(this.connection.results.store.karma, undefined)
667
667
  done()
668
668
  })
669
669
  })
@@ -674,28 +674,28 @@ describe('check_result', function () {
674
674
  it('geoip country is scored', function (done) {
675
675
  this.plugin.cfg.result_awards = {
676
676
  1: 'geoip | country | equals | CN | 2',
677
- };
678
- this.plugin.preparse_result_awards();
679
- this.connection.results.add({name: 'geoip'}, {country: 'CN'});
677
+ }
678
+ this.plugin.preparse_result_awards()
679
+ this.connection.results.add({name: 'geoip'}, {country: 'CN'})
680
680
  this.plugin.check_result(this.connection,
681
- '{"plugin":"geoip","result":{"country":"CN"}}');
681
+ '{"plugin":"geoip","result":{"country":"CN"}}')
682
682
  // console.log(this.connection.results.store);
683
- assert.equal(this.connection.results.store.karma.score, 2);
684
- assert.equal(this.connection.results.store.karma.awards[0], 1);
683
+ assert.equal(this.connection.results.store.karma.score, 2)
684
+ assert.equal(this.connection.results.store.karma.awards[0], 1)
685
685
  done()
686
686
  })
687
687
 
688
688
  it('dnsbl listing is scored', function (done) {
689
689
  this.plugin.cfg.result_awards = {
690
690
  2: 'dnsbl | fail | equals | dnsbl.sorbs.net | -5',
691
- };
692
- this.plugin.preparse_result_awards();
693
- 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'})
694
694
  this.plugin.check_result(this.connection,
695
- '{"plugin":"dnsbl","result":{"fail":"dnsbl.sorbs.net"}}');
695
+ '{"plugin":"dnsbl","result":{"fail":"dnsbl.sorbs.net"}}')
696
696
  // console.log(this.connection.results.store);
697
- assert.equal(this.connection.results.store.karma.score, -5);
698
- assert.equal(this.connection.results.store.karma.awards[0], 2);
697
+ assert.equal(this.connection.results.store.karma.score, -5)
698
+ assert.equal(this.connection.results.store.karma.awards[0], 2)
699
699
  done()
700
700
  })
701
701
  })
@@ -704,22 +704,22 @@ describe('check_spammy_tld', function () {
704
704
  beforeEach(_set_up)
705
705
 
706
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);
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)
710
710
  // console.log(this.connection.results.store);
711
- assert.equal(this.connection.results.store.karma.score, -3);
712
- assert.equal(this.connection.results.store.karma.fail[0], 'spammy.TLD');
711
+ assert.equal(this.connection.results.store.karma.score, -3)
712
+ assert.equal(this.connection.results.store.karma.fail[0], 'spammy.TLD')
713
713
  done()
714
714
  })
715
715
 
716
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);
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)
720
720
  // console.log(this.connection.results.store);
721
- assert.equal(this.connection.results.store.karma.score, -2);
722
- assert.equal(this.connection.results.store.karma.fail[0], 'spammy.TLD');
721
+ assert.equal(this.connection.results.store.karma.score, -2)
722
+ assert.equal(this.connection.results.store.karma.fail[0], 'spammy.TLD')
723
723
  done()
724
724
  })
725
725
  })
@@ -728,37 +728,37 @@ describe('tls', function () {
728
728
  beforeEach(_set_up)
729
729
 
730
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>";
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>"
734
734
  this.plugin.hook_mail(() => {
735
- assert.equal(this.connection.results.store.karma, undefined);
735
+ assert.equal(this.connection.results.store.karma, undefined)
736
736
  done()
737
- }, this.connection, [mfrom]);
737
+ }, this.connection, [mfrom])
738
738
  })
739
739
 
740
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>";
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>"
745
745
  this.plugin.hook_mail(() => {
746
746
  // console.log(this.connection.results.store);
747
- assert.equal(this.connection.results.store.karma.score, 2);
747
+ assert.equal(this.connection.results.store.karma.score, 2)
748
748
  done()
749
- }, this.connection, [mfrom]);
749
+ }, this.connection, [mfrom])
750
750
  })
751
751
 
752
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>";
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>"
757
757
  this.plugin.hook_mail(() => {
758
758
  // console.log(this.connection.results.store);
759
- assert.equal(this.connection.results.store.karma.score, -4);
759
+ assert.equal(this.connection.results.store.karma.score, -4)
760
760
  done()
761
- }, this.connection, [mfrom]);
761
+ }, this.connection, [mfrom])
762
762
  })
763
763
  })
764
764
 
@@ -767,43 +767,43 @@ describe('skiping_hooks', function () {
767
767
 
768
768
  it('notes.disable_karma', function (done) {
769
769
  function next (rc) {
770
- assert.equal(undefined, rc);
770
+ assert.equal(undefined, rc)
771
771
  }
772
772
  function last (rc) {
773
- assert.equal(undefined, rc);
773
+ assert.equal(undefined, rc)
774
774
  done()
775
775
  }
776
- this.connection.notes.disable_karma = true;
776
+ this.connection.notes.disable_karma = true
777
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);
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
787
  })
788
788
 
789
789
  it('private skip', function (done) {
790
790
  function next (rc) {
791
- assert.equal(undefined, rc);
791
+ assert.equal(undefined, rc)
792
792
  }
793
793
  function last (rc) {
794
- assert.equal(undefined, rc);
794
+ assert.equal(undefined, rc)
795
795
  done()
796
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);
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
808
  })
809
809
  })