From 8f01d4b0b521e0b78abf4f27ff79dde9c0ceab46 Mon Sep 17 00:00:00 2001 From: Sanjana Rajan Date: Wed, 1 Aug 2018 17:47:07 +0300 Subject: [PATCH] clean up tests --- test/general/brainpool.js | 26 +++++++++++++------------- test/general/ecc_nist.js | 25 +++++++++++++------------ test/general/openpgp.js | 4 ++-- test/general/x25519.js | 20 ++++++++++---------- 4 files changed, 38 insertions(+), 37 deletions(-) diff --git a/test/general/brainpool.js b/test/general/brainpool.js index 627a8907..fa088841 100644 --- a/test/general/brainpool.js +++ b/test/general/brainpool.js @@ -55,7 +55,7 @@ describe('Brainpool Cryptography', function () { '=uGZP', '-----END PGP PRIVATE KEY BLOCK-----' ].join('\n'), - message: 'test message', + message: 'test message\n', message_encrypted: [ '-----BEGIN PGP MESSAGE-----', '', @@ -110,18 +110,19 @@ describe('Brainpool Cryptography', function () { '=3Dct', '-----END PGP PRIVATE KEY BLOCK-----' ].join('\n'), - message: 'second test message', + message: 'second test message\n', message_signed: [ '-----BEGIN PGP SIGNED MESSAGE-----', 'Hash: SHA512', '', 'second test message', + '', '-----BEGIN PGP SIGNATURE-----', '', - 'iHUEARMKAB0WIQQi1GdXVRHGK/mAm7434WqYa4r5ngUCWq8vXQAKCRA34WqYa4r5', - 'nuLcAP9PvP2XRqhybqRLwa2OCKyAOmUogvx/xLWDwT4HYQDurwD/dnhMrzBQ6kJg', - 'jpFFbWyAqJavhedwBsFXCUoLH0/BA8w=', - '=XwF/', + 'wl4EARMKABAFAltbE34JEDfhaphrivmeAABaXQD+LzOhFxTqz8+IcaD3xzww', + 'EjEn0u7qgCFem9PHPD4wqAcA/1WQE3N7DIwRG45HFd+ZBo4vcuRkWK+Q6CHl', + 'upbAEX7k', + '=obwy', '-----END PGP SIGNATURE-----' ].join('\n') } @@ -166,20 +167,20 @@ describe('Brainpool Cryptography', function () { const msg = openpgp.cleartext.readArmored(data.juliet.message_signed); return openpgp.verify({publicKeys: [pub], message: msg}).then(function(result) { expect(result).to.exist; - expect(result.data.trim()).to.equal(data.juliet.message); + expect(result.data).to.equal(data.juliet.message); expect(result.signatures).to.have.length(1); expect(result.signatures[0].valid).to.be.true; }); }); it('Sign message', async function () { const romeoPrivate = await load_priv_key('romeo'); - const signed = await openpgp.sign({privateKeys: [romeoPrivate], data: data.romeo.message + "\n"}); + const signed = await openpgp.sign({privateKeys: [romeoPrivate], data: data.romeo.message}); const romeoPublic = load_pub_key('romeo'); const msg = openpgp.cleartext.readArmored(signed.data); const result = await openpgp.verify({publicKeys: [romeoPublic], message: msg}); expect(result).to.exist; - expect(result.data.trim()).to.equal(data.romeo.message); + expect(result.data).to.equal(data.romeo.message); expect(result.signatures).to.have.length(1); expect(result.signatures[0].valid).to.be.true; }); @@ -190,15 +191,14 @@ describe('Brainpool Cryptography', function () { const result = await openpgp.decrypt({privateKeys: romeo, publicKeys: [juliet], message: msg}); expect(result).to.exist; - // trim required because https://github.com/openpgpjs/openpgpjs/issues/311 - expect(result.data.trim()).to.equal(data.romeo.message); + expect(result.data).to.equal(data.romeo.message); expect(result.signatures).to.have.length(1); expect(result.signatures[0].valid).to.be.true; }); it('Encrypt and sign message', async function () { const romeoPrivate = await load_priv_key('romeo'); const julietPublic = load_pub_key('juliet'); - const encrypted = await openpgp.encrypt({publicKeys: [julietPublic], privateKeys: [romeoPrivate], data: data.romeo.message + "\n"}); + const encrypted = await openpgp.encrypt({publicKeys: [julietPublic], privateKeys: [romeoPrivate], data: data.romeo.message}); const message = openpgp.message.readArmored(encrypted.data); const romeoPublic = load_pub_key('romeo'); @@ -206,7 +206,7 @@ describe('Brainpool Cryptography', function () { const result = await openpgp.decrypt({privateKeys: julietPrivate, publicKeys: [romeoPublic], message: message}); expect(result).to.exist; - expect(result.data.trim()).to.equal(data.romeo.message); + expect(result.data).to.equal(data.romeo.message); expect(result.signatures).to.have.length(1); expect(result.signatures[0].valid).to.be.true; }); diff --git a/test/general/ecc_nist.js b/test/general/ecc_nist.js index 89c27fdd..b83e6527 100644 --- a/test/general/ecc_nist.js +++ b/test/general/ecc_nist.js @@ -53,7 +53,7 @@ describe('Elliptic Curve Cryptography', function () { '=C3TW', '-----END PGP PRIVATE KEY BLOCK-----' ].join('\n'), - message: 'Shall I hear more, or shall I speak at this?' + message: 'Shall I hear more, or shall I speak at this?\n' }, juliet: { id: '64116021959bdfe0', @@ -98,19 +98,21 @@ describe('Elliptic Curve Cryptography', function () { '=QvXN', '-----END PGP PRIVATE KEY BLOCK-----' ].join('\n'), - message: 'O Romeo, Romeo! Wherefore art thou Romeo?', + message: 'O Romeo, Romeo! Wherefore art thou Romeo?\n', message_signed: [ '-----BEGIN PGP SIGNED MESSAGE-----', 'Hash: SHA256', '', 'O Romeo, Romeo! Wherefore art thou Romeo?', + '', '-----BEGIN PGP SIGNATURE-----', 'Version: GnuPG v2', 'Comment: GnuPG v2.1+libgcrypt-1.7', '', - 'iF4EARMIAAYFAlYxF8oACgkQZBFgIZWb3+BfTwD/b1yKtFnKrRjELuD6/gOH9/er', - '6yc7nzn1FBYFzMz8aFIA/3FlcIvR+eLvRTVmfiEatB6IU6JviBnzxR1gA/SOdyS2', - '=GCiR', + 'wl4EARMIABAFAltbFFMJEGQRYCGVm9/gAAAjugD/W/OZ++qiNlhy08OOflAN', + 'rjjX3rknSZyUkr96HD4VWVsBAPL9QjyHI3714cdkQmwYGiG8TVrtPetnqHho', + 'Ppmby7/I', + '=IyBz', '-----END PGP SIGNATURE-----' ].join('\n'), message_encrypted: [ @@ -177,20 +179,20 @@ describe('Elliptic Curve Cryptography', function () { const msg = openpgp.cleartext.readArmored(data.juliet.message_signed); return openpgp.verify({publicKeys: [pub], message: msg}).then(function(result) { expect(result).to.exist; - expect(result.data.trim()).to.equal(data.juliet.message); + expect(result.data).to.equal(data.juliet.message); expect(result.signatures).to.have.length(1); expect(result.signatures[0].valid).to.be.true; }); }); it('Sign message', async function () { const romeoPrivate = await load_priv_key('romeo'); - const signed = await openpgp.sign({privateKeys: [romeoPrivate], data: data.romeo.message + "\n"}); + const signed = await openpgp.sign({privateKeys: [romeoPrivate], data: data.romeo.message}); const romeoPublic = load_pub_key('romeo'); const msg = openpgp.cleartext.readArmored(signed.data); const result = await openpgp.verify({publicKeys: [romeoPublic], message: msg}); expect(result).to.exist; - expect(result.data.trim()).to.equal(data.romeo.message); + expect(result.data).to.equal(data.romeo.message); expect(result.signatures).to.have.length(1); expect(result.signatures[0].valid).to.be.true; }); @@ -201,15 +203,14 @@ describe('Elliptic Curve Cryptography', function () { const result = await openpgp.decrypt({privateKeys: romeo, publicKeys: [juliet], message: msg}); expect(result).to.exist; - // trim required because https://github.com/openpgpjs/openpgpjs/issues/311 - expect(result.data.trim()).to.equal(data.juliet.message); + expect(result.data).to.equal(data.juliet.message); expect(result.signatures).to.have.length(1); expect(result.signatures[0].valid).to.be.true; }); it('Encrypt and sign message', async function () { const romeoPrivate = await load_priv_key('romeo'); const julietPublic = load_pub_key('juliet'); - const encrypted = await openpgp.encrypt({publicKeys: [julietPublic], privateKeys: [romeoPrivate], data: data.romeo.message + "\n"}); + const encrypted = await openpgp.encrypt({publicKeys: [julietPublic], privateKeys: [romeoPrivate], data: data.romeo.message}); const message = openpgp.message.readArmored(encrypted.data); const romeoPublic = load_pub_key('romeo'); @@ -217,7 +218,7 @@ describe('Elliptic Curve Cryptography', function () { const result = await openpgp.decrypt({privateKeys: julietPrivate, publicKeys: [romeoPublic], message: message}); expect(result).to.exist; - expect(result.data.trim()).to.equal(data.romeo.message); + expect(result.data).to.equal(data.romeo.message); expect(result.signatures).to.have.length(1); expect(result.signatures[0].valid).to.be.true; }); diff --git a/test/general/openpgp.js b/test/general/openpgp.js index fee80aa7..668e7eee 100644 --- a/test/general/openpgp.js +++ b/test/general/openpgp.js @@ -287,7 +287,7 @@ DECl1Qu4QyeXin29uEXWiekMpNlZVsEuc8icCw6ABhIZ -----END PGP PRIVATE KEY BLOCK-----`; const passphrase = 'hello world'; -const plaintext = input.createSomeMessage() + '\n한국어/조선말'; +const plaintext = input.createSomeMessage(); const password1 = 'I am a password'; const password2 = 'I am another password'; const password3 = 'I am a third password'; @@ -756,7 +756,7 @@ describe('OpenPGP.js public api tests', function() { openpgp.initWorker({path: '../dist/openpgp.worker.js', workers, n: 2}); const workerTest = (_, index) => { - const plaintext = input.createSomeMessage() + index + '\n한국어/조선말'; + const plaintext = input.createSomeMessage() + index; return openpgp.encrypt({ publicKeys: publicKey.keys, data: plaintext diff --git a/test/general/x25519.js b/test/general/x25519.js index f2e7c817..1ee36bc5 100644 --- a/test/general/x25519.js +++ b/test/general/x25519.js @@ -46,18 +46,19 @@ describe('X25519 Cryptography', function () { '=wo91', '-----END PGP PRIVATE KEY BLOCK-----' ].join('\n'), - message: 'Hi, Light wrote this!', + message: 'Hi, Light wrote this!\n', message_signed: [ '-----BEGIN PGP SIGNED MESSAGE-----', - 'Hash: SHA256', + 'Hash: SHA512', '', 'Hi, Light wrote this!', + '', '-----BEGIN PGP SIGNATURE-----', '', - 'iIAEARYIACgWIQSGS0GuVELT3Rs0wocezfAmwCRYMAUCWkyVkAocbGlnaHRAc3Vu', - 'AAoJEB7N8CbAJFgwdqAA/RwTsy9Nt5HEJLnokUNgHVX8wNr7Ef9wfAG1RaMgMMWs', - 'AP9KEEohpHqaj8smb1oLjYU9DgOugE40LrkujvnWNbOZBQ==', - '=T9p+', + 'wl4EARYKABAFAltbFNAJEB7N8CbAJFgwAAAhcAEA5b2MIQNxQYj8TAMyuhZJ', + 'UvxEgPS8DU59Kxw5F9+oldQBAN4mA+SOJyTxEx4oyyLh+8RD27dqyeDpmXju', + 'xqMRN8oE', + '=siSU', '-----END PGP SIGNATURE-----' ].join('\n') }, @@ -97,7 +98,7 @@ describe('X25519 Cryptography', function () { '=NDSU', '-----END PGP PRIVATE KEY BLOCK-----' ].join('\n'), - message: 'Oh hi, this is a private message from Light to Night!', + message: 'Oh hi, this is a private message from Light to Night!\n', message_encrypted: [ '-----BEGIN PGP MESSAGE-----', '', @@ -162,7 +163,7 @@ describe('X25519 Cryptography', function () { const msg = openpgp.cleartext.readArmored(data[name].message_signed); return openpgp.verify({ publicKeys: [pub], message: msg }).then(function(result) { expect(result).to.exist; - expect(result.data.trim()).to.equal(data[name].message); + expect(result.data).to.equal(data[name].message); expect(result.signatures).to.have.length(1); expect(result.signatures[0].valid).to.be.true; }); @@ -190,8 +191,7 @@ describe('X25519 Cryptography', function () { const result = await openpgp.decrypt({ privateKeys: night, publicKeys: [light], message: msg }); expect(result).to.exist; - // trim required because https://github.com/openpgpjs/openpgpjs/issues/311 - expect(result.data.trim()).to.equal(data.night.message); + expect(result.data).to.equal(data.night.message); expect(result.signatures).to.have.length(1); expect(result.signatures[0].valid).to.be.true; });