@@ -53,23 +53,33 @@ assert.throws(function() {
5353} , / ^ T y p e E r r o r : D a t a m u s t b e a s t r i n g o r a b u f f e r $ / ) ;
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 ( ) ;
6474assert ( 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 ( ) ;
7079assert ( 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.
7585assert . notStrictEqual ( 0 , crypto . getHashes ( ) . length ) ;
@@ -79,13 +89,13 @@ assert(!crypto.getHashes().includes('SHA1'));
7989assert ( ! crypto . getHashes ( ) . includes ( 'SHA' ) ) ;
8090assert ( crypto . getHashes ( ) . includes ( 'RSA-SHA1' ) ) ;
8191assert ( ! crypto . getHashes ( ) . includes ( 'rsa-sha1' ) ) ;
82- assertSorted ( crypto . getHashes ( ) ) ;
92+ validateList ( crypto . getHashes ( ) ) ;
8393
8494// Assume that we have at least secp384r1.
8595assert . notStrictEqual ( 0 , crypto . getCurves ( ) . length ) ;
8696assert ( crypto . getCurves ( ) . includes ( 'secp384r1' ) ) ;
8797assert ( ! 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