aboutsummaryrefslogtreecommitdiffstats
path: root/test/integration/lib/encryptor-test.js
diff options
context:
space:
mode:
authorKevin Serrano <kevgagser@gmail.com>2016-11-19 01:23:20 +0800
committerKevin Serrano <kevgagser@gmail.com>2016-11-19 01:23:20 +0800
commitbef023fb4a699c16fe0fff30ce18840678ed7ad0 (patch)
treed11be9af938712aeb554f070822be01b2d7fbceb /test/integration/lib/encryptor-test.js
parent37d836fa72c75945d436bd94feadb65aa95d7e5f (diff)
parent39e0a33bba2709971edec0304027f646cb2db3cc (diff)
downloadtangerine-wallet-browser-bef023fb4a699c16fe0fff30ce18840678ed7ad0.tar.gz
tangerine-wallet-browser-bef023fb4a699c16fe0fff30ce18840678ed7ad0.tar.zst
tangerine-wallet-browser-bef023fb4a699c16fe0fff30ce18840678ed7ad0.zip
Resolve merge conflict.
Diffstat (limited to 'test/integration/lib/encryptor-test.js')
-rw-r--r--test/integration/lib/encryptor-test.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/test/integration/lib/encryptor-test.js b/test/integration/lib/encryptor-test.js
new file mode 100644
index 000000000..d42608152
--- /dev/null
+++ b/test/integration/lib/encryptor-test.js
@@ -0,0 +1,67 @@
+var encryptor = require('../../../app/scripts/lib/encryptor')
+
+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
+
+ password = 'a sample passw0rd'
+ data = { foo: 'data to encrypt' }
+
+ encryptor.encrypt(password, data)
+ .then(function(encryptedStr) {
+ assert.equal(typeof encryptedStr, 'string', 'returns a string')
+ return encryptor.decrypt(password, encryptedStr)
+ })
+ .then(function (decryptedObj) {
+ assert.deepEqual(decryptedObj, data, 'decrypted what was encrypted')
+ done()
+ })
+ .catch(function(reason) {
+ assert.ifError(reason, 'threw an error')
+ done(reason)
+ })
+
+})
+
+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()
+ })
+})