@passmarked/malware
Version:
Rules that check if the page or linked pages on the same domain (or external) contain any unwanted software,malware or reported phishing attacks
272 lines (172 loc) • 5.93 kB
JavaScript
// modules
const assert = require('assert');
const _ = require('underscore');
const fs = require('fs');
const passmarked = require('passmarked');
// handle the settings
describe('safebrowsing', function() {
describe('page', function() {
describe('unwanted', function() {
// handle the error output
it('Should report back error if the current page is part of the cache of bad links', function(done) {
// handle the payload
var payload = passmarked.createPayload({
url: 'http://example.com',
cache: {
'passmarked:safebrowsing:9c17e047f58f9220a7008d4f18152fee4d111d14': 'unwanted'
}
}, null, '')
// run the rules
require('../lib/rules/page')(payload, function(err) {
// check for a error
if(err)
assert.fail('Was not expecting a error');
// get the rules
var rules = payload.getRules();
// check
var rule = _.find(rules, function(item) {
return item.key == 'page.unwanted';
});
// check if we found it
if(!rule)
assert.fail('Expected a error');
// done
done();
});
});
// handle the error output
it('Should not report error if the given page is not a unwanted attack', function(done) {
// handle the payload
var payload = passmarked.createPayload({
url: 'http://example22222.com',
cache: {}
}, null, '')
// run the rules
require('../lib/rules/page')(payload, function(err) {
// check for a error
if(err)
assert.fail('Was not expecting a error');
// get the rules
var rules = payload.getRules();
// check
var rule = _.find(rules, function(item) {
return item.key == 'page.unwanted';
});
// check if we found it
if(rule)
assert.fail('Was not expecting a error');
// done
done();
});
});
});
describe('phishing', function() {
// handle the error output
it('Should report back error if the current page is part of the cache of bad links', function(done) {
// handle the payload
var payload = passmarked.createPayload({
url: 'http://example.com',
cache: {
'passmarked:safebrowsing:9c17e047f58f9220a7008d4f18152fee4d111d14': 'phishing'
}
}, null, '')
// run the rules
require('../lib/rules/page')(payload, function(err) {
// check for a error
if(err)
assert.fail('Was not expecting a error');
// get the rules
var rules = payload.getRules();
// check
var rule = _.find(rules, function(item) {
return item.key == 'page.phishing';
});
// check if we found it
if(!rule)
assert.fail('Expected a error');
// done
done();
});
});
// handle the error output
it('Should not report error if the given page is not a phishing attack', function(done) {
// handle the payload
var payload = passmarked.createPayload({
url: 'http://example22222.com',
cache: {}
}, null, '')
// run the rules
require('../lib/rules/page')(payload, function(err) {
// check for a error
if(err)
assert.fail('Was not expecting a error');
// get the rules
var rules = payload.getRules();
// check
var rule = _.find(rules, function(item) {
return item.key == 'page.phishing';
});
// check if we found it
if(rule)
assert.fail('Was not expecting a error');
// done
done();
});
});
});
describe('malware', function() {
// handle the error output
it('Should report back error if the current page is part of the cache of bad links', function(done) {
// handle the payload
var payload = passmarked.createPayload({
url: 'http://example.com',
cache: {
'passmarked:safebrowsing:9c17e047f58f9220a7008d4f18152fee4d111d14': 'malware'
}
}, null, '')
// run the rules
require('../lib/rules/page')(payload, function(err) {
// check for a error
if(err)
assert.fail('Was not expecting a error');
// get the rules
var rules = payload.getRules();
// check
var rule = _.find(rules, function(item) {
return item.key == 'page.malware';
});
// check if we found it
if(!rule)
assert.fail('Expected a error');
// done
done();
});
});
// handle the error output
it('Should not report error if the given page is not a phishing attack', function(done) {
// handle the payload
var payload = passmarked.createPayload({
url: 'http://example22222.com',
cache: {}
}, null, '')
// run the rules
require('../lib/rules/page')(payload, function(err) {
// check for a error
if(err)
assert.fail('Was not expecting a error');
// get the rules
var rules = payload.getRules();
// check
var rule = _.find(rules, function(item) {
return item.key == 'page.phishtank';
});
// check if we found it
if(rule)
assert.fail('Was not expecting a error');
// done
done();
});
});
});
});
});