From d7ac63ec5453218ef8f7e8a8effefa627a4a7412 Mon Sep 17 00:00:00 2001 From: Bryan English Date: Fri, 19 Aug 2016 14:45:20 -0700 Subject: [PATCH] test: crypto createClass instanceof Class The crypto classes are also exposed as createClass for each class. This tests that each of them returns an instance of the class in question. Backport-PR-URL: https://github.com/nodejs/node/pull/16245 PR-URL: https://github.com/nodejs/node/pull/8188 Reviewed-By: Ben Noordhuis Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell Reviewed-By: Rich Trott --- test/parallel/test-crypto-classes.js | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 test/parallel/test-crypto-classes.js diff --git a/test/parallel/test-crypto-classes.js b/test/parallel/test-crypto-classes.js new file mode 100644 index 00000000000000..55d76a607e5066 --- /dev/null +++ b/test/parallel/test-crypto-classes.js @@ -0,0 +1,41 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); + +if (!common.hasCrypto) { + common.skip('missing crypto'); + return; +} +const crypto = require('crypto'); + +// 'ClassName' : ['args', 'for', 'constructor'] +const TEST_CASES = { + 'Hash': ['sha1'], + 'Hmac': ['sha1', 'Node'], + 'Cipheriv': ['des-ede3-cbc', '0123456789abcd0123456789', '12345678'], + 'Decipheriv': ['des-ede3-cbc', '0123456789abcd0123456789', '12345678'], + 'Sign': ['RSA-SHA1'], + 'Verify': ['RSA-SHA1'], + 'DiffieHellman': [1024], + 'DiffieHellmanGroup': ['modp5'], + 'Credentials': [] +}; + +if (!common.hasFipsCrypto) { + TEST_CASES.Cipher = ['aes192', 'secret']; + TEST_CASES.Decipher = ['aes192', 'secret']; +} + +function entries(obj) { + const ownProps = Object.keys(obj); + let i = ownProps.length; + const resArray = new Array(i); // preallocate the Array + while (i--) + resArray[i] = [ownProps[i], obj[ownProps[i]]]; + + return resArray; +} + +for (const [clazz, args] of entries(TEST_CASES)) { + assert(crypto[`create${clazz}`](...args) instanceof crypto[clazz]); +}