Skip to content

Commit

Permalink
test: crypto createClass instanceof Class
Browse files Browse the repository at this point in the history
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: #16245
PR-URL: #8188
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
bengl authored and MylesBorins committed Feb 13, 2018
1 parent 7b801b5 commit d29a620
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/parallel/test-crypto-classes.js
Original file line number Diff line number Diff line change
@@ -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]);
}

0 comments on commit d29a620

Please sign in to comment.