1
1
'use strict' ;
2
- var common = require ( '../common' ) ;
3
- var assert = require ( 'assert' ) ;
4
- var util = require ( 'util' ) ;
2
+ const common = require ( '../common' ) ;
5
3
6
4
if ( ! common . hasCrypto ) {
7
5
common . skip ( 'missing crypto' ) ;
8
6
return ;
9
7
}
10
- var crypto = require ( 'crypto' ) ;
11
8
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' ) ;
13
13
14
- var fs = require ( 'fs' ) ;
14
+ crypto . DEFAULT_ENCODING = 'buffer' ;
15
15
16
16
// 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' ) ;
22
21
23
22
// 'this' safety
24
23
// https://github.com/joyent/node/issues/6690
25
24
assert . 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 $ / ) ;
32
31
33
32
// PFX tests
34
33
assert . doesNotThrow ( function ( ) {
@@ -37,55 +36,55 @@ assert.doesNotThrow(function() {
37
36
38
37
assert . throws ( function ( ) {
39
38
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 $ / ) ;
41
40
42
41
assert . throws ( function ( ) {
43
42
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 $ / ) ;
45
44
46
45
assert . throws ( function ( ) {
47
46
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 $ / ) ;
49
48
50
49
51
50
// update() should only take buffers / strings
52
51
assert . throws ( function ( ) {
53
52
crypto . createHash ( 'sha1' ) . update ( { foo : 'bar' } ) ;
54
- } , / b u f f e r / ) ;
53
+ } , / ^ T y p e E r r o r : N o t a s t r i n g o r b u f f e r $ / ) ;
55
54
56
55
57
56
function assertSorted ( list ) {
58
57
// Array#sort() modifies the list in place so make a copy.
59
- var sorted = util . _extend ( [ ] , list ) . sort ( ) ;
58
+ const sorted = list . slice ( ) . sort ( ) ;
60
59
assert . deepEqual ( list , sorted ) ;
61
60
}
62
61
63
62
// 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 . notStrictEqual ( - 1 , crypto . getCiphers ( ) . indexOf ( 'aes-128-cbc' ) ) ;
65
+ assert . strictEqual ( - 1 , crypto . getCiphers ( ) . indexOf ( 'AES-128-CBC' ) ) ;
67
66
assertSorted ( crypto . getCiphers ( ) ) ;
68
67
69
68
// 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 . notStrictEqual ( - 1 , tls . getCiphers ( ) . indexOf ( 'aes256-sha' ) ) ;
71
+ assert . strictEqual ( - 1 , tls . getCiphers ( ) . indexOf ( 'AES256-SHA' ) ) ;
73
72
assertSorted ( tls . getCiphers ( ) ) ;
74
73
75
74
// 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 . notStrictEqual ( - 1 , crypto . getHashes ( ) . indexOf ( 'sha1' ) ) ;
77
+ assert . notStrictEqual ( - 1 , crypto . getHashes ( ) . indexOf ( 'sha' ) ) ;
78
+ assert . strictEqual ( - 1 , crypto . getHashes ( ) . indexOf ( 'SHA1' ) ) ;
79
+ assert . strictEqual ( - 1 , crypto . getHashes ( ) . indexOf ( 'SHA' ) ) ;
80
+ assert . notStrictEqual ( - 1 , crypto . getHashes ( ) . indexOf ( 'RSA-SHA1' ) ) ;
81
+ assert . strictEqual ( - 1 , crypto . getHashes ( ) . indexOf ( 'rsa-sha1' ) ) ;
83
82
assertSorted ( crypto . getHashes ( ) ) ;
84
83
85
84
// 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 . notStrictEqual ( - 1 , crypto . getCurves ( ) . indexOf ( 'secp384r1' ) ) ;
87
+ assert . strictEqual ( - 1 , crypto . getCurves ( ) . indexOf ( 'SECP384R1' ) ) ;
89
88
assertSorted ( crypto . getCurves ( ) ) ;
90
89
91
90
// Regression tests for #5725: hex input that's not a power of two should
@@ -100,18 +99,18 @@ assert.throws(function() {
100
99
101
100
assert . throws ( function ( ) {
102
101
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 $ / ) ;
104
103
105
104
assert . throws ( function ( ) {
106
105
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 $ / ) ;
108
107
109
108
assert . throws ( function ( ) {
110
109
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 $ / ) ;
112
111
113
112
assert . throws ( function ( ) {
114
- var priv = [
113
+ const priv = [
115
114
'-----BEGIN RSA PRIVATE KEY-----' ,
116
115
'MIGrAgEAAiEA+3z+1QNF2/unumadiwEr+C5vfhezsb3hp4jAnCNRpPcCAwEAAQIgQNriSQK4' ,
117
116
'EFwczDhMZp2dvbcz7OUUyt36z3S4usFPHSECEQD/41K7SujrstBfoCPzwC1xAhEA+5kt4BJy' ,
@@ -121,7 +120,7 @@ assert.throws(function() {
121
120
''
122
121
] . join ( '\n' ) ;
123
122
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 $ / ) ;
125
124
126
125
assert . throws ( function ( ) {
127
126
// The correct header inside `test_bad_rsa_privkey.pem` should have been
@@ -133,7 +132,7 @@ assert.throws(function() {
133
132
// $ openssl pkcs8 -topk8 -inform PEM -outform PEM -in mykey.pem \
134
133
// -out private_key.pem -nocrypt;
135
134
// 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 +
137
136
'/test_bad_rsa_privkey.pem' , 'ascii' ) ;
138
137
// this would inject errors onto OpenSSL's error stack
139
138
crypto . createSign ( 'sha1' ) . sign ( sha1_privateKey ) ;
0 commit comments