@@ -29,14 +29,13 @@ if (!common.opensslCli)
29
29
common . skip ( 'missing openssl-cli' ) ;
30
30
31
31
const assert = require ( 'assert' ) ;
32
+ const { once } = require ( 'events' ) ;
32
33
const tls = require ( 'tls' ) ;
33
- const spawn = require ( 'child_process' ) . spawn ;
34
+ const { execFile } = require ( 'child_process' ) ;
34
35
const fixtures = require ( '../common/fixtures' ) ;
35
36
36
37
const key = fixtures . readKey ( 'agent2-key.pem' ) ;
37
38
const cert = fixtures . readKey ( 'agent2-cert.pem' ) ;
38
- let nsuccess = 0 ;
39
- let ntests = 0 ;
40
39
const ciphers = 'DHE-RSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256' ;
41
40
42
41
// Test will emit a warning because the DH parameter size is < 2048 bits
@@ -48,7 +47,7 @@ function loadDHParam(n) {
48
47
return fixtures . readKey ( keyname ) ;
49
48
}
50
49
51
- function test ( keylen , expectedCipher , cb ) {
50
+ function test ( keylen , expectedCipher ) {
52
51
const options = {
53
52
key : key ,
54
53
cert : cert ,
@@ -57,61 +56,29 @@ function test(keylen, expectedCipher, cb) {
57
56
maxVersion : 'TLSv1.2' ,
58
57
} ;
59
58
60
- const server = tls . createServer ( options , function ( conn ) {
61
- conn . end ( ) ;
62
- } ) ;
59
+ const server = tls . createServer ( options , ( conn ) => conn . end ( ) ) ;
63
60
64
- server . on ( 'close' , function ( err ) {
65
- assert . ifError ( err ) ;
66
- if ( cb ) cb ( ) ;
67
- } ) ;
68
-
69
- server . listen ( 0 , '127.0.0.1' , function ( ) {
70
- const args = [ 's_client' , '-connect' , `127.0.0.1:${ this . address ( ) . port } ` ,
61
+ server . listen ( 0 , '127.0.0.1' , common . mustCall ( ( ) => {
62
+ const args = [ 's_client' , '-connect' , `127.0.0.1:${ server . address ( ) . port } ` ,
71
63
'-cipher' , ciphers ] ;
72
64
73
- const client = spawn ( common . opensslCli , args ) ;
74
- let out = '' ;
75
- client . stdout . setEncoding ( 'utf8' ) ;
76
- client . stdout . on ( 'data' , function ( d ) {
77
- out += d ;
78
- } ) ;
79
- client . stdout . on ( 'end' , function ( ) {
65
+ execFile ( common . opensslCli , args , common . mustSucceed ( ( stdout ) => {
80
66
assert ( keylen === 'error' ||
81
- out . includes ( `Server Temp Key: DH, ${ keylen } bits` ) ) ;
82
- const reg = new RegExp ( `Cipher : ${ expectedCipher } ` ) ;
83
- if ( reg . test ( out ) ) {
84
- nsuccess ++ ;
85
- server . close ( ) ;
86
- }
87
- } ) ;
88
- } ) ;
89
- }
90
-
91
- function test512 ( ) {
92
- assert . throws ( function ( ) {
93
- test ( 512 , 'DHE-RSA-AES128-SHA256' , null ) ;
94
- } , / D H p a r a m e t e r i s l e s s t h a n 1 0 2 4 b i t s / ) ;
95
- }
67
+ stdout . includes ( `Server Temp Key: DH, ${ keylen } bits` ) ) ;
68
+ assert ( stdout . includes ( `Cipher : ${ expectedCipher } ` ) ) ;
69
+ server . close ( ) ;
70
+ } ) ) ;
71
+ } ) ) ;
96
72
97
- function test1024 ( ) {
98
- test ( 1024 , 'DHE-RSA-AES128-SHA256' , test2048 ) ;
99
- ntests ++ ;
73
+ return once ( server , 'close' ) ;
100
74
}
101
75
102
- function test2048 ( ) {
103
- test ( 2048 , 'DHE-RSA-AES128-SHA256' , testError ) ;
104
- ntests ++ ;
105
- }
106
-
107
- function testError ( ) {
108
- test ( 'error' , 'ECDHE-RSA-AES128-SHA256' , test512 ) ;
109
- ntests ++ ;
110
- }
111
-
112
- test1024 ( ) ;
76
+ ( async ( ) => {
77
+ assert . throws ( ( ) => {
78
+ test ( 512 , 'DHE-RSA-AES128-SHA256' ) ;
79
+ } , / D H p a r a m e t e r i s l e s s t h a n 1 0 2 4 b i t s / ) ;
113
80
114
- process . on ( 'exit' , function ( ) {
115
- assert . strictEqual ( ntests , nsuccess ) ;
116
- assert . strictEqual ( ntests , 3 ) ;
117
- } ) ;
81
+ await test ( 1024 , 'DHE-RSA-AES128-SHA256' ) ;
82
+ await test ( 2048 , 'DHE-RSA-AES128-SHA256' ) ;
83
+ await test ( 'error' , 'ECDHE-RSA-AES128-SHA256' ) ;
84
+ } ) ( ) . then ( common . mustCall ( ) ) ;
0 commit comments