mail/test/unit/crypto/crypto-test.js

50 lines
1.3 KiB
JavaScript
Raw Normal View History

2014-10-07 14:32:23 -04:00
'use strict';
2014-06-05 09:26:19 -04:00
var Crypto = require('../../../src/js/crypto/crypto'),
config = require('../../../src/js/app-config').config,
2014-10-07 14:32:23 -04:00
util = require('crypto-lib').util;
2014-06-05 09:26:19 -04:00
2014-10-07 14:32:23 -04:00
describe('Crypto unit tests', function() {
this.timeout(20000);
2014-06-05 09:26:19 -04:00
2014-10-07 14:32:23 -04:00
var crypto,
password = 'password',
keySize = config.symKeySize,
ivSize = config.symIvSize;
2014-06-05 09:26:19 -04:00
2014-10-07 14:32:23 -04:00
beforeEach(function() {
2014-12-12 12:07:30 -05:00
crypto = new Crypto();
2014-10-07 14:32:23 -04:00
});
2014-06-05 09:26:19 -04:00
2014-10-07 14:32:23 -04:00
afterEach(function() {});
2014-06-05 09:26:19 -04:00
2014-10-07 14:32:23 -04:00
describe('AES encrypt/decrypt', function() {
it('should work', function(done) {
var plaintext = 'Hello, World!';
var key = util.random(keySize);
var iv = util.random(ivSize);
2014-06-05 09:26:19 -04:00
2014-12-11 08:16:07 -05:00
crypto.encrypt(plaintext, key, iv).then(function(ciphertext) {
2014-10-07 14:32:23 -04:00
expect(ciphertext).to.exist;
2014-06-05 09:26:19 -04:00
2014-12-11 08:16:07 -05:00
return crypto.decrypt(ciphertext, key, iv);
}).then(function(decrypted) {
expect(decrypted).to.equal(plaintext);
2014-06-05 09:26:19 -04:00
2014-12-11 08:16:07 -05:00
done();
2014-06-05 09:26:19 -04:00
});
});
2014-10-07 14:32:23 -04:00
});
2014-06-05 09:26:19 -04:00
2014-10-07 14:32:23 -04:00
describe("PBKDF2 (Async/Worker)", function() {
it('should work', function(done) {
var salt = util.random(keySize);
2014-06-05 09:26:19 -04:00
2014-12-11 08:16:07 -05:00
crypto.deriveKey(password, salt, keySize).then(function(key) {
2014-10-07 14:32:23 -04:00
expect(util.base642Str(key).length * 8).to.equal(keySize);
done();
2014-06-05 09:26:19 -04:00
});
});
});
2014-10-07 14:32:23 -04:00
2014-06-05 09:26:19 -04:00
});