diff options
Diffstat (limited to 'lang/js/BrowserTestExtension/tests')
-rw-r--r-- | lang/js/BrowserTestExtension/tests/KeyImportExport.js | 35 | ||||
-rw-r--r-- | lang/js/BrowserTestExtension/tests/KeyInfos.js | 2 | ||||
-rw-r--r-- | lang/js/BrowserTestExtension/tests/decryptTest.js | 23 | ||||
-rw-r--r-- | lang/js/BrowserTestExtension/tests/encryptDecryptTest.js | 160 | ||||
-rw-r--r-- | lang/js/BrowserTestExtension/tests/encryptTest.js | 87 | ||||
-rw-r--r-- | lang/js/BrowserTestExtension/tests/longRunningTests.js | 24 | ||||
-rw-r--r-- | lang/js/BrowserTestExtension/tests/signTest.js | 19 | ||||
-rw-r--r-- | lang/js/BrowserTestExtension/tests/verifyTest.js | 40 |
8 files changed, 204 insertions, 186 deletions
diff --git a/lang/js/BrowserTestExtension/tests/KeyImportExport.js b/lang/js/BrowserTestExtension/tests/KeyImportExport.js index f52b790a..f57877f4 100644 --- a/lang/js/BrowserTestExtension/tests/KeyImportExport.js +++ b/lang/js/BrowserTestExtension/tests/KeyImportExport.js @@ -35,7 +35,7 @@ describe('Key importing', function () { const prm = Gpgmejs.init(); prm.then(function (gpgmejs){ context = gpgmejs; - context.Keyring.getKeys(fpr).then( + context.Keyring.getKeys({ pattern: fpr }).then( function (result){ if (result.length === 1) { result[0].delete().then(function (){ @@ -52,7 +52,7 @@ describe('Key importing', function () { afterEach(function (done){ // delete the test key if still present - context.Keyring.getKeys(fpr).then( + context.Keyring.getKeys({ pattern: fpr }).then( function (result){ if (result.length === 1) { result[0].delete().then(function (){ @@ -67,7 +67,7 @@ describe('Key importing', function () { }); it('Importing Key', function (done) { - context.Keyring.getKeys(fpr).then(function (result){ + context.Keyring.getKeys({ pattern: fpr }).then(function (result){ expect(result).to.be.an('array'); expect(result.length).to.equal(0); context.Keyring.importKey(pubKey).then(function (result){ @@ -127,23 +127,26 @@ describe('Key importing', function () { it('exporting armored Key with getKeysArmored', function (done) { context.Keyring.importKey(pubKey).then(function (){ - context.Keyring.getKeysArmored(fpr).then(function (result){ - expect(result).to.be.an('object'); - expect(result.armored).to.be.a('string'); - expect(result.secret_fprs).to.be.undefined; - done(); - }); + context.Keyring.getKeysArmored({ pattern: fpr }) + .then(function (result){ + expect(result).to.be.an('object'); + expect(result.armored).to.be.a('string'); + expect(result.secret_fprs).to.be.undefined; + done(); + }); }); }); it('Exporting Key (including secret fingerprints)', function (done) { const key_secret = inputvalues.encrypt.good.fingerprint; - context.Keyring.getKeysArmored(key_secret, true).then(function (result){ - expect(result).to.be.an('object'); - expect(result.armored).to.be.a('string'); - expect(result.secret_fprs).to.be.an('array'); - expect(result.secret_fprs[0]).to.equal(key_secret); - done(); - }); + context.Keyring.getKeysArmored({ + pattern: key_secret, with_secret_fpr: true }) + .then(function (result){ + expect(result).to.be.an('object'); + expect(result.armored).to.be.a('string'); + expect(result.secret_fprs).to.be.an('array'); + expect(result.secret_fprs[0]).to.equal(key_secret); + done(); + }); }); });
\ No newline at end of file diff --git a/lang/js/BrowserTestExtension/tests/KeyInfos.js b/lang/js/BrowserTestExtension/tests/KeyInfos.js index e1caabe1..430c83a3 100644 --- a/lang/js/BrowserTestExtension/tests/KeyInfos.js +++ b/lang/js/BrowserTestExtension/tests/KeyInfos.js @@ -36,7 +36,7 @@ describe('Key information', function () { it('A fingerprint is consistently returned upper case hex', function (done){ const mixedCase = inputvalues.encrypt.good.fingerprint_mixedcase; - context.Keyring.getKeys(mixedCase).then(function (result){ + context.Keyring.getKeys({ pattern: mixedCase }).then(function (result){ expect(result).to.be.an('array'); expect(result.length).to.equal(1); expect(result[0].fingerprint).to.equal(mixedCase.toUpperCase()); diff --git a/lang/js/BrowserTestExtension/tests/decryptTest.js b/lang/js/BrowserTestExtension/tests/decryptTest.js index ea887491..8852cb6a 100644 --- a/lang/js/BrowserTestExtension/tests/decryptTest.js +++ b/lang/js/BrowserTestExtension/tests/decryptTest.js @@ -38,7 +38,7 @@ describe('Decryption', function () { it('Decryption of random string fails', function (done) { let data = bigString(20 * 1024); - context.decrypt(data).then( + context.decrypt({ data: data }).then( function (){}, function (error){ expect(error).to.be.an('error'); @@ -49,21 +49,22 @@ describe('Decryption', function () { it('Decryption of slightly corrupted message fails', function (done) { const data = bigString(10000); - context.encrypt(data, good_fpr).then(function (enc){ - context.decrypt(sabotageMsg(enc.data)).then( - function (){}, - function (error){ - expect(error).to.be.an('error'); - expect(error.code).to.equal('GNUPG_ERROR'); - done(); - }); - }); + context.encrypt({ data: data, publicKeys:good_fpr }).then( + function (enc){ + context.decrypt({ data: sabotageMsg(enc.data) }).then( + function (){}, + function (error){ + expect(error).to.be.an('error'); + expect(error.code).to.equal('GNUPG_ERROR'); + done(); + }); + }); }).timeout(5000); it('decrypt/verify operations return proper information', function (done){ const data = inputvalues.encryptSignedMessage; - context.decrypt(data).then(function (result){ + context.decrypt({ data: data }).then(function (result){ expect(result).to.be.an('object'); expect(result.signatures).to.be.an('object'); expect(result.signatures.all_valid).to.be.true; diff --git a/lang/js/BrowserTestExtension/tests/encryptDecryptTest.js b/lang/js/BrowserTestExtension/tests/encryptDecryptTest.js index 28c98d98..1efdf5cf 100644 --- a/lang/js/BrowserTestExtension/tests/encryptDecryptTest.js +++ b/lang/js/BrowserTestExtension/tests/encryptDecryptTest.js @@ -38,25 +38,25 @@ describe('Encryption and Decryption', function (){ it('Successful encrypt and decrypt simple string', function (done) { let 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'); - - context.decrypt(answer.data).then(function (result) { - expect(result).to.not.be.empty; - expect(result.data).to.be.a('string'); - expect(result.data).to.equal( - inputvalues.encrypt.good.data); - done(); + context.encrypt({ data: data, publicKeys: 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'); + context.decrypt({ data: answer.data }).then(function (result) { + expect(result).to.not.be.empty; + expect(result.data).to.be.a('string'); + expect(result.data).to.equal( + inputvalues.encrypt.good.data); + done(); + }); }); - }); }); it('Decrypt simple non-ascii', function (done) { let data = encryptedData; - context.decrypt(data).then(function (result) { + context.decrypt({ data: data }).then(function (result) { expect(result).to.not.be.empty; expect(result.data).to.be.a('string'); expect(result.data).to.equal( @@ -67,77 +67,81 @@ describe('Encryption and Decryption', function (){ it('Trailing whitespace and different line endings', function (done) { const data = 'Keks. \rKeks \n Keks \r\n'; - 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'); + context.encrypt({ data: data, publicKeys: 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'); - context.decrypt(answer.data).then(function (result) { - expect(result).to.not.be.empty; - expect(result.data).to.be.a('string'); - expect(result.data).to.equal(data); - done(); + context.decrypt({ data: answer.data }).then(function (result) { + expect(result).to.not.be.empty; + expect(result.data).to.be.a('string'); + expect(result.data).to.equal(data); + done(); + }); }); - }); }).timeout(5000); it('Random data, as string', function (done) { let data = bigString(1000); - 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'); - context.decrypt(answer.data).then(function (result) { - expect(result).to.not.be.empty; - expect(result.data).to.be.a('string'); - expect(result.data).to.equal(data); - done(); + context.encrypt({ data:data, publicKeys: 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'); + context.decrypt({ data: answer.data }).then(function (result) { + expect(result).to.not.be.empty; + expect(result.data).to.be.a('string'); + expect(result.data).to.equal(data); + done(); + }); }); - }); }).timeout(3000); it('Data, input as base64', function (done) { let data = inputvalues.encrypt.good.data; let b64data = btoa(data); - context.encrypt(b64data, good_fpr, true).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'); - context.decrypt(answer.data).then( - function (result) { + context.encrypt({ data: b64data, publicKeys: good_fpr, base64: true }) + .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'); + context.decrypt({ data: answer.data }).then(function (result) { expect(result).to.not.be.empty; expect(result.data).to.be.a('string'); - expect(data).to.equal(data); + expect(result.data).to.equal(data); done(); }); - }); + }); }).timeout(3000); it('Random data, input as base64', function (done) { let data = bigBoringString(0.001); let b64data = btoa(data); - context.encrypt(b64data, good_fpr, true).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'); - context.decrypt(answer.data).then( - function (result) { - expect(result).to.not.be.empty; - expect(result.data).to.be.a('string'); - expect(result.data).to.equal(b64data); - done(); - }); - }); + context.encrypt( + { data: b64data, publicKeys: good_fpr, base64: true }) + .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'); + context.decrypt({ data:answer.data }).then( + function (result) { + expect(result).to.not.be.empty; + expect(result.data).to.be.a('string'); + expect(result.data).to.equal(data); + done(); + }); + }); }).timeout(3000); for (let j = 0; j < inputvalues.encrypt.good.data_nonascii_32.length; j++){ @@ -151,20 +155,22 @@ describe('Encryption and Decryption', function (){ for (let i=0; i < 34 * 1024; i++){ data += input; } - 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'); - context.decrypt(answer.data).then(function (result) { - expect(result).to.not.be.empty; - expect(result.data).to.be.a('string'); - expect(result.data).to.equal(data); - done(); + context.encrypt({ data: data, publicKeys: 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'); + context.decrypt({ data: answer.data }) + .then(function (result) { + expect(result).to.not.be.empty; + expect(result.data).to.be.a('string'); + expect(result.data).to.equal(data); + done(); + }); }); - }); }).timeout(5000); } }); diff --git a/lang/js/BrowserTestExtension/tests/encryptTest.js b/lang/js/BrowserTestExtension/tests/encryptTest.js index a242af5f..ccdb4994 100644 --- a/lang/js/BrowserTestExtension/tests/encryptTest.js +++ b/lang/js/BrowserTestExtension/tests/encryptTest.js @@ -37,32 +37,34 @@ describe('Encryption', function () { 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(); - }); - }); - - 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) { + context.encrypt({ data: data, publicKeys: 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(); }); + }); + + 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: data, publicKeys: 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('Sending encryption without keys fails', function (done) { const data = inputvalues.encrypt.good.data; - context.encrypt(data,null).then(function (answer) { + context.encrypt({ data: data }).then(function (answer) { expect(answer).to.be.undefined; }, function (error){ expect(error).to.be.an('Error'); @@ -72,41 +74,44 @@ describe('Encryption', function () { }); it('Sending encryption without data fails', function (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(); - }); + context.encrypt({ data: null, publicKeys: 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) { 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(); - }); + context.encrypt({ data:data, publicKeys: 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) { 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(); - }); + context.encrypt({ data: data, publicKeys: 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); // TODO check different valid parameter diff --git a/lang/js/BrowserTestExtension/tests/longRunningTests.js b/lang/js/BrowserTestExtension/tests/longRunningTests.js index 240a6b93..1d710e31 100644 --- a/lang/js/BrowserTestExtension/tests/longRunningTests.js +++ b/lang/js/BrowserTestExtension/tests/longRunningTests.js @@ -38,18 +38,20 @@ describe('Long running Encryption/Decryption', function () { it('Successful encrypt/decrypt completely random data ' + (i+1) + '/100', function (done) { const data = bigString(2*1024*1024); - 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'); - context.decrypt(answer.data).then(function (result){ - expect(result).to.not.be.empty; - expect(result.data).to.be.a('string'); - expect(result.data).to.equal(data); - done(); + context.encrypt({ data: data, publicKeys: 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'); + context.decrypt({ data: answer.data }) + .then(function (result){ + expect(result).to.not.be.empty; + expect(result.data).to.be.a('string'); + expect(result.data).to.equal(data); + done(); + }); }); - }); }).timeout(15000); } diff --git a/lang/js/BrowserTestExtension/tests/signTest.js b/lang/js/BrowserTestExtension/tests/signTest.js index f5bd9c1d..bd8db807 100644 --- a/lang/js/BrowserTestExtension/tests/signTest.js +++ b/lang/js/BrowserTestExtension/tests/signTest.js @@ -38,7 +38,7 @@ describe('Signing', function () { it('Sign a message', function (done) { const data = bigString(100); - context.sign(data, good_fpr).then(function (answer) { + context.sign({ data: data, keys: 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 SIGNATURE'); @@ -50,14 +50,15 @@ describe('Signing', function () { it('Detached sign a message', function (done) { const data = bigString(100); - context.sign(data,good_fpr, 'detached').then(function (answer) { - expect(answer).to.not.be.empty; - expect(answer.data).to.be.a('string'); - expect(answer.data).to.include(data); - expect(answer.signature).to.be.a('string'); - expect(answer.signature).to.be.a('string'); - done(); - }); + context.sign({ data: data, keys: good_fpr, mode: 'detached' }) + .then(function (answer) { + expect(answer).to.not.be.empty; + expect(answer.data).to.be.a('string'); + expect(answer.data).to.include(data); + expect(answer.signature).to.be.a('string'); + expect(answer.signature).to.be.a('string'); + done(); + }); }); }); diff --git a/lang/js/BrowserTestExtension/tests/verifyTest.js b/lang/js/BrowserTestExtension/tests/verifyTest.js index 5788ed51..04c7a77a 100644 --- a/lang/js/BrowserTestExtension/tests/verifyTest.js +++ b/lang/js/BrowserTestExtension/tests/verifyTest.js @@ -36,7 +36,7 @@ describe('Verifying data', function () { }); it('Successful verify message', function (done) { const message = inputvalues.signedMessage.good; - context.verify(message).then(function (result){ + context.verify({ data: message }).then(function (result){ expect(result.data).to.be.a('string'); expect(result.signatures.all_valid).to.be.true; expect(result.signatures.count).to.equal(1); @@ -50,7 +50,7 @@ describe('Verifying data', function () { it('Successfully recognize changed cleartext', function (done) { const message = inputvalues.signedMessage.bad; - context.verify(message).then(function (result){ + context.verify({ data: message }).then(function (result){ expect(result.data).to.be.a('string'); expect(result.signatures.all_valid).to.be.false; expect(result.signatures.count).to.equal(1); @@ -67,24 +67,24 @@ describe('Verifying data', function () { it('Encrypt-Sign-Verify random message', function (done) { const message = bigString(2000); let fpr = inputvalues.encrypt.good.fingerprint; - context.encrypt(message, fpr).then(function (message_enc){ - context.sign(message_enc.data, fpr).then(function (message_encsign){ - context.verify(message_encsign.data).then(function (result){ - expect(result.data).to.equal(message_enc.data); - expect(result.data).to.be.a('string'); - expect(result.signatures.all_valid).to.be.true; - expect(result.signatures.count).to.equal(1); - expect(result.signatures.signatures.good) - .to.be.an('array'); - expect(result.signatures.signatures.good.length) - .to.equal(1); - expect(result.signatures.signatures.good[0].fingerprint) - .to.equal(fpr); - expect(result.signatures.signatures.good[0].valid) - .to.be.true; - done(); - }); + context.encrypt({ data: message, publicKeys: fpr }) + .then(function (message_enc){ + context.sign({ data: message_enc.data, keys: fpr }) + .then(function (message_encsign){ + context.verify({ data: message_encsign.data }) + .then(function (result){ + expect(result.data).to.equal(message_enc.data); + expect(result.data).to.be.a('string'); + expect(result.signatures.all_valid).to.be.true; + expect(result.signatures.count).to.equal(1); + const arr = result.signatures.signatures.good; + expect(arr).to.be.an('array'); + expect(arr.length).to.equal(1); + expect(arr[0].fingerprint).to.equal(fpr); + expect(arr[0].valid).to.be.true; + done(); + }); + }); }); - }); }); });
\ No newline at end of file |