haraka-plugin-karma
Advanced tools
Comparing version 1.0.1 to 1.0.3
{ | ||
"env": { | ||
"node": true, | ||
"mocha": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"installedESLint": true, | ||
"plugins": [ | ||
"haraka" | ||
], | ||
"extends": [ "eslint:recommended", "plugin:haraka/recommended" ], | ||
"root": true, | ||
"rules": { | ||
"comma-dangle": [2, "only-multiline"], | ||
"dot-notation": 2, | ||
"indent": [2, 2, {"SwitchCase": 1}], | ||
"one-var": [2, "never"], | ||
"no-trailing-spaces": [2, { "skipBlankLines": false }], | ||
"keyword-spacing": [2, { | ||
"before": true, | ||
"after": true | ||
}], | ||
"no-delete-var": 2, | ||
"no-empty": ["error", { "allowEmptyCatch": true }], | ||
"no-label-var": 2, | ||
"no-shadow": 2, | ||
"no-unused-vars": [ 1, { "args": "none" }], | ||
"no-console": 0 | ||
} | ||
} |
51
index.js
@@ -26,3 +26,3 @@ 'use strict'; | ||
plugin.load_karma_ini(); | ||
plugin.load_redis_ini(); | ||
plugin.merge_redis_ini(); | ||
@@ -72,4 +72,2 @@ plugin.register_hook('init_master', 'init_redis_plugin'); | ||
} | ||
if (!cfg.redis.host) cfg.redis.host = '127.0.0.1'; | ||
if (!cfg.redis.port) cfg.redis.port = 6379; | ||
}; | ||
@@ -114,3 +112,3 @@ | ||
// ex: karma.result_awards.clamd.fail = { .... } | ||
Object.keys(plugin.cfg.result_awards).forEach(function(anum) { | ||
Object.keys(plugin.cfg.result_awards).forEach(function (anum) { | ||
// plugin, property, operator, value, award, reason, resolution | ||
@@ -169,2 +167,4 @@ var parts = plugin.cfg.result_awards[anum].split(/(?:\s*\|\s*)/); | ||
switch (thisAward.operator) { | ||
case 'eq': | ||
case 'equal': | ||
case 'equals': | ||
@@ -182,2 +182,5 @@ plugin.check_result_equal(thisResArr, thisAward, connection); | ||
break; | ||
case 'length': | ||
plugin.check_result_length(thisResArr, thisAward, connection); | ||
break; | ||
} | ||
@@ -243,3 +246,2 @@ } | ||
/* jshint eqeqeq: false */ | ||
for (var j=0; j < thisResult.length; j++) { | ||
@@ -275,2 +277,33 @@ if (thisAward.value === 'true') { | ||
exports.check_result_length = function (thisResult, thisAward, conn) { | ||
var plugin = this; | ||
for (let j=0; j < thisResult.length; j++) { | ||
// var [operator, qty] = thisAward.value.split(/\s+/); // requires node 6 | ||
var matches = thisAward.value.split(/\s+/); | ||
var operator = matches[0]; | ||
var qty = matches[1]; | ||
switch (operator) { | ||
case 'eq': | ||
case 'equal': | ||
case 'equals': | ||
if (parseInt(thisResult[j], 10) != parseInt(qty, 10)) continue; | ||
break; | ||
case 'gt': | ||
if (parseInt(thisResult[j], 10) <= parseInt(qty, 10)) continue; | ||
break; | ||
case 'lt': | ||
if (parseInt(thisResult[j], 10) >= parseInt(qty, 10)) continue; | ||
break; | ||
default: | ||
conn.results.add(plugin, { err: 'invalid operator:' + operator }); | ||
continue; | ||
} | ||
conn.results.incr(plugin, {score: thisAward.award}); | ||
conn.results.push(plugin, {awards: thisAward.id}); | ||
} | ||
}; | ||
exports.apply_tarpit = function (connection, hook, score, next) { | ||
@@ -470,3 +503,3 @@ var plugin = this; | ||
exports.hook_unrecognized_command = function(next, connection, cmd) { | ||
exports.hook_unrecognized_command = function (next, connection, cmd) { | ||
var plugin = this; | ||
@@ -731,3 +764,3 @@ | ||
var award = parseFloat(bits[0]); | ||
if (!bits[1] || bits[1] !== 'if') { // no if conditions | ||
if (!bits[1] || bits[1] !== 'if') { // no if conditions | ||
if (!note) { continue; } // failed truth test | ||
@@ -781,3 +814,3 @@ if (!wants) { // no wants, truth matches | ||
operator + '" not supported.'); | ||
continue; // not supported! | ||
continue; | ||
} | ||
@@ -855,3 +888,3 @@ break; | ||
exports.assemble_note_obj = function(prefix, key) { | ||
exports.assemble_note_obj = function (prefix, key) { | ||
var note = prefix; | ||
@@ -858,0 +891,0 @@ var parts = key.split('.'); |
{ | ||
"name": "haraka-plugin-karma", | ||
"version": "1.0.1", | ||
"version": "1.0.3", | ||
"description": "Watch live SMTP traffic in a web interface", | ||
@@ -25,8 +25,9 @@ "main": "index.js", | ||
"dependencies": { | ||
"address-rfc2821": "^1.0.1", | ||
"haraka-constants": "^1.0.0", | ||
"haraka-utils": "^1.0.0" | ||
"address-rfc2821": "*", | ||
"haraka-constants": ">=1.0.2", | ||
"haraka-utils": "*" | ||
}, | ||
"devDependencies": { | ||
"eslint": ">=3", | ||
"eslint-plugin-haraka": "*", | ||
"haraka-test-fixtures": "*", | ||
@@ -33,0 +34,0 @@ "nodeunit": "*" |
@@ -5,2 +5,3 @@ [![Build Status][ci-img]][ci-url] | ||
[![NPM][npm-img]][npm-url] | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/haraka/haraka-plugin-karma.svg)](https://greenkeeper.io/) | ||
@@ -7,0 +8,0 @@ # Karma - A heuristics based reputation engine for the Haraka MTA |
@@ -543,2 +543,81 @@ 'use strict'; | ||
exports.check_result_length = { | ||
setUp : _set_up, | ||
'eq pattern is scored': function (test) { | ||
test.expect(2); | ||
var award = { | ||
id : 1, award : 2, | ||
operator : 'length', value : 'eq 3', | ||
reason : 'testing', resolution : 'hah', | ||
}; | ||
this.plugin.check_result_length(['3'], award, this.connection); | ||
// console.log(this.connection.results.store); | ||
test.equals(this.connection.results.store.karma.score, 2); | ||
test.equals(this.connection.results.store.karma.awards[0], 1); | ||
test.done(); | ||
}, | ||
'eq pattern is not scored': function (test) { | ||
test.expect(1); | ||
var award = { | ||
id : 1, award : 2, | ||
operator : 'length', value : 'eq 3', | ||
reason : 'testing', resolution : 'hah', | ||
}; | ||
this.plugin.check_result_length(['4'], award, this.connection); | ||
// console.log(this.connection.results.store.karma); | ||
test.deepEqual(this.connection.results.store.karma, undefined); | ||
test.done(); | ||
}, | ||
'gt pattern is scored': function (test) { | ||
test.expect(2); | ||
var award = { | ||
id : 1, award : 2, | ||
operator : 'length', value : 'gt 3', | ||
reason : 'testing', resolution : 'hah', | ||
}; | ||
this.plugin.check_result_length(['5'], award, this.connection); | ||
// console.log(this.connection.results.store); | ||
test.equals(this.connection.results.store.karma.score, 2); | ||
test.equals(this.connection.results.store.karma.awards[0], 1); | ||
test.done(); | ||
}, | ||
'gt pattern is not scored': function (test) { | ||
test.expect(1); | ||
var award = { | ||
id : 1, award : 2, | ||
operator : 'length', value : 'gt 3', | ||
reason : 'testing', resolution : 'hah', | ||
}; | ||
this.plugin.check_result_length(['3'], award, this.connection); | ||
// console.log(this.connection.results.store.karma); | ||
test.deepEqual(this.connection.results.store.karma, undefined); | ||
test.done(); | ||
}, | ||
'lt pattern is scored': function (test) { | ||
test.expect(2); | ||
var award = { | ||
id : 1, award : 2, | ||
operator : 'length', value : 'lt 3', | ||
reason : 'testing', resolution : 'hah', | ||
}; | ||
this.plugin.check_result_length(['2'], award, this.connection); | ||
// console.log(this.connection.results.store); | ||
test.equals(this.connection.results.store.karma.score, 2); | ||
test.equals(this.connection.results.store.karma.awards[0], 1); | ||
test.done(); | ||
}, | ||
'lt pattern is not scored': function (test) { | ||
test.expect(1); | ||
var award = { | ||
id : 1, award : 2, | ||
operator : 'length', value : 'lt 3', | ||
reason : 'testing', resolution : 'hah', | ||
}; | ||
this.plugin.check_result_length(['3'], award, this.connection); | ||
// console.log(this.connection.results.store.karma); | ||
test.deepEqual(this.connection.results.store.karma, undefined); | ||
test.done(); | ||
}, | ||
}; | ||
exports.check_result = { | ||
@@ -545,0 +624,0 @@ setUp : _set_up, |
Sorry, the diff of this file is not supported yet
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 2 instances in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
81227
12
1463
213
4
2
1
+ Addedaddress-rfc2821@2.1.3(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addeddiscontinuous-range@1.0.0(transitive)
+ Addedmoo@0.5.2(transitive)
+ Addednearley@2.20.1(transitive)
+ Addedrailroad-diagrams@1.0.0(transitive)
+ Addedrandexp@0.4.6(transitive)
+ Addedret@0.1.15(transitive)
- Removedaddress-rfc2821@1.2.3(transitive)
Updatedaddress-rfc2821@*
Updatedharaka-constants@>=1.0.2
Updatedharaka-utils@*