From 5056741c9ea7eec9536ae4537e7aa2da5bdc12d3 Mon Sep 17 00:00:00 2001 From: Eric Christie Date: Wed, 8 Feb 2017 23:20:05 -0500 Subject: [PATCH 1/5] test: add error validation to assert.throws calls Used regular expressions to validate error messages. Also added messages (third parameter) to the assert.throws calls. --- test/pummel/test-crypto-dh.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/pummel/test-crypto-dh.js b/test/pummel/test-crypto-dh.js index 64c2800f16ae8d..460d860d000e72 100644 --- a/test/pummel/test-crypto-dh.js +++ b/test/pummel/test-crypto-dh.js @@ -10,13 +10,13 @@ if (!common.hasCrypto) { assert.throws(function() { crypto.getDiffieHellman('unknown-group'); -}); +}, /^Unknown group$/, "crypto.getDiffieHellman('unknown-group') failed to throw the expected error."); assert.throws(function() { crypto.getDiffieHellman('modp1').setPrivateKey(''); -}); +}, /^crypto\.getDiffieHellman\(\.\.\.\)\.setPrivateKey is not a function$/, "crypto.getDiffieHellman('modp1').setPrivateKey('') failed to throw the expected error."); assert.throws(function() { crypto.getDiffieHellman('modp1').setPublicKey(''); -}); +}, /^crypto\.getDiffieHellman\(\.\.\.\)\.setPublicKey is not a function$/, "crypto.getDiffieHellman('modp1').setPublicKey('') failed to throw the expected error."); const hashes = { modp1: '630e9acd2cc63f7e80d8507624ba60ac0757201a', From 86ba1c98d7dc1643519e8d9461be212ab94f028d Mon Sep 17 00:00:00 2001 From: Eric Christie Date: Thu, 9 Feb 2017 00:27:33 -0500 Subject: [PATCH 2/5] test: fixed code styling of assert.throws calls --- test/pummel/test-crypto-dh.js | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/test/pummel/test-crypto-dh.js b/test/pummel/test-crypto-dh.js index 460d860d000e72..6bfae06e8ab130 100644 --- a/test/pummel/test-crypto-dh.js +++ b/test/pummel/test-crypto-dh.js @@ -8,15 +8,30 @@ if (!common.hasCrypto) { return; } -assert.throws(function() { - crypto.getDiffieHellman('unknown-group'); -}, /^Unknown group$/, "crypto.getDiffieHellman('unknown-group') failed to throw the expected error."); -assert.throws(function() { - crypto.getDiffieHellman('modp1').setPrivateKey(''); -}, /^crypto\.getDiffieHellman\(\.\.\.\)\.setPrivateKey is not a function$/, "crypto.getDiffieHellman('modp1').setPrivateKey('') failed to throw the expected error."); -assert.throws(function() { - crypto.getDiffieHellman('modp1').setPublicKey(''); -}, /^crypto\.getDiffieHellman\(\.\.\.\)\.setPublicKey is not a function$/, "crypto.getDiffieHellman('modp1').setPublicKey('') failed to throw the expected error."); +assert.throws( + function() { + crypto.getDiffieHellman('unknown-group'); + }, + /^Unknown group$/, + 'crypto.getDiffieHellman(\'unknown-group\') ' + + 'failed to throw the expected error.' +); +assert.throws( + function() { + crypto.getDiffieHellman('modp1').setPrivateKey(''); + }, + /^crypto\.getDiffieHellman\(\.\.\.\)\.setPrivateKey is not a function$/, + 'crypto.getDiffieHellman(\'modp1\').setPrivateKey(\'\') ' + + 'failed to throw the expected error.' +); +assert.throws( + function() { + crypto.getDiffieHellman('modp1').setPublicKey(''); + }, + /^crypto\.getDiffieHellman\(\.\.\.\)\.setPublicKey is not a function$/, + 'crypto.getDiffieHellman(\'modp1\').setPublicKey(\'\') ' + + 'failed to throw the expected error.' +); const hashes = { modp1: '630e9acd2cc63f7e80d8507624ba60ac0757201a', From 5049fe604942b908b3c475a56581dc8dcaba141d Mon Sep 17 00:00:00 2001 From: Eric Christie Date: Thu, 9 Feb 2017 13:20:18 -0500 Subject: [PATCH 3/5] test: add error type to regular expressions --- test/pummel/test-crypto-dh.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/pummel/test-crypto-dh.js b/test/pummel/test-crypto-dh.js index 6bfae06e8ab130..12fe3fb3e6960b 100644 --- a/test/pummel/test-crypto-dh.js +++ b/test/pummel/test-crypto-dh.js @@ -12,7 +12,7 @@ assert.throws( function() { crypto.getDiffieHellman('unknown-group'); }, - /^Unknown group$/, + /^Error: Unknown group$/, 'crypto.getDiffieHellman(\'unknown-group\') ' + 'failed to throw the expected error.' ); @@ -20,7 +20,8 @@ assert.throws( function() { crypto.getDiffieHellman('modp1').setPrivateKey(''); }, - /^crypto\.getDiffieHellman\(\.\.\.\)\.setPrivateKey is not a function$/, + /^TypeError: crypto\.getDiffieHellman\(\.\.\.\)\.setPrivateKey/ + + / is not a function$/, 'crypto.getDiffieHellman(\'modp1\').setPrivateKey(\'\') ' + 'failed to throw the expected error.' ); @@ -28,7 +29,8 @@ assert.throws( function() { crypto.getDiffieHellman('modp1').setPublicKey(''); }, - /^crypto\.getDiffieHellman\(\.\.\.\)\.setPublicKey is not a function$/, + /^TypeError: crypto\.getDiffieHellman\(\.\.\.\)\.setPublicKey/ + + / is not a function$/, 'crypto.getDiffieHellman(\'modp1\').setPublicKey(\'\') ' + 'failed to throw the expected error.' ); From a0f6e1e111d1453041a35276597e879fd3bd5188 Mon Sep 17 00:00:00 2001 From: Eric Christie Date: Thu, 9 Feb 2017 13:46:00 -0500 Subject: [PATCH 4/5] test: fixed assert.throws regular expressions --- test/pummel/test-crypto-dh.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/pummel/test-crypto-dh.js b/test/pummel/test-crypto-dh.js index 12fe3fb3e6960b..a2bbf49af0c4ff 100644 --- a/test/pummel/test-crypto-dh.js +++ b/test/pummel/test-crypto-dh.js @@ -20,8 +20,8 @@ assert.throws( function() { crypto.getDiffieHellman('modp1').setPrivateKey(''); }, - /^TypeError: crypto\.getDiffieHellman\(\.\.\.\)\.setPrivateKey/ + - / is not a function$/, + new RegExp(/^TypeError: crypto\.getDiffieHellman\(\.\.\.\)\./.source + + /setPrivateKey is not a function$/.source), 'crypto.getDiffieHellman(\'modp1\').setPrivateKey(\'\') ' + 'failed to throw the expected error.' ); @@ -29,8 +29,8 @@ assert.throws( function() { crypto.getDiffieHellman('modp1').setPublicKey(''); }, - /^TypeError: crypto\.getDiffieHellman\(\.\.\.\)\.setPublicKey/ + - / is not a function$/, + new RegExp(/^TypeError: crypto\.getDiffieHellman\(\.\.\.\)\./.source + + /setPublicKey is not a function$/.source), 'crypto.getDiffieHellman(\'modp1\').setPublicKey(\'\') ' + 'failed to throw the expected error.' ); From a20d68ea6a41e85259df16da1dcf43155aece5cc Mon Sep 17 00:00:00 2001 From: Eric Christie Date: Tue, 14 Feb 2017 10:10:07 -0500 Subject: [PATCH 5/5] test: change some regular expressions to strings --- test/pummel/test-crypto-dh.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/pummel/test-crypto-dh.js b/test/pummel/test-crypto-dh.js index a2bbf49af0c4ff..03be3ab7ad48e2 100644 --- a/test/pummel/test-crypto-dh.js +++ b/test/pummel/test-crypto-dh.js @@ -20,8 +20,8 @@ assert.throws( function() { crypto.getDiffieHellman('modp1').setPrivateKey(''); }, - new RegExp(/^TypeError: crypto\.getDiffieHellman\(\.\.\.\)\./.source + - /setPrivateKey is not a function$/.source), + new RegExp('^TypeError: crypto\\.getDiffieHellman\\(\\.\\.\\.\\)\\.' + + 'setPrivateKey is not a function$'), 'crypto.getDiffieHellman(\'modp1\').setPrivateKey(\'\') ' + 'failed to throw the expected error.' ); @@ -29,8 +29,8 @@ assert.throws( function() { crypto.getDiffieHellman('modp1').setPublicKey(''); }, - new RegExp(/^TypeError: crypto\.getDiffieHellman\(\.\.\.\)\./.source + - /setPublicKey is not a function$/.source), + new RegExp('^TypeError: crypto\\.getDiffieHellman\\(\\.\\.\\.\\)\\.' + + 'setPublicKey is not a function$'), 'crypto.getDiffieHellman(\'modp1\').setPublicKey(\'\') ' + 'failed to throw the expected error.' );