1
0
mirror of https://github.com/moparisthebest/mail synced 2024-12-02 05:42:20 -05:00
mail/test/unit/crypto-test.js

58 lines
1.7 KiB
JavaScript
Raw Normal View History

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