11'use strict' ;
2+
23const common = require ( '../common' ) ;
34if ( ! common . hasCrypto )
45 common . skip ( 'missing crypto' ) ;
@@ -7,15 +8,55 @@ const assert = require('assert');
78const tls = require ( 'tls' ) ;
89const { X509Certificate } = require ( 'crypto' ) ;
910
10- function testX509Option ( ) {
11+ {
1112 const certs = tls . getCACertificates ( { type : 'default' , as : 'x509' } ) ;
1213
1314 assert . ok ( Array . isArray ( certs ) , 'should return an array' ) ;
1415 assert . ok ( certs . length > 0 , 'should return non-empty array' ) ;
1516 assert . ok ( certs [ 0 ] instanceof X509Certificate ,
1617 'each cert should be instance of X509Certificate' ) ;
1718
18- assert . match ( certs [ 0 ] . serialNumber , / ^ [ 0 - 9 A - F ] + $ / i, 'serialNumber should be hex string' ) ;
19+ assert . match ( certs [ 0 ] . serialNumber , / ^ [ 0 - 9 A - F ] + $ / i,
20+ 'serialNumber should be hex string' ) ;
21+ }
22+
23+ {
24+ const certs = tls . getCACertificates ( { type : 'default' , as : 'buffer' } ) ;
25+ assert . ok ( Array . isArray ( certs ) ) ;
26+ assert . ok ( certs . length > 0 ) ;
27+ assert . ok ( Buffer . isBuffer ( certs [ 0 ] ) ) ;
28+ }
29+
30+ {
31+ const certs = tls . getCACertificates ( { type : 'default' } ) ;
32+ assert . ok ( Array . isArray ( certs ) ) ;
33+ assert . ok ( certs . length > 0 ) ;
34+ assert . ok ( Buffer . isBuffer ( certs [ 0 ] ) ) ;
1935}
2036
21- testX509Option ( ) ;
37+ {
38+ assert . throws ( ( ) => {
39+ tls . getCACertificates ( { type : 'default' , as : 'invalid' } ) ;
40+ } , {
41+ name : 'TypeError' ,
42+ code : 'ERR_INVALID_ARG_VALUE' ,
43+ message : / m u s t b e o n e o f /
44+ } ) ;
45+ }
46+
47+ {
48+ const certs = tls . getCACertificates ( { as : 'buffer' } ) ;
49+ assert . ok ( Array . isArray ( certs ) ) ;
50+ assert . ok ( certs . length > 0 ) ;
51+ assert . ok ( Buffer . isBuffer ( certs [ 0 ] ) ) ;
52+ }
53+
54+ {
55+ assert . throws ( ( ) => {
56+ tls . getCACertificates ( { type : 'invalid' , as : 'buffer' } ) ;
57+ } , {
58+ name : 'TypeError' ,
59+ code : 'ERR_INVALID_ARG_VALUE' ,
60+ message : "The argument 'type' is invalid. Received 'invalid'"
61+ } ) ;
62+ }
0 commit comments