@@ -35,6 +35,49 @@ test('RequestManager.request with cafile', async () => {
35
35
expect ( body ) . toBe ( 'ok' ) ;
36
36
} ) ;
37
37
38
+ test ( 'RequestManager.request with ca (string)' , async ( ) => {
39
+ let body ;
40
+ const options = {
41
+ key : await fs . readFile ( path . join ( __dirname , '..' , 'fixtures' , 'certificates' , 'server-key.pem' ) ) ,
42
+ cert : await fs . readFile ( path . join ( __dirname , '..' , 'fixtures' , 'certificates' , 'server-cert.pem' ) ) ,
43
+ } ;
44
+ const server = https . createServer ( options , ( req , res ) => { res . end ( 'ok' ) ; } ) ;
45
+ try {
46
+ server . listen ( 0 ) ;
47
+ const bundle = await fs . readFile ( path . join ( __dirname , '..' , 'fixtures' , 'certificates' , 'cacerts.pem' ) ) ;
48
+ const hasPemPrefix = ( block ) => block . startsWith ( '-----BEGIN ' ) ;
49
+ const caCerts = bundle . split ( / ( - - - - - B E G I N .* \r ? \n [ ^ - ] + \r ? \n - - .* ) / ) . filter ( hasPemPrefix ) ;
50
+ // the 2nd cert is valid one
51
+ const config = await createConfig ( { 'ca' : caCerts [ 1 ] } ) ;
52
+ const port = server . address ( ) . port ;
53
+ body = await config . requestManager . request ( { url : `https://localhost:${ port } /?nocache` , headers : { Connection : 'close' } } ) ;
54
+ } finally {
55
+ server . close ( ) ;
56
+ }
57
+ expect ( body ) . toBe ( 'ok' ) ;
58
+ } ) ;
59
+
60
+ test ( 'RequestManager.request with ca (array)' , async ( ) => {
61
+ let body ;
62
+ const options = {
63
+ key : await fs . readFile ( path . join ( __dirname , '..' , 'fixtures' , 'certificates' , 'server-key.pem' ) ) ,
64
+ cert : await fs . readFile ( path . join ( __dirname , '..' , 'fixtures' , 'certificates' , 'server-cert.pem' ) ) ,
65
+ } ;
66
+ const server = https . createServer ( options , ( req , res ) => { res . end ( 'ok' ) ; } ) ;
67
+ try {
68
+ server . listen ( 0 ) ;
69
+ const bundle = await fs . readFile ( path . join ( __dirname , '..' , 'fixtures' , 'certificates' , 'cacerts.pem' ) ) ;
70
+ const hasPemPrefix = ( block ) => block . startsWith ( '-----BEGIN ' ) ;
71
+ const caCerts = bundle . split ( / ( - - - - - B E G I N .* \r ? \n [ ^ - ] + \r ? \n - - .* ) / ) . filter ( hasPemPrefix ) ;
72
+ const config = await createConfig ( { 'ca' : caCerts } ) ;
73
+ const port = server . address ( ) . port ;
74
+ body = await config . requestManager . request ( { url : `https://localhost:${ port } /?nocache` , headers : { Connection : 'close' } } ) ;
75
+ } finally {
76
+ server . close ( ) ;
77
+ }
78
+ expect ( body ) . toBe ( 'ok' ) ;
79
+ } ) ;
80
+
38
81
test ( 'RequestManager.request with mutual TLS' , async ( ) => {
39
82
let body ;
40
83
const options = {
0 commit comments