65 lines
2.5 KiB
JavaScript
65 lines
2.5 KiB
JavaScript
/* globals tryTests: true */
|
|
|
|
'use strict';
|
|
|
|
var openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../../dist/openpgp');
|
|
|
|
var chai = require('chai'),
|
|
expect = chai.expect;
|
|
|
|
var pub_key =
|
|
['-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
|
'Version: GnuPG v2.0.19 (GNU/Linux)',
|
|
'',
|
|
'mI0EUmEvTgEEANyWtQQMOybQ9JltDqmaX0WnNPJeLILIM36sw6zL0nfTQ5zXSS3+',
|
|
'fIF6P29lJFxpblWk02PSID5zX/DYU9/zjM2xPO8Oa4xo0cVTOTLj++Ri5mtr//f5',
|
|
'GLsIXxFrBJhD/ghFsL3Op0GXOeLJ9A5bsOn8th7x6JucNKuaRB6bQbSPABEBAAG0',
|
|
'JFRlc3QgTWNUZXN0aW5ndG9uIDx0ZXN0QGV4YW1wbGUuY29tPoi5BBMBAgAjBQJS',
|
|
'YS9OAhsvBwsJCAcDAgEGFQgCCQoLBBYCAwECHgECF4AACgkQSmNhOk1uQJQwDAP6',
|
|
'AgrTyqkRlJVqz2pb46TfbDM2TDF7o9CBnBzIGoxBhlRwpqALz7z2kxBDmwpQa+ki',
|
|
'Bq3jZN/UosY9y8bhwMAlnrDY9jP1gdCo+H0sD48CdXybblNwaYpwqC8VSpDdTndf',
|
|
'9j2wE/weihGp/DAdy/2kyBCaiOY1sjhUfJ1GogF49rC4jQRSYS9OAQQA6R/PtBFa',
|
|
'JaT4jq10yqASk4sqwVMsc6HcifM5lSdxzExFP74naUMMyEsKHP53QxTF0Grqusag',
|
|
'Qg/ZtgT0CN1HUM152y7ACOdp1giKjpMzOTQClqCoclyvWOFB+L/SwGEIJf7LSCEr',
|
|
'woBuJifJc8xAVr0XX0JthoW+uP91eTQ3XpsAEQEAAYkBPQQYAQIACQUCUmEvTgIb',
|
|
'LgCoCRBKY2E6TW5AlJ0gBBkBAgAGBQJSYS9OAAoJEOCE90RsICyXuqIEANmmiRCA',
|
|
'SF7YK7PvFkieJNwzeK0V3F2lGX+uu6Y3Q/Zxdtwc4xR+me/CSBmsURyXTO29OWhP',
|
|
'GLszPH9zSJU9BdDi6v0yNprmFPX/1Ng0Abn/sCkwetvjxC1YIvTLFwtUL/7v6NS2',
|
|
'bZpsUxRTg9+cSrMWWSNjiY9qUKajm1tuzPDZXAUEAMNmAN3xXN/Kjyvj2OK2ck0X',
|
|
'W748sl/tc3qiKPMJ+0AkMF7Pjhmh9nxqE9+QCEl7qinFqqBLjuzgUhBU4QlwX1GD',
|
|
'AtNTq6ihLMD5v1d82ZC7tNatdlDMGWnIdvEMCv2GZcuIqDQ9rXWs49e7tq1NncLY',
|
|
'hz3tYjKhoFTKEIq3y3Pp',
|
|
'=h/aX',
|
|
'-----END PGP PUBLIC KEY BLOCK-----'].join('\n');
|
|
|
|
var plaintext = 'short message\nnext line\n한국어/조선말';
|
|
var pubKey;
|
|
|
|
tryTests('Async Proxy', tests, {
|
|
if: typeof window !== 'undefined' && window.Worker,
|
|
before: function() {
|
|
openpgp.initWorker({ path:'../dist/openpgp.worker.js' });
|
|
pubKey = openpgp.key.readArmored(pub_key).keys[0];
|
|
},
|
|
after: function() {
|
|
openpgp.destroyWorker();
|
|
}
|
|
});
|
|
|
|
function tests() {
|
|
|
|
describe('Error handling', function() {
|
|
it('Depleted random buffer in worker gives error', function (done) {
|
|
var wProxy = new openpgp.AsyncProxy({ path:'../dist/openpgp.worker.js' });
|
|
wProxy.worker = new Worker('../dist/openpgp.worker.js');
|
|
wProxy.worker.onmessage = wProxy.onMessage.bind(wProxy);
|
|
wProxy.seedRandom(10);
|
|
wProxy.delegate('encrypt', { publicKeys:[pubKey], data:plaintext }).catch(function(err) {
|
|
expect(err.message).to.match(/Random number buffer depleted/);
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
|
|
}
|