11'use strict' ;
2- var common = require ( '../common' ) ;
3- var assert = require ( 'assert' ) ;
4- var util = require ( 'util' ) ;
2+ const common = require ( '../common' ) ;
53
64if ( ! common . hasCrypto ) {
75 common . skip ( 'missing crypto' ) ;
86 return ;
97}
10- var crypto = require ( 'crypto' ) ;
118
12- crypto . DEFAULT_ENCODING = 'buffer' ;
9+ const assert = require ( 'assert' ) ;
10+ const crypto = require ( 'crypto' ) ;
11+ const fs = require ( 'fs' ) ;
12+ const tls = require ( 'tls' ) ;
1313
14- var fs = require ( 'fs' ) ;
14+ crypto . DEFAULT_ENCODING = 'buffer' ;
1515
1616// Test Certificates
17- var caPem = fs . readFileSync ( common . fixturesDir + '/test_ca.pem' , 'ascii' ) ;
18- var certPem = fs . readFileSync ( common . fixturesDir + '/test_cert.pem' , 'ascii' ) ;
19- var certPfx = fs . readFileSync ( common . fixturesDir + '/test_cert.pfx' ) ;
20- var keyPem = fs . readFileSync ( common . fixturesDir + '/test_key.pem' , 'ascii' ) ;
21- var tls = require ( 'tls' ) ;
17+ const caPem = fs . readFileSync ( common . fixturesDir + '/test_ca.pem' , 'ascii' ) ;
18+ const certPem = fs . readFileSync ( common . fixturesDir + '/test_cert.pem' , 'ascii' ) ;
19+ const certPfx = fs . readFileSync ( common . fixturesDir + '/test_cert.pfx' ) ;
20+ const keyPem = fs . readFileSync ( common . fixturesDir + '/test_key.pem' , 'ascii' ) ;
2221
2322// 'this' safety
2423// https://github.com/joyent/node/issues/6690
2524assert . throws ( function ( ) {
26- var options = { key : keyPem , cert : certPem , ca : caPem } ;
27- var credentials = crypto . createCredentials ( options ) ;
28- var context = credentials . context ;
29- var notcontext = { setOptions : context . setOptions , setKey : context . setKey } ;
30- crypto . createCredentials ( { secureOptions : 1 } , notcontext ) ;
31- } , TypeError ) ;
25+ const options = { key : keyPem , cert : certPem , ca : caPem } ;
26+ const credentials = tls . createSecureContext ( options ) ;
27+ const context = credentials . context ;
28+ const notcontext = { setOptions : context . setOptions , setKey : context . setKey } ;
29+ tls . createSecureContext ( { secureOptions : 1 } , notcontext ) ;
30+ } , / ^ T y p e E r r o r : I l l e g a l i n v o c a t i o n $ / ) ;
3231
3332// PFX tests
3433assert . doesNotThrow ( function ( ) {
@@ -37,55 +36,55 @@ assert.doesNotThrow(function() {
3736
3837assert . throws ( function ( ) {
3938 tls . createSecureContext ( { pfx : certPfx } ) ;
40- } , ' mac verify failure' ) ;
39+ } , / ^ E r r o r : m a c v e r i f y f a i l u r e $ / ) ;
4140
4241assert . throws ( function ( ) {
4342 tls . createSecureContext ( { pfx : certPfx , passphrase : 'test' } ) ;
44- } , ' mac verify failure' ) ;
43+ } , / ^ E r r o r : m a c v e r i f y f a i l u r e $ / ) ;
4544
4645assert . throws ( function ( ) {
4746 tls . createSecureContext ( { pfx : 'sample' , passphrase : 'test' } ) ;
48- } , ' not enough data' ) ;
47+ } , / ^ E r r o r : n o t e n o u g h d a t a $ / ) ;
4948
5049
5150// update() should only take buffers / strings
5251assert . throws ( function ( ) {
5352 crypto . createHash ( 'sha1' ) . update ( { foo : 'bar' } ) ;
54- } , / b u f f e r / ) ;
53+ } , / ^ 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 $ / ) ;
5554
5655
5756function assertSorted ( list ) {
5857 // Array#sort() modifies the list in place so make a copy.
59- var sorted = util . _extend ( [ ] , list ) . sort ( ) ;
58+ const sorted = list . slice ( ) . sort ( ) ;
6059 assert . deepStrictEqual ( list , sorted ) ;
6160}
6261
6362// Assume that we have at least AES-128-CBC.
64- assert . notEqual ( 0 , crypto . getCiphers ( ) . length ) ;
65- assert . notEqual ( - 1 , crypto . getCiphers ( ) . indexOf ( 'aes-128-cbc' ) ) ;
66- assert . equal ( - 1 , crypto . getCiphers ( ) . indexOf ( 'AES-128-CBC' ) ) ;
63+ assert . notStrictEqual ( 0 , crypto . getCiphers ( ) . length ) ;
64+ assert ( crypto . getCiphers ( ) . includes ( 'aes-128-cbc' ) ) ;
65+ assert ( ! crypto . getCiphers ( ) . includes ( 'AES-128-CBC' ) ) ;
6766assertSorted ( crypto . getCiphers ( ) ) ;
6867
6968// Assume that we have at least AES256-SHA.
70- assert . notEqual ( 0 , tls . getCiphers ( ) . length ) ;
71- assert . notEqual ( - 1 , tls . getCiphers ( ) . indexOf ( 'aes256-sha' ) ) ;
72- assert . equal ( - 1 , tls . getCiphers ( ) . indexOf ( 'AES256-SHA' ) ) ;
69+ assert . notStrictEqual ( 0 , tls . getCiphers ( ) . length ) ;
70+ assert ( tls . getCiphers ( ) . includes ( 'aes256-sha' ) ) ;
71+ assert ( ! tls . getCiphers ( ) . includes ( 'AES256-SHA' ) ) ;
7372assertSorted ( tls . getCiphers ( ) ) ;
7473
7574// Assert that we have sha and sha1 but not SHA and SHA1.
76- assert . notEqual ( 0 , crypto . getHashes ( ) . length ) ;
77- assert . notEqual ( - 1 , crypto . getHashes ( ) . indexOf ( 'sha1' ) ) ;
78- assert . notEqual ( - 1 , crypto . getHashes ( ) . indexOf ( 'sha' ) ) ;
79- assert . equal ( - 1 , crypto . getHashes ( ) . indexOf ( 'SHA1' ) ) ;
80- assert . equal ( - 1 , crypto . getHashes ( ) . indexOf ( 'SHA' ) ) ;
81- assert . notEqual ( - 1 , crypto . getHashes ( ) . indexOf ( 'RSA-SHA1' ) ) ;
82- assert . equal ( - 1 , crypto . getHashes ( ) . indexOf ( 'rsa-sha1' ) ) ;
75+ assert . notStrictEqual ( 0 , crypto . getHashes ( ) . length ) ;
76+ assert ( crypto . getHashes ( ) . includes ( 'sha1' ) ) ;
77+ assert ( crypto . getHashes ( ) . includes ( 'sha' ) ) ;
78+ assert ( ! crypto . getHashes ( ) . includes ( 'SHA1' ) ) ;
79+ assert ( ! crypto . getHashes ( ) . includes ( 'SHA' ) ) ;
80+ assert ( crypto . getHashes ( ) . includes ( 'RSA-SHA1' ) ) ;
81+ assert ( ! crypto . getHashes ( ) . includes ( 'rsa-sha1' ) ) ;
8382assertSorted ( crypto . getHashes ( ) ) ;
8483
8584// Assume that we have at least secp384r1.
86- assert . notEqual ( 0 , crypto . getCurves ( ) . length ) ;
87- assert . notEqual ( - 1 , crypto . getCurves ( ) . indexOf ( 'secp384r1' ) ) ;
88- assert . equal ( - 1 , crypto . getCurves ( ) . indexOf ( 'SECP384R1' ) ) ;
85+ assert . notStrictEqual ( 0 , crypto . getCurves ( ) . length ) ;
86+ assert ( crypto . getCurves ( ) . includes ( 'secp384r1' ) ) ;
87+ assert ( ! crypto . getCurves ( ) . includes ( 'SECP384R1' ) ) ;
8988assertSorted ( crypto . getCurves ( ) ) ;
9089
9190// Regression tests for #5725: hex input that's not a power of two should
@@ -100,18 +99,18 @@ assert.throws(function() {
10099
101100assert . throws ( function ( ) {
102101 crypto . createHash ( 'sha1' ) . update ( '0' , 'hex' ) ;
103- } , / B a d i n p u t s t r i n g / ) ;
102+ } , / ^ T y p e E r r o r : B a d i n p u t s t r i n g $ / ) ;
104103
105104assert . throws ( function ( ) {
106105 crypto . createSign ( 'RSA-SHA1' ) . update ( '0' , 'hex' ) ;
107- } , / B a d i n p u t s t r i n g / ) ;
106+ } , / ^ T y p e E r r o r : B a d i n p u t s t r i n g $ / ) ;
108107
109108assert . throws ( function ( ) {
110109 crypto . createVerify ( 'RSA-SHA1' ) . update ( '0' , 'hex' ) ;
111- } , / B a d i n p u t s t r i n g / ) ;
110+ } , / ^ T y p e E r r o r : B a d i n p u t s t r i n g $ / ) ;
112111
113112assert . throws ( function ( ) {
114- var priv = [
113+ const priv = [
115114 '-----BEGIN RSA PRIVATE KEY-----' ,
116115 'MIGrAgEAAiEA+3z+1QNF2/unumadiwEr+C5vfhezsb3hp4jAnCNRpPcCAwEAAQIgQNriSQK4' ,
117116 'EFwczDhMZp2dvbcz7OUUyt36z3S4usFPHSECEQD/41K7SujrstBfoCPzwC1xAhEA+5kt4BJy' ,
@@ -121,7 +120,7 @@ assert.throws(function() {
121120 ''
122121 ] . join ( '\n' ) ;
123122 crypto . createSign ( 'RSA-SHA256' ) . update ( 'test' ) . sign ( priv ) ;
124- } , / d i g e s t t o o b i g f o r r s a k e y / ) ;
123+ } , / d i g e s t t o o b i g f o r r s a k e y $ / ) ;
125124
126125assert . throws ( function ( ) {
127126 // The correct header inside `test_bad_rsa_privkey.pem` should have been
@@ -133,7 +132,7 @@ assert.throws(function() {
133132 // $ openssl pkcs8 -topk8 -inform PEM -outform PEM -in mykey.pem \
134133 // -out private_key.pem -nocrypt;
135134 // Then open private_key.pem and change its header and footer.
136- var sha1_privateKey = fs . readFileSync ( common . fixturesDir +
135+ const sha1_privateKey = fs . readFileSync ( common . fixturesDir +
137136 '/test_bad_rsa_privkey.pem' , 'ascii' ) ;
138137 // this would inject errors onto OpenSSL's error stack
139138 crypto . createSign ( 'sha1' ) . sign ( sha1_privateKey ) ;
@@ -144,4 +143,4 @@ console.log(crypto.randomBytes(16));
144143
145144assert . throws ( function ( ) {
146145 tls . createSecureContext ( { crl : 'not a CRL' } ) ;
147- } , '/ Failed to parse CRL/' ) ;
146+ } , / ^ E r r o r : F a i l e d t o p a r s e C R L $ / ) ;
0 commit comments