2016-10-13 05:03:14 +02:00
|
|
|
var encryptor = require('../../../app/scripts/lib/encryptor')
|
|
|
|
|
|
|
|
QUnit.test('encryptor', function(assert) {
|
2016-10-14 22:21:00 +02:00
|
|
|
var done = assert.async();
|
2016-10-13 05:03:14 +02:00
|
|
|
var password, data, encrypted
|
|
|
|
|
|
|
|
password = 'a sample passw0rd'
|
|
|
|
data = { foo: 'data to encrypt' }
|
|
|
|
|
|
|
|
encryptor.encrypt(password, data)
|
2016-10-14 22:21:00 +02:00
|
|
|
.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()
|
2016-10-13 05:03:14 +02:00
|
|
|
})
|
|
|
|
.catch(function(reason) {
|
|
|
|
assert.ifError(reason, 'threw an error')
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|