From cce8d9e3600e8ba0ced12013b0b208fff9f9c8a8 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 12 Oct 2016 20:03:14 -0700 Subject: Began adding browser-native encryptor module Added new Qunit build process that will browserify the contents of `test/integration/lib` into the QUnit browser, allowing much more modular testing, including unit testing of our modules in our target browsers. Made a basic unit test file of this form for the new encryptor module, which fails miserably because I've only just begun to work with it. I've started with this blog post as a starting point, and will be adjusting it to our needs from there: http://qnimate.com/passphrase-based-encryption-using-web-cryptography-api/ --- test/integration/lib/encryptor-test.js | 17 +++++++++++++++++ test/integration/lib/first-time.js | 25 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 test/integration/lib/encryptor-test.js create mode 100644 test/integration/lib/first-time.js (limited to 'test/integration/lib') diff --git a/test/integration/lib/encryptor-test.js b/test/integration/lib/encryptor-test.js new file mode 100644 index 000000000..21d6ee6f7 --- /dev/null +++ b/test/integration/lib/encryptor-test.js @@ -0,0 +1,17 @@ +var encryptor = require('../../../app/scripts/lib/encryptor') + +QUnit.test('encryptor', function(assert) { + var password, data, encrypted + + password = 'a sample passw0rd' + data = { foo: 'data to encrypt' } + + encryptor.encrypt(password, data) + .then(function(result) { + assert.equal(typeof result, 'string', 'returns a string') + }) + .catch(function(reason) { + assert.ifError(reason, 'threw an error') + }) + +}) diff --git a/test/integration/lib/first-time.js b/test/integration/lib/first-time.js new file mode 100644 index 000000000..af9b94e24 --- /dev/null +++ b/test/integration/lib/first-time.js @@ -0,0 +1,25 @@ +QUnit.test('agree to terms', function (assert) { + var done = assert.async() + + // Select the mock app root + var app = $('iframe').contents().find('#app-content .mock-app-root') + + app.find('.markdown').prop('scrollTop', 100000000) + + wait().then(function() { + app.find('button').click() + }).then(function() { + return wait() + }).then(function() { + var title = app.find('h1').text() + assert.equal(title, 'MetaMask', 'title screen') + + var buttons = app.find('button') + assert.equal(buttons.length, 1, 'one button: create new vault') + + done() + }) + + // Wait for view to transition: +}) + -- cgit v1.2.3 From c9cfcd5253b29ef7240e556a847f525c38729fa0 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Fri, 14 Oct 2016 13:21:00 -0700 Subject: Got encrypting working, not yet decrypting --- test/integration/lib/encryptor-test.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'test/integration/lib') diff --git a/test/integration/lib/encryptor-test.js b/test/integration/lib/encryptor-test.js index 21d6ee6f7..f5cdea835 100644 --- a/test/integration/lib/encryptor-test.js +++ b/test/integration/lib/encryptor-test.js @@ -1,14 +1,25 @@ var encryptor = require('../../../app/scripts/lib/encryptor') QUnit.test('encryptor', function(assert) { + var done = assert.async(); var password, data, encrypted password = 'a sample passw0rd' data = { foo: 'data to encrypt' } encryptor.encrypt(password, data) - .then(function(result) { - assert.equal(typeof result, 'string', 'returns a string') + .then(function(encryptedStr) { + + assert.equal(typeof encryptedStr, 'string', 'returns a string') + + // Now try decrypting!jk + // + return encryptor.decrypt(password, encryptedStr) + + }) + .then(function (decryptedObj) { + assert.equal(decryptedObj, data, 'decrypted what was encrypted') + done() }) .catch(function(reason) { assert.ifError(reason, 'threw an error') -- cgit v1.2.3 From 1c791c4d2e7f280b634a5fe1bb449d5d05c9db7c Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Fri, 14 Oct 2016 15:59:07 -0700 Subject: Got basic encryptor working --- test/integration/lib/encryptor-test.js | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'test/integration/lib') diff --git a/test/integration/lib/encryptor-test.js b/test/integration/lib/encryptor-test.js index f5cdea835..3297ad177 100644 --- a/test/integration/lib/encryptor-test.js +++ b/test/integration/lib/encryptor-test.js @@ -1,6 +1,27 @@ var encryptor = require('../../../app/scripts/lib/encryptor') -QUnit.test('encryptor', function(assert) { +QUnit.test('encryptor:serializeBufferForStorage', function (assert) { + assert.expect(1) + var buf = new Buffer(2) + buf[0] = 16 + buf[1] = 1 + + var output = encryptor.serializeBufferForStorage(buf) + + var expect = '0x1001' + assert.equal(expect, output) +}) + +QUnit.test('encryptor:serializeBufferFromStorage', function (assert) { + assert.expect(2) + var input = '0x1001' + var output = encryptor.serializeBufferFromStorage(input) + + assert.equal(output[0], 16) + assert.equal(output[1], 1) +}) + +QUnit.test('encryptor:encrypt & decrypt', function(assert) { var done = assert.async(); var password, data, encrypted @@ -9,19 +30,15 @@ QUnit.test('encryptor', function(assert) { encryptor.encrypt(password, data) .then(function(encryptedStr) { - assert.equal(typeof encryptedStr, 'string', 'returns a string') - - // Now try decrypting!jk - // return encryptor.decrypt(password, encryptedStr) - }) .then(function (decryptedObj) { - assert.equal(decryptedObj, data, 'decrypted what was encrypted') + assert.deepEqual(decryptedObj, data, 'decrypted what was encrypted') done() }) .catch(function(reason) { + debugger assert.ifError(reason, 'threw an error') }) -- cgit v1.2.3 From 036b0e4ccabded3c3dda39f8d81b9fa3fc07dd9c Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Fri, 14 Oct 2016 16:28:08 -0700 Subject: Linted --- test/integration/lib/encryptor-test.js | 1 - 1 file changed, 1 deletion(-) (limited to 'test/integration/lib') diff --git a/test/integration/lib/encryptor-test.js b/test/integration/lib/encryptor-test.js index 3297ad177..88ebed51b 100644 --- a/test/integration/lib/encryptor-test.js +++ b/test/integration/lib/encryptor-test.js @@ -38,7 +38,6 @@ QUnit.test('encryptor:encrypt & decrypt', function(assert) { done() }) .catch(function(reason) { - debugger assert.ifError(reason, 'threw an error') }) -- cgit v1.2.3 From 0deed1775237bc8d48eb41e83b5a661b55e4b6be Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 20 Oct 2016 12:07:53 -0700 Subject: Fix tests --- test/integration/lib/encryptor-test.js | 1 + 1 file changed, 1 insertion(+) (limited to 'test/integration/lib') diff --git a/test/integration/lib/encryptor-test.js b/test/integration/lib/encryptor-test.js index 88ebed51b..1c8a7605a 100644 --- a/test/integration/lib/encryptor-test.js +++ b/test/integration/lib/encryptor-test.js @@ -39,6 +39,7 @@ QUnit.test('encryptor:encrypt & decrypt', function(assert) { }) .catch(function(reason) { assert.ifError(reason, 'threw an error') + done(reason) }) }) -- cgit v1.2.3 From 678301a20e6112d79a052c13f921bb75c451c613 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Tue, 25 Oct 2016 13:24:03 -0700 Subject: Phase out extra warning screen. --- test/integration/lib/first-time.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test/integration/lib') diff --git a/test/integration/lib/first-time.js b/test/integration/lib/first-time.js index af9b94e24..caa6102fe 100644 --- a/test/integration/lib/first-time.js +++ b/test/integration/lib/first-time.js @@ -5,7 +5,7 @@ QUnit.test('agree to terms', function (assert) { var app = $('iframe').contents().find('#app-content .mock-app-root') app.find('.markdown').prop('scrollTop', 100000000) - + debugger; wait().then(function() { app.find('button').click() }).then(function() { @@ -22,4 +22,3 @@ QUnit.test('agree to terms', function (assert) { // Wait for view to transition: }) - -- cgit v1.2.3 From b3cb3e9ec67a138767bb2d6833c9056a66d46b92 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Tue, 25 Oct 2016 13:24:57 -0700 Subject: Remove debugger statement. --- test/integration/lib/first-time.js | 1 - 1 file changed, 1 deletion(-) (limited to 'test/integration/lib') diff --git a/test/integration/lib/first-time.js b/test/integration/lib/first-time.js index caa6102fe..7cabf1f0a 100644 --- a/test/integration/lib/first-time.js +++ b/test/integration/lib/first-time.js @@ -5,7 +5,6 @@ QUnit.test('agree to terms', function (assert) { var app = $('iframe').contents().find('#app-content .mock-app-root') app.find('.markdown').prop('scrollTop', 100000000) - debugger; wait().then(function() { app.find('button').click() }).then(function() { -- cgit v1.2.3 From ba7d6b437f2e03a9e2bb46dcda846cee1f816ce1 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 3 Nov 2016 16:06:57 -0700 Subject: Fix password validation and persistence issue Was wiping the vault on each successful password attempt... :P --- test/integration/lib/encryptor-test.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/integration/lib') diff --git a/test/integration/lib/encryptor-test.js b/test/integration/lib/encryptor-test.js index 1c8a7605a..d42608152 100644 --- a/test/integration/lib/encryptor-test.js +++ b/test/integration/lib/encryptor-test.js @@ -43,3 +43,25 @@ QUnit.test('encryptor:encrypt & decrypt', function(assert) { }) }) + +QUnit.test('encryptor:encrypt & decrypt with wrong password', function(assert) { + var done = assert.async(); + var password, data, encrypted, wrongPassword + + password = 'a sample passw0rd' + wrongPassword = 'a wrong password' + data = { foo: 'data to encrypt' } + + encryptor.encrypt(password, data) + .then(function(encryptedStr) { + assert.equal(typeof encryptedStr, 'string', 'returns a string') + return encryptor.decrypt(wrongPassword, encryptedStr) + }) + .then(function (decryptedObj) { + assert.equal(!decryptedObj, true, 'Wrong password should not decrypt') + done() + }) + .catch(function(reason) { + done() + }) +}) -- cgit v1.2.3 From 93c0a6826aa70fa14874579b1009bee7248a7c51 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Mon, 7 Nov 2016 14:11:01 -0800 Subject: Fix integration test suite --- test/integration/lib/first-time.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'test/integration/lib') diff --git a/test/integration/lib/first-time.js b/test/integration/lib/first-time.js index 7cabf1f0a..a73b0cba3 100644 --- a/test/integration/lib/first-time.js +++ b/test/integration/lib/first-time.js @@ -1,23 +1,15 @@ QUnit.test('agree to terms', function (assert) { var done = assert.async() + let app - // Select the mock app root - var app = $('iframe').contents().find('#app-content .mock-app-root') - - app.find('.markdown').prop('scrollTop', 100000000) wait().then(function() { - app.find('button').click() - }).then(function() { + app = $('iframe').contents().find('#app-content .mock-app-root') + app.find('.markdown').prop('scrollTop', 100000000) return wait() }).then(function() { var title = app.find('h1').text() assert.equal(title, 'MetaMask', 'title screen') - var buttons = app.find('button') - assert.equal(buttons.length, 1, 'one button: create new vault') - done() }) - - // Wait for view to transition: }) -- cgit v1.2.3