From cd05d77c3fd9fe8e49d38b43728ff90b72b1ca9d Mon Sep 17 00:00:00 2001 From: Csaba Solya Date: Fri, 23 Feb 2018 10:49:56 +0100 Subject: fix tests --- test/unit/edge-encryptor-test.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/unit/edge-encryptor-test.js b/test/unit/edge-encryptor-test.js index 627386051..ef733a494 100644 --- a/test/unit/edge-encryptor-test.js +++ b/test/unit/edge-encryptor-test.js @@ -5,21 +5,21 @@ const EdgeEncryptor = require('../../app/scripts/edge-encryptor') var password = 'passw0rd1' var data = 'some random data' -// polyfill fetch global.crypto = global.crypto || { - getRandomValues (array) { + getRandomValues: function (array) { for (let i = 0; i < array.length; i++) { - array[i] = Math.random() * 100; + array[i] = Math.random() * 100 } + return array } } describe('EdgeEncryptor', function () { - const edgeEncryptor = new EdgeEncryptor() + const edgeEncryptor = new EdgeEncryptor() describe('encrypt', function () { - it('should encrypt the data.', function () { + it('should encrypt the data.', function (done) { edgeEncryptor.encrypt(password, data) .then(function (encryptedData) { assert.notEqual(data, encryptedData) @@ -30,6 +30,19 @@ describe('EdgeEncryptor', function () { }) }) + it('should return proper format.', function (done) { + edgeEncryptor.encrypt(password, data) + .then(function (encryptedData) { + let encryptedObject = JSON.parse(encryptedData) + assert.ok(encryptedObject.data, 'there is no data') + assert.ok(encryptedObject.iv && encryptedObject.iv.length != 0, 'there is no iv') + assert.ok(encryptedObject.salt && encryptedObject.salt.length != 0, 'there is no salt') + done() + }).catch(function (err) { + done(err) + }) + }) + it('should not return the same twice.', function () { const encryptPromises = [] @@ -46,13 +59,14 @@ describe('EdgeEncryptor', function () { }) describe('decrypt', function () { - it('should be able to decrypt the encrypted data.', function () { + it('should be able to decrypt the encrypted data.', function (done) { edgeEncryptor.encrypt(password, data) .then(function (encryptedData) { edgeEncryptor.decrypt(password, encryptedData) .then(function (decryptedData) { assert.equal(decryptedData, data) + done() }) .catch(function (err) { done(err) -- cgit v1.2.3