From 629457ea5460a1841d4682a234d6a6fb330517f9 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 24 Apr 2018 13:33:31 -0700 Subject: setupUntrustedCommunication and setupTrustedCommunication --- test/unit/metamask-controller-test.js | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'test') diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js index c9d041f01..acf105d4d 100644 --- a/test/unit/metamask-controller-test.js +++ b/test/unit/metamask-controller-test.js @@ -2,6 +2,7 @@ const assert = require('assert') const sinon = require('sinon') const clone = require('clone') const nock = require('nock') +const createThoughStream = require('through2').obj const MetaMaskController = require('../../app/scripts/metamask-controller') const blacklistJSON = require('../stub/blacklist') const firstTimeState = require('../../app/scripts/first-time-state') @@ -187,6 +188,10 @@ describe('MetaMaskController', function () { rpcTarget = metamaskController.setCustomRpc(customRPC) }) + afterEach(function () { + nock.cleanAll() + }) + it('returns custom RPC that when called', async function () { assert.equal(await rpcTarget, customRPC) }) @@ -484,6 +489,46 @@ describe('MetaMaskController', function () { }) }) + describe('#setupUntrustedCommunication', function () { + let streamTest + + const phishingUrl = 'decentral.market' + + afterEach(function () { + streamTest.end() + }) + + it('sets up phishing stream for untrusted communication ', async function () { + await metamaskController.blacklistController.updatePhishingList() + + streamTest = createThoughStream((chunk, enc, cb) => { + assert.equal(chunk.name, 'phishing') + assert.equal(chunk.data.hostname, phishingUrl) + cb() + }) + // console.log(streamTest) + metamaskController.setupUntrustedCommunication(streamTest, phishingUrl) + }) + }) + + describe('#setupTrustedCommunication', function () { + let streamTest + + afterEach(function () { + streamTest.end() + }) + + it('sets up controller dnode api for trusted communication', function (done) { + streamTest = createThoughStream((chunk, enc, cb) => { + assert.equal(chunk.name, 'controller') + cb() + done() + }) + + metamaskController.setupTrustedCommunication(streamTest, 'mycrypto.com') + }) + }) + describe('#markAccountsFound', function () { it('adds lost accounts to config manager data', function () { metamaskController.markAccountsFound(noop) -- cgit