From 652a0b96a242859b5a6dce72fe49984923388f96 Mon Sep 17 00:00:00 2001 From: Ali Groening <ali.groening@gmail.com> Date: Fri, 6 Oct 2017 11:20:11 -0700 Subject: [PATCH 1/2] test: update test messages for assert.strictEqual --- test/parallel/test-crypto-cipher-decipher.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/parallel/test-crypto-cipher-decipher.js b/test/parallel/test-crypto-cipher-decipher.js index 336ab3a07ba42e..295efab6d44be8 100644 --- a/test/parallel/test-crypto-cipher-decipher.js +++ b/test/parallel/test-crypto-cipher-decipher.js @@ -25,7 +25,7 @@ function testCipher1(key) { let txt = decipher.update(ciph, 'hex', 'utf8'); txt += decipher.final('utf8'); - assert.strictEqual(txt, plaintext, 'encryption and decryption'); + assert.strictEqual(txt, plaintext, `${txt} is encrypted, ${plaintext} is unencrypted`); // streaming cipher interface // NB: In real life, it's not guaranteed that you can get all of it @@ -39,7 +39,7 @@ function testCipher1(key) { dStream.end(ciph); txt = dStream.read().toString('utf8'); - assert.strictEqual(txt, plaintext, 'encryption and decryption with streams'); + assert.strictEqual(txt, plaintext, `${txt} is the deciphered stream of ${ciph}`); } @@ -61,7 +61,7 @@ function testCipher2(key) { let txt = decipher.update(ciph, 'base64', 'utf8'); txt += decipher.final('utf8'); - assert.strictEqual(txt, plaintext, 'encryption and decryption with Base64'); + assert.strictEqual(txt, plaintext, `${txt} is the decryption with Base64, ${plaintext} is the encryption`); } testCipher1('MySecretKey123'); @@ -74,7 +74,7 @@ testCipher2(Buffer.from('0123456789abcdef')); { const c = crypto.createCipher('aes-256-cbc', 'secret'); const s = c.update('test', 'utf8', 'base64') + c.final('base64'); - assert.strictEqual(s, '375oxUQCIocvxmC5At+rvA=='); + assert.strictEqual(s, '375oxUQCIocvxmC5At+rvA==', `${s} is updated to be base64 instead utf8`); } // Calling Cipher.final() or Decipher.final() twice should error but @@ -125,17 +125,17 @@ testCipher2(Buffer.from('0123456789abcdef')); let txt; assert.doesNotThrow(() => txt = decipher.update(ciph, 'base64', 'ucs2')); assert.doesNotThrow(() => txt += decipher.final('ucs2')); - assert.strictEqual(txt, plaintext, 'decrypted result in ucs2'); + assert.strictEqual(txt, plaintext, `${plaintext} has decrypted ${txt} in ucs2`); decipher = crypto.createDecipher('aes192', key); assert.doesNotThrow(() => txt = decipher.update(ciph, 'base64', 'ucs-2')); assert.doesNotThrow(() => txt += decipher.final('ucs-2')); - assert.strictEqual(txt, plaintext, 'decrypted result in ucs-2'); + assert.strictEqual(txt, plaintext, `${plaintext} has decrypted ${txt} in ucs-2`); decipher = crypto.createDecipher('aes192', key); assert.doesNotThrow(() => txt = decipher.update(ciph, 'base64', 'utf-16le')); assert.doesNotThrow(() => txt += decipher.final('utf-16le')); - assert.strictEqual(txt, plaintext, 'decrypted result in utf-16le'); + assert.strictEqual(txt, plaintext, `${plaintext} decrypted ${txt} in utf-16le`); } // setAutoPadding/setAuthTag/setAAD should return `this` @@ -144,9 +144,9 @@ testCipher2(Buffer.from('0123456789abcdef')); const tagbuf = Buffer.from('tagbuf'); const aadbuf = Buffer.from('aadbuf'); const decipher = crypto.createDecipher('aes-256-gcm', key); - assert.strictEqual(decipher.setAutoPadding(), decipher); - assert.strictEqual(decipher.setAuthTag(tagbuf), decipher); - assert.strictEqual(decipher.setAAD(aadbuf), decipher); + assert.strictEqual(decipher.setAutoPadding(), decipher, `${decipher} will be set to the appropriate block size with autopadding`); + assert.strictEqual(decipher.setAuthTag(tagbuf), decipher, `${tagbuf} is the a authenticated tag of ${decipher}`); + assert.strictEqual(decipher.setAAD(aadbuf), decipher, `${decipher} has set the additional authenticated data param for ${aadbuf}`); } // error throwing in setAAD/setAuthTag/getAuthTag/setAutoPadding From 646e0c78c18a105fac4e59a69c4ae472d30f1784 Mon Sep 17 00:00:00 2001 From: Ali Groening <ali.groening@gmail.com> Date: Fri, 13 Oct 2017 18:04:24 -0700 Subject: [PATCH 2/2] test: remove test messages for assert.strictEqual, as the default messages are a better option --- test/parallel/test-crypto-cipher-decipher.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/parallel/test-crypto-cipher-decipher.js b/test/parallel/test-crypto-cipher-decipher.js index 295efab6d44be8..c1f1d84b797810 100644 --- a/test/parallel/test-crypto-cipher-decipher.js +++ b/test/parallel/test-crypto-cipher-decipher.js @@ -25,7 +25,7 @@ function testCipher1(key) { let txt = decipher.update(ciph, 'hex', 'utf8'); txt += decipher.final('utf8'); - assert.strictEqual(txt, plaintext, `${txt} is encrypted, ${plaintext} is unencrypted`); + assert.strictEqual(txt, plaintext); // streaming cipher interface // NB: In real life, it's not guaranteed that you can get all of it @@ -39,7 +39,7 @@ function testCipher1(key) { dStream.end(ciph); txt = dStream.read().toString('utf8'); - assert.strictEqual(txt, plaintext, `${txt} is the deciphered stream of ${ciph}`); + assert.strictEqual(txt, plaintext); } @@ -61,7 +61,7 @@ function testCipher2(key) { let txt = decipher.update(ciph, 'base64', 'utf8'); txt += decipher.final('utf8'); - assert.strictEqual(txt, plaintext, `${txt} is the decryption with Base64, ${plaintext} is the encryption`); + assert.strictEqual(txt, plaintext); } testCipher1('MySecretKey123'); @@ -74,7 +74,7 @@ testCipher2(Buffer.from('0123456789abcdef')); { const c = crypto.createCipher('aes-256-cbc', 'secret'); const s = c.update('test', 'utf8', 'base64') + c.final('base64'); - assert.strictEqual(s, '375oxUQCIocvxmC5At+rvA==', `${s} is updated to be base64 instead utf8`); + assert.strictEqual(s, '375oxUQCIocvxmC5At+rvA=='); } // Calling Cipher.final() or Decipher.final() twice should error but @@ -125,17 +125,17 @@ testCipher2(Buffer.from('0123456789abcdef')); let txt; assert.doesNotThrow(() => txt = decipher.update(ciph, 'base64', 'ucs2')); assert.doesNotThrow(() => txt += decipher.final('ucs2')); - assert.strictEqual(txt, plaintext, `${plaintext} has decrypted ${txt} in ucs2`); + assert.strictEqual(txt, plaintext); decipher = crypto.createDecipher('aes192', key); assert.doesNotThrow(() => txt = decipher.update(ciph, 'base64', 'ucs-2')); assert.doesNotThrow(() => txt += decipher.final('ucs-2')); - assert.strictEqual(txt, plaintext, `${plaintext} has decrypted ${txt} in ucs-2`); + assert.strictEqual(txt, plaintext); decipher = crypto.createDecipher('aes192', key); assert.doesNotThrow(() => txt = decipher.update(ciph, 'base64', 'utf-16le')); assert.doesNotThrow(() => txt += decipher.final('utf-16le')); - assert.strictEqual(txt, plaintext, `${plaintext} decrypted ${txt} in utf-16le`); + assert.strictEqual(txt, plaintext); } // setAutoPadding/setAuthTag/setAAD should return `this` @@ -144,9 +144,9 @@ testCipher2(Buffer.from('0123456789abcdef')); const tagbuf = Buffer.from('tagbuf'); const aadbuf = Buffer.from('aadbuf'); const decipher = crypto.createDecipher('aes-256-gcm', key); - assert.strictEqual(decipher.setAutoPadding(), decipher, `${decipher} will be set to the appropriate block size with autopadding`); - assert.strictEqual(decipher.setAuthTag(tagbuf), decipher, `${tagbuf} is the a authenticated tag of ${decipher}`); - assert.strictEqual(decipher.setAAD(aadbuf), decipher, `${decipher} has set the additional authenticated data param for ${aadbuf}`); + assert.strictEqual(decipher.setAutoPadding(), decipher); + assert.strictEqual(decipher.setAuthTag(tagbuf), decipher); + assert.strictEqual(decipher.setAAD(aadbuf), decipher); } // error throwing in setAAD/setAuthTag/getAuthTag/setAutoPadding