diff --git a/test/alexa.json b/test/alexa.json new file mode 100644 index 0000000..5e59b09 --- /dev/null +++ b/test/alexa.json @@ -0,0 +1,52 @@ +[ + "google.com", + "youtube.com", + "facebook.com", + "baidu.com", + "wikipedia.org", + "yahoo.com", + "google.co.in", + "qq.com", + "reddit.com", + "amazon.com", + "taobao.com", + "twitter.com", + "google.co.jp", + "tmall.com", + "vk.com", + "live.com", + "sohu.com", + "instagram.com", + "sina.com.cn", + "jd.com", + "weibo.com", + "360.cn", + "google.de", + "google.co.uk", + "linkedin.com", + "list.tmall.com", + "google.fr", + "google.com.br", + "google.ru", + "yandex.ru", + "google.com.hk", + "netflix.com", + "yahoo.co.jp", + "google.it", + "t.co", + "google.es", + "ebay.com", + "pornhub.com", + "imgur.com", + "bing.com", + "twitch.tv", + "alipay.com", + "google.ca", + "msn.com", + "google.com.mx", + "tumblr.com", + "xvideos.com", + "ok.ru", + "mail.ru", + "microsoft.com" +] \ No newline at end of file diff --git a/test/index.js b/test/index.js index 625eb03..26f332d 100644 --- a/test/index.js +++ b/test/index.js @@ -1,6 +1,7 @@ const test = require('tape') const PhishingDetector = require('../src/detector') const config = require('../src/config.json') +const alexaTopSites = require('./alexa.json') const detector = new PhishingDetector(config) @@ -60,6 +61,13 @@ test('basic test', (t) => { t.end() }) +test('alexa top sites', (t) => { + // alexa top sites + testAnyType(t, false, alexaTopSites) + t.end() +}) + + function testBlacklist(t, domains) { domains.forEach((domain) => { testDomain(t, { @@ -100,11 +108,25 @@ function testNoMatch(t, domains) { }) } +function testAnyType(t, expected, domains) { + domains.forEach((domain) => { + testDomain(t, { + domain: domain, + expected, + }) + }) +} + function testDomain(t, { domain, type, expected }) { const value = detector.check(domain) + // log fuzzy match for debugging if (value.type === 'fuzzy') { t.comment(`"${domain}" fuzzy matches against "${value.match}"`) } - t.equal(value.type, type, `type: "${domain}" should be "${type}"`) + // enforcing type is optional + if (type) { + t.equal(value.type, type, `type: "${domain}" should be "${type}"`) + } + // enforcing result is required t.equal(value.result, expected, `result: "${domain}" should be match "${expected}"`) } \ No newline at end of file