@@ -11,44 +11,53 @@ const { fork } = require('node:child_process');
11
11
const fixtures = require ( '../common/fixtures' ) ;
12
12
13
13
const tests = [
14
- 'additional-ca' ,
15
- 'crl' ,
16
- 'pfx' ,
14
+ {
15
+ get clientOptions ( ) {
16
+ const secureContext = tls . createSecureContext ( ) ;
17
+ secureContext . context . addCACert (
18
+ fixtures . readKey ( 'ca1-cert.pem' )
19
+ ) ;
20
+
21
+ return {
22
+ secureContext
23
+ } ;
24
+ }
25
+ } ,
26
+ {
27
+ clientOptions : {
28
+ crl : fixtures . readKey ( 'ca2-crl.pem' )
29
+ }
30
+ } ,
31
+ {
32
+ clientOptions : {
33
+ pfx : fixtures . readKey ( 'agent1.pfx' ) ,
34
+ passphrase : 'sample'
35
+ }
36
+ } ,
17
37
] ;
18
38
19
- const clientTest = process . argv [ 2 ] ;
20
- if ( clientTest ) {
39
+ if ( process . argv [ 2 ] ) {
40
+ const testNumber = parseInt ( process . argv [ 2 ] , 10 ) ;
41
+ assert ( testNumber >= 0 && testNumber < tests . length ) ;
42
+
43
+ const test = tests [ testNumber ] ;
44
+
21
45
const clientOptions = {
46
+ ...test . clientOptions ,
22
47
port : process . argv [ 3 ] ,
23
48
checkServerIdentity : common . mustCall ( )
24
49
} ;
25
50
26
- switch ( clientTest ) {
27
- case 'additional-ca' :
28
- clientOptions . secureContext = tls . createSecureContext ( ) ;
29
- clientOptions . secureContext . context . addCACert (
30
- fixtures . readKey ( 'ca1-cert.pem' )
31
- ) ;
32
- break ;
33
- case 'crl' :
34
- clientOptions . crl = fixtures . readKey ( 'ca2-crl.pem' ) ;
35
- break ;
36
- case 'pfx' :
37
- clientOptions . pfx = fixtures . readKey ( 'agent1.pfx' ) ;
38
- clientOptions . passphrase = 'sample' ;
39
- break ;
40
- }
41
-
42
51
const client = tls . connect ( clientOptions , common . mustCall ( ( ) => {
43
52
client . end ( 'hi' ) ;
44
53
} ) ) ;
45
54
} else {
46
- for ( const test of tests ) {
47
- const serverOptions = {
48
- key : fixtures . readKey ( 'agent3-key.pem' ) ,
49
- cert : fixtures . readKey ( 'agent3-cert.pem' )
50
- } ;
55
+ const serverOptions = {
56
+ key : fixtures . readKey ( 'agent3-key.pem' ) ,
57
+ cert : fixtures . readKey ( 'agent3-cert.pem' )
58
+ } ;
51
59
60
+ for ( const testNumber in tests ) {
52
61
const server = tls . createServer ( serverOptions , common . mustCall ( ( socket ) => {
53
62
socket . end ( 'bye' ) ;
54
63
server . close ( ) ;
@@ -61,7 +70,7 @@ if (clientTest) {
61
70
} ;
62
71
63
72
const args = [
64
- test ,
73
+ testNumber ,
65
74
server . address ( ) . port ,
66
75
] ;
67
76
0 commit comments