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/.codeclimate.yml +16 -1
- package/.eslintrc.yaml +3 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +29 -0
- package/.github/ISSUE_TEMPLATE/custom.md +10 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/.github/workflows/ci.yml +48 -0
- package/.github/workflows/publish.yml +29 -0
- package/Changes.md +26 -0
- package/README.md +3 -10
- package/config/karma.ini +1 -1
- package/index.js +456 -517
- package/package.json +8 -8
- package/test/karma.js +680 -648
- package/.travis.yml +0 -21
- package/appveyor.yml +0 -20
- package/run_tests +0 -33
package/test/karma.js
CHANGED
|
@@ -1,777 +1,809 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
this.plugin
|
|
14
|
-
|
|
15
|
-
this.plugin.
|
|
16
|
-
|
|
17
|
-
this.
|
|
18
|
-
|
|
19
|
-
this.connection
|
|
20
|
-
this.connection.transaction
|
|
21
|
-
|
|
22
|
-
done()
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
this.plugin.hook_deny(next, this.connection, ['','','',''])
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
this.plugin.hook_deny(next, this.connection, ['','','karma',''])
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
this.plugin.deny_exclude_plugins = { access: true }
|
|
121
|
-
this.plugin.hook_deny(next, this.connection, ['','','access',''])
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
127
|
-
|
|
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
|
-
|
|
134
|
-
|
|
135
|
+
['','','','','','rcpt_to'])
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it('pi_hook=queue', function (done) {
|
|
135
139
|
const next = function (rc) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
this.plugin.deny_exclude_hooks = { queue: true }
|
|
140
|
-
this.plugin.hook_deny(next, this.connection, ['','','','','','queue'])
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
this.plugin.hook_deny(next, this.connection, [constants.DENYSOFT,'','','','',''])
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
this.connection.relaying=false
|
|
157
|
-
const r = this.plugin.get_award_location(this.connection, 'relaying')
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
this.connection.relaying=true
|
|
164
|
-
const r = this.plugin.get_award_location(this.connection, 'relaying')
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
const r = this.plugin.get_award_location(this.connection, 'notes.undef')
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
this.connection.notes = { tarpit: 2 }
|
|
177
|
-
const r = this.plugin.get_award_location(this.connection, 'notes.tarpit')
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
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
|
-
|
|
200
|
-
this.
|
|
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
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
|
|
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
|
-
|
|
209
|
-
this.connection.results.
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
'geoip.distance'
|
|
227
|
-
|
|
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
|
-
|
|
233
|
+
))
|
|
234
|
+
assert.equal(4000, this.plugin.get_award_condition(
|
|
232
235
|
'results.geoip.distance@uniq', '-1 if gt 4000'
|
|
233
|
-
))
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
-
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const r = this.plugin.check_awards(this.connection)
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
this.connection.results.add('karma', { todo: { } })
|
|
256
|
-
const r = this.plugin.check_awards(this.connection)
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
|
|
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
|
-
|
|
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
|
-
|
|
281
|
+
assert.equal('geoip.distance', this.connection.results.get('karma').fail[0])
|
|
282
|
+
|
|
283
|
+
done()
|
|
284
|
+
})
|
|
279
285
|
|
|
280
|
-
|
|
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
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
|
|
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
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
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
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
}
|
|
316
|
-
this.plugin.apply_tarpit(this.connection, 'connect', 0, next)
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
|
|
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
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
}
|
|
325
|
-
this.plugin.cfg.tarpit = { max: 1, delay: 0 }
|
|
326
|
-
this.plugin.apply_tarpit(this.connection, 'connect', 0, next)
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
|
|
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
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
335
|
-
this.plugin.cfg.tarpit = { max: 1, delay: 0 }
|
|
336
|
-
this.plugin.apply_tarpit(this.connection, 'connect', 1, next)
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
|
|
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
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
}
|
|
347
|
-
this.plugin.cfg.tarpit = { max: 1, delay: 0 }
|
|
348
|
-
this.plugin.apply_tarpit(this.connection, 'connect', -1, next)
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
|
|
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
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
}
|
|
359
|
-
this.plugin.cfg.tarpit = { max: 1, delay: 0 }
|
|
360
|
-
this.plugin.apply_tarpit(this.connection, 'connect', -2, next)
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
|
|
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
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
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
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
this.plugin.should_we_deny(next, this.connection, 'connect')
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
|
|
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
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
}
|
|
395
|
-
this.connection.results.add(this.plugin, { test: 'blah' })
|
|
396
|
-
this.plugin.should_we_deny(next, this.connection, 'connect')
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
|
|
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
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
}
|
|
405
|
-
this.connection.results.add(this.plugin, { score: 'blah' })
|
|
406
|
-
this.plugin.should_we_deny(next, this.connection, 'connect')
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
|
|
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
|
-
|
|
412
|
-
|
|
413
|
-
|
|
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
|
-
|
|
420
|
-
|
|
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
|
-
|
|
423
|
-
|
|
424
|
-
|
|
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
|
-
|
|
432
|
-
|
|
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
|
-
|
|
435
|
-
|
|
436
|
-
|
|
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
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
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
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
|
|
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
|
-
|
|
468
|
-
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
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
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
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
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
|
|
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
|
-
|
|
514
|
-
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
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
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
|
|
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
|
-
|
|
543
|
-
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
|
|
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
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
'eq pattern is scored'
|
|
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
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
|
|
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
|
-
|
|
585
|
-
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
|
|
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
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
|
|
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
|
-
|
|
610
|
-
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
|
|
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
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
|
|
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
|
-
|
|
635
|
-
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
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
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
|
|
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
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
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
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
|
|
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
|
-
|
|
690
|
-
|
|
691
|
-
|
|
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
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
test.
|
|
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
|
-
|
|
704
|
-
|
|
705
|
-
}, this.connection, [mfrom])
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
|
|
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
|
-
|
|
716
|
-
|
|
717
|
-
}, this.connection, [mfrom])
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
|
|
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
|
-
|
|
728
|
-
|
|
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
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
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
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
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
|
+
})
|