summaryrefslogtreecommitdiff
path: root/test/parallel/test-crypto.js
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2017-01-12 22:16:21 -0800
committerItalo A. Casas <me@italoacasas.com>2017-01-16 16:40:31 -0500
commite21126d20f10b319593b755312dea13cd39f048a (patch)
tree5b5e59050368a7a6e8e901e74c58bb19d8194980 /test/parallel/test-crypto.js
parent5ab910e9dfbb952d7b20d5a847ef96d068d0cf81 (diff)
downloadandroid-node-v8-e21126d20f10b319593b755312dea13cd39f048a.tar.gz
android-node-v8-e21126d20f10b319593b755312dea13cd39f048a.tar.bz2
android-node-v8-e21126d20f10b319593b755312dea13cd39f048a.zip
test: increase test-crypto.js strictness
Confirm that `getCiphers()` contains no duplicates. PR-URL: https://github.com/nodejs/node/pull/10784 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test/parallel/test-crypto.js')
-rw-r--r--test/parallel/test-crypto.js30
1 files changed, 20 insertions, 10 deletions
diff --git a/test/parallel/test-crypto.js b/test/parallel/test-crypto.js
index 13401e4ac5..eff9a5092e 100644
--- a/test/parallel/test-crypto.js
+++ b/test/parallel/test-crypto.js
@@ -53,23 +53,33 @@ assert.throws(function() {
}, /^TypeError: Data must be a string or a buffer$/);
-function assertSorted(list) {
+function validateList(list) {
+ // The list must not be empty
+ assert(list.length > 0);
+
+ // The list should be sorted.
// Array#sort() modifies the list in place so make a copy.
- const sorted = list.slice().sort();
+ const sorted = [...list].sort();
assert.deepStrictEqual(list, sorted);
+
+ // Each element should be unique.
+ assert.strictEqual([...new Set(list)].length, list.length);
+
+ // Each element should be a string.
+ assert(list.every((value) => typeof value === 'string'));
}
// Assume that we have at least AES-128-CBC.
-assert.notStrictEqual(0, crypto.getCiphers().length);
+const cryptoCiphers = crypto.getCiphers();
assert(crypto.getCiphers().includes('aes-128-cbc'));
-assert(!crypto.getCiphers().includes('AES-128-CBC'));
-assertSorted(crypto.getCiphers());
+validateList(cryptoCiphers);
// Assume that we have at least AES256-SHA.
-assert.notStrictEqual(0, tls.getCiphers().length);
+const tlsCiphers = tls.getCiphers();
assert(tls.getCiphers().includes('aes256-sha'));
-assert(!tls.getCiphers().includes('AES256-SHA'));
-assertSorted(tls.getCiphers());
+// There should be no capital letters in any element.
+assert(tlsCiphers.every((value) => /^[^A-Z]+$/.test(value)));
+validateList(tlsCiphers);
// Assert that we have sha and sha1 but not SHA and SHA1.
assert.notStrictEqual(0, crypto.getHashes().length);
@@ -79,13 +89,13 @@ assert(!crypto.getHashes().includes('SHA1'));
assert(!crypto.getHashes().includes('SHA'));
assert(crypto.getHashes().includes('RSA-SHA1'));
assert(!crypto.getHashes().includes('rsa-sha1'));
-assertSorted(crypto.getHashes());
+validateList(crypto.getHashes());
// Assume that we have at least secp384r1.
assert.notStrictEqual(0, crypto.getCurves().length);
assert(crypto.getCurves().includes('secp384r1'));
assert(!crypto.getCurves().includes('SECP384R1'));
-assertSorted(crypto.getCurves());
+validateList(crypto.getCurves());
// Regression tests for #5725: hex input that's not a power of two should
// throw, not assert in C++ land.