aboutsummaryrefslogtreecommitdiffstats
path: root/lang/js/BrowserTestExtension/tests/encryptTest.js
diff options
context:
space:
mode:
authorMaximilian Krambach <[email protected]>2018-07-27 09:20:33 +0000
committerMaximilian Krambach <[email protected]>2018-07-27 09:20:33 +0000
commitb18b96fb364711025d1e5fa9f135ee682dd0558a (patch)
tree9221b5b177eb68a7a11a66c1b782048aa61e3b3d /lang/js/BrowserTestExtension/tests/encryptTest.js
parentjs: include armored Key in import callback (diff)
downloadgpgme-b18b96fb364711025d1e5fa9f135ee682dd0558a.tar.gz
gpgme-b18b96fb364711025d1e5fa9f135ee682dd0558a.zip
js: clean up test extension
-- Tests will now run with one instance of gpgmejs each block, which reduces overhead. Readability is (hopefully) improved), some negative tests are added. There is still a performance problem in base64 encoding/decoding, which causes some tests to fail due to time out.
Diffstat (limited to 'lang/js/BrowserTestExtension/tests/encryptTest.js')
-rw-r--r--lang/js/BrowserTestExtension/tests/encryptTest.js157
1 files changed, 57 insertions, 100 deletions
diff --git a/lang/js/BrowserTestExtension/tests/encryptTest.js b/lang/js/BrowserTestExtension/tests/encryptTest.js
index 1114125e..3ead8153 100644
--- a/lang/js/BrowserTestExtension/tests/encryptTest.js
+++ b/lang/js/BrowserTestExtension/tests/encryptTest.js
@@ -21,134 +21,91 @@
* Maximilian Krambach <[email protected]>
*/
-/* global describe, it, expect, Gpgmejs */
+/* global describe, it, expect, before, Gpgmejs */
/* global inputvalues, fixedLengthString */
describe('Encryption', function () {
- it('Successful encrypt', function (done) {
- let prm = Gpgmejs.init();
- prm.then(function (context) {
- context.encrypt(
- inputvalues.encrypt.good.data,
- inputvalues.encrypt.good.fingerprint).then(function (answer) {
- expect(answer).to.not.be.empty;
- expect(answer.data).to.be.a('string');
- expect(answer.data).to.include('BEGIN PGP MESSAGE');
- expect(answer.data).to.include('END PGP MESSAGE');
- done();
- });
+ let context = null;
+ const good_fpr = inputvalues.encrypt.good.fingerprint;
+ before(function(done){
+ const prm = Gpgmejs.init();
+ prm.then(function(gpgmejs){
+ context = gpgmejs;
+ done();
});
});
- it('Successful encrypt 5 MB', function (done) {
- let prm = Gpgmejs.init();
- let data = fixedLengthString(5);
- prm.then(function (context) {
- context.encrypt(
- data,
- inputvalues.encrypt.good.fingerprint).then(function (answer) {
- expect(answer).to.not.be.empty;
- expect(answer.data).to.be.a('string');
- expect(answer.data).to.include('BEGIN PGP MESSAGE');
- expect(answer.data).to.include('END PGP MESSAGE');
- done();
- });
- });
- }).timeout(10000);
-
- it('Successful encrypt 20 MB', function (done) {
- let prm = Gpgmejs.init();
- let data = fixedLengthString(20);
- prm.then(function (context) {
- context.encrypt(
- data,
- inputvalues.encrypt.good.fingerprint).then(function (answer) {
- expect(answer).to.not.be.empty;
- expect(answer.data).to.be.a('string');
- expect(answer.data).to.include('BEGIN PGP MESSAGE');
- expect(answer.data).to.include('END PGP MESSAGE');
- done();
- });
+ it('Successful encrypt', function (done) {
+ const data = inputvalues.encrypt.good.data;
+ context.encrypt(data, good_fpr).then(function (answer) {
+ expect(answer).to.not.be.empty;
+ expect(answer.data).to.be.a('string');
+ expect(answer.data).to.include('BEGIN PGP MESSAGE');
+ expect(answer.data).to.include('END PGP MESSAGE');
+ done();
});
- }).timeout(20000);
+ });
- it('Successful encrypt 50 MB', function (done) {
- let prm = Gpgmejs.init();
- let data = fixedLengthString(50);
- prm.then(function (context) {
- context.encrypt(
- data,
- inputvalues.encrypt.good.fingerprint).then(function (answer) {
+ const sizes = [5,20,50];
+ for (let i=0; i < sizes.length; i++) {
+ it('Successful encrypt a ' + sizes[i] + 'MB message', function (done) {
+ const data = fixedLengthString(sizes[i]);
+ context.encrypt(data, good_fpr).then(function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a('string');
expect(answer.data).to.include('BEGIN PGP MESSAGE');
expect(answer.data).to.include('END PGP MESSAGE');
done();
});
- });
- }).timeout(20000);
+ }).timeout(20000);
+ }
it('Sending encryption without keys fails', function (done) {
- let prm = Gpgmejs.init();
- prm.then(function (context) {
- context.encrypt(
- inputvalues.encrypt.good.data,
- null).then(function (answer) {
- expect(answer).to.be.undefined;
- }, function(error){
- expect(error).to.be.an('Error');
- expect(error.code).to.equal('MSG_INCOMPLETE');
- done();
- });
+ const data = inputvalues.encrypt.good.data;
+ context.encrypt(data,null).then(function (answer) {
+ expect(answer).to.be.undefined;
+ }, function(error){
+ expect(error).to.be.an('Error');
+ expect(error.code).to.equal('MSG_INCOMPLETE');
+ done();
});
});
it('Sending encryption without data fails', function (done) {
- let prm = Gpgmejs.init();
- prm.then(function (context) {
- context.encrypt(
- null, inputvalues.encrypt.good.keyid).then(function (answer) {
- expect(answer).to.be.undefined;
- }, function (error) {
- expect(error).to.be.an.instanceof(Error);
- expect(error.code).to.equal('MSG_INCOMPLETE');
- done();
- });
+ context.encrypt(null, good_fpr).then(function (answer) {
+ expect(answer).to.be.undefined;
+ }, function (error) {
+ expect(error).to.be.an.instanceof(Error);
+ expect(error.code).to.equal('MSG_INCOMPLETE');
+ done();
});
});
it('Sending encryption with non existing keys fails', function (done) {
- let prm = Gpgmejs.init();
- prm.then(function (context) {
- context.encrypt(
- inputvalues.encrypt.good.data,
- inputvalues.encrypt.bad.fingerprint).then(function (answer) {
- expect(answer).to.be.undefined;
- }, function(error){
- expect(error).to.be.an('Error');
- expect(error.code).to.not.be.undefined;
- expect(error.code).to.equal('GNUPG_ERROR');
- done();
- });
+ const data = inputvalues.encrypt.good.data;
+ const bad_fpr = inputvalues.encrypt.bad.fingerprint;
+ context.encrypt(data, bad_fpr).then(function (answer) {
+ expect(answer).to.be.undefined;
+ }, function(error){
+ expect(error).to.be.an('Error');
+ expect(error.code).to.not.be.undefined;
+ expect(error.code).to.equal('GNUPG_ERROR');
+ done();
});
}).timeout(5000);
it('Overly large message ( > 64MB) is rejected', function (done) {
- let prm = Gpgmejs.init();
- prm.then(function (context) {
- context.encrypt(
- fixedLengthString(65),
- inputvalues.encrypt.good.fingerprint).then(function (answer) {
- expect(answer).to.be.undefined;
- }, function(error){
- expect(error).to.be.an.instanceof(Error);
- // TODO: there is a 64 MB hard limit at least in chrome at:
- // chromium//extensions/renderer/messaging_util.cc:
- // kMaxMessageLength
- // The error will be a browser error, not from gnupg or from
- // this library
- done();
- });
+ const data = fixedLengthString(65);
+ context.encrypt(data, good_fpr).then(function (answer) {
+ expect(answer).to.be.undefined;
+ }, function(error){
+ expect(error).to.be.an.instanceof(Error);
+ // TODO: there is a 64 MB hard limit at least in chrome at:
+ // chromium//extensions/renderer/messaging_util.cc:
+ // kMaxMessageLength
+ // The error will be a browser error, not from gnupg or from
+ // this library
+ done();
});
}).timeout(8000);