|
@ -5,19 +5,28 @@ let c = require('../../encryption') |
|
|
describe('unit - encryption', function () { |
|
|
describe('unit - encryption', function () { |
|
|
|
|
|
|
|
|
it('encrypts and decrypts', function () { |
|
|
it('encrypts and decrypts', function () { |
|
|
let crypted = c.encrypt('data', 'password'); |
|
|
const data2encrypt = 'really long data string bla bla really long data string bla bla really long data string bla bla'; |
|
|
let decrypted = c.decrypt(crypted, 'password'); |
|
|
const crypted = c.encrypt(data2encrypt, 'password'); |
|
|
|
|
|
const decrypted = c.decrypt(crypted, 'password'); |
|
|
|
|
|
|
|
|
assert.ok(crypted); |
|
|
assert.ok(crypted); |
|
|
assert.ok(decrypted); |
|
|
assert.ok(decrypted); |
|
|
assert.equal(decrypted, 'data'); |
|
|
assert.equal(decrypted, data2encrypt); |
|
|
assert.ok(crypted !== 'data'); |
|
|
assert.ok(crypted !== data2encrypt); |
|
|
|
|
|
|
|
|
let decryptedWithBadPassword |
|
|
let decryptedWithBadPassword |
|
|
try { |
|
|
try { |
|
|
decryptedWithBadPassword = c.decrypt(crypted, 'passwordBad'); |
|
|
decryptedWithBadPassword = c.decrypt(crypted, 'passwordBad'); |
|
|
} catch (e) {} |
|
|
} catch (e) {} |
|
|
assert.ok(!decryptedWithBadPassword) |
|
|
assert.ok(!decryptedWithBadPassword) |
|
|
|
|
|
|
|
|
|
|
|
let exceptionRaised = false; |
|
|
|
|
|
try { |
|
|
|
|
|
c.encrypt('yolo', 'password'); |
|
|
|
|
|
} catch (_) { |
|
|
|
|
|
exceptionRaised = true; |
|
|
|
|
|
} |
|
|
|
|
|
assert.ok(exceptionRaised); |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
it('handles ok malformed data', function() { |
|
|
it('handles ok malformed data', function() { |
|
|