Skip to content

Commit 73c0c46

Browse files
TrottMylesBorins
authored andcommitted
test: increase test-crypto.js strictness
Confirm that `getCiphers()` contains no duplicates. PR-URL: #10784 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 4a87aee commit 73c0c46

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

test/parallel/test-crypto.js

+20-10
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,33 @@ assert.throws(function() {
5353
}, /^TypeError: Data must be a string or a buffer$/);
5454

5555

56-
function assertSorted(list) {
56+
function validateList(list) {
57+
// The list must not be empty
58+
assert(list.length > 0);
59+
60+
// The list should be sorted.
5761
// Array#sort() modifies the list in place so make a copy.
58-
const sorted = list.slice().sort();
62+
const sorted = [...list].sort();
5963
assert.deepStrictEqual(list, sorted);
64+
65+
// Each element should be unique.
66+
assert.strictEqual([...new Set(list)].length, list.length);
67+
68+
// Each element should be a string.
69+
assert(list.every((value) => typeof value === 'string'));
6070
}
6171

6272
// Assume that we have at least AES-128-CBC.
63-
assert.notStrictEqual(0, crypto.getCiphers().length);
73+
const cryptoCiphers = crypto.getCiphers();
6474
assert(crypto.getCiphers().includes('aes-128-cbc'));
65-
assert(!crypto.getCiphers().includes('AES-128-CBC'));
66-
assertSorted(crypto.getCiphers());
75+
validateList(cryptoCiphers);
6776

6877
// Assume that we have at least AES256-SHA.
69-
assert.notStrictEqual(0, tls.getCiphers().length);
78+
const tlsCiphers = tls.getCiphers();
7079
assert(tls.getCiphers().includes('aes256-sha'));
71-
assert(!tls.getCiphers().includes('AES256-SHA'));
72-
assertSorted(tls.getCiphers());
80+
// There should be no capital letters in any element.
81+
assert(tlsCiphers.every((value) => /^[^A-Z]+$/.test(value)));
82+
validateList(tlsCiphers);
7383

7484
// Assert that we have sha and sha1 but not SHA and SHA1.
7585
assert.notStrictEqual(0, crypto.getHashes().length);
@@ -79,13 +89,13 @@ assert(!crypto.getHashes().includes('SHA1'));
7989
assert(!crypto.getHashes().includes('SHA'));
8090
assert(crypto.getHashes().includes('RSA-SHA1'));
8191
assert(!crypto.getHashes().includes('rsa-sha1'));
82-
assertSorted(crypto.getHashes());
92+
validateList(crypto.getHashes());
8393

8494
// Assume that we have at least secp384r1.
8595
assert.notStrictEqual(0, crypto.getCurves().length);
8696
assert(crypto.getCurves().includes('secp384r1'));
8797
assert(!crypto.getCurves().includes('SECP384R1'));
88-
assertSorted(crypto.getCurves());
98+
validateList(crypto.getCurves());
8999

90100
// Regression tests for #5725: hex input that's not a power of two should
91101
// throw, not assert in C++ land.

0 commit comments

Comments
 (0)