aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/app/controllers/blacklist-controller-test.js
blob: 7a14c02ccb0ae533f03dde3ddd3aebc736c2ea67 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
const assert = require('assert')
const BlacklistController = require('../../../../app/scripts/controllers/blacklist')

describe('blacklist controller', function () {
  let blacklistController

  before(() => {
    blacklistController = new BlacklistController()
  })

  describe('whitelistDomain', function () {
    it('should add hostname to the runtime whitelist', function () {
      blacklistController.whitelistDomain('foo.com')
      assert.deepEqual(blacklistController.store.getState().whitelist, ['foo.com'])

      blacklistController.whitelistDomain('bar.com')
      assert.deepEqual(blacklistController.store.getState().whitelist, ['bar.com', 'foo.com'])
    })
  })

  describe('checkForPhishing', function () {
    it('should not flag whitelisted values', function () {
      const result = blacklistController.checkForPhishing('www.metamask.io')
      assert.equal(result, false)
    })
    it('should flag explicit values', function () {
      const result = blacklistController.checkForPhishing('metamask.com')
      assert.equal(result, true)
    })
    it('should flag levenshtein values', function () {
      const result = blacklistController.checkForPhishing('metmask.io')
      assert.equal(result, true)
    })
    it('should not flag not-even-close values', function () {
      const result = blacklistController.checkForPhishing('example.com')
      assert.equal(result, false)
    })
    it('should not flag the ropsten faucet domains', function () {
      const result = blacklistController.checkForPhishing('faucet.metamask.io')
      assert.equal(result, false)
    })
    it('should not flag the mascara domain', function () {
      const result = blacklistController.checkForPhishing('zero.metamask.io')
      assert.equal(result, false)
    })
    it('should not flag the mascara-faucet domain', function () {
      const result = blacklistController.checkForPhishing('zero-faucet.metamask.io')
      assert.equal(result, false)
    })
    it('should not flag whitelisted domain', function () {
      blacklistController.whitelistDomain('metamask.com')
      const result = blacklistController.checkForPhishing('metamask.com')
      assert.equal(result, false)
    })
  })
})