@@ -29,14 +29,13 @@ if (!common.opensslCli)
2929 common . skip ( 'missing openssl-cli' ) ;
3030
3131const assert = require ( 'assert' ) ;
32+ const { once } = require ( 'events' ) ;
3233const tls = require ( 'tls' ) ;
33- const spawn = require ( 'child_process' ) . spawn ;
34+ const { execFile } = require ( 'child_process' ) ;
3435const fixtures = require ( '../common/fixtures' ) ;
3536
3637const key = fixtures . readKey ( 'agent2-key.pem' ) ;
3738const cert = fixtures . readKey ( 'agent2-cert.pem' ) ;
38- let nsuccess = 0 ;
39- let ntests = 0 ;
4039const ciphers = 'DHE-RSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256' ;
4140
4241// Test will emit a warning because the DH parameter size is < 2048 bits
@@ -48,7 +47,7 @@ function loadDHParam(n) {
4847 return fixtures . readKey ( keyname ) ;
4948}
5049
51- function test ( keylen , expectedCipher , cb ) {
50+ function test ( keylen , expectedCipher ) {
5251 const options = {
5352 key : key ,
5453 cert : cert ,
@@ -57,61 +56,29 @@ function test(keylen, expectedCipher, cb) {
5756 maxVersion : 'TLSv1.2' ,
5857 } ;
5958
60- const server = tls . createServer ( options , function ( conn ) {
61- conn . end ( ) ;
62- } ) ;
59+ const server = tls . createServer ( options , ( conn ) => conn . end ( ) ) ;
6360
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 } ` ,
7163 '-cipher' , ciphers ] ;
7264
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 ) => {
8066 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+ } ) ) ;
9672
97- function test1024 ( ) {
98- test ( 1024 , 'DHE-RSA-AES128-SHA256' , test2048 ) ;
99- ntests ++ ;
73+ return once ( server , 'close' ) ;
10074}
10175
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 / ) ;
11380
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