@@ -8,28 +8,41 @@ const assert = require('assert');
88const tls = require ( 'tls' ) ;
99const { X509Certificate } = require ( 'crypto' ) ;
1010
11+ const expectedPems = tls . getCACertificates ( { type : 'default' , format : 'pem' } ) ;
12+
1113{
1214 const certs = tls . getCACertificates ( { type : 'default' , format : 'x509' } ) ;
13- assert . ok ( Array . isArray ( certs ) ) ;
14- assert . ok ( certs . length > 0 ) ;
15- for ( const cert of certs ) {
15+ assert . strictEqual ( certs . length , expectedPems . length ) ;
16+
17+ for ( let i = 0 ; i < certs . length ; i ++ ) {
18+ const cert = certs [ i ] ;
19+ const expected = new X509Certificate ( expectedPems [ i ] ) ;
20+
1621 assert . ok ( cert instanceof X509Certificate ) ;
22+
23+ assert . strictEqual ( cert . fingerprint , expected . fingerprint ) ;
24+ assert . strictEqual ( cert . serialNumber , expected . serialNumber ) ;
25+ assert . strictEqual ( cert . subject , expected . subject ) ;
26+ assert . strictEqual ( cert . raw . toString ( 'hex' ) , expected . raw . toString ( 'hex' ) ) ;
1727 }
1828}
1929
2030{
2131 const certs = tls . getCACertificates ( { type : 'default' , format : 'buffer' } ) ;
22- assert . ok ( Array . isArray ( certs ) ) ;
23- assert . ok ( certs . length > 0 ) ;
24- for ( const cert of certs ) {
32+ assert . strictEqual ( certs . length , expectedPems . length ) ;
33+
34+ for ( let i = 0 ; i < certs . length ; i ++ ) {
35+ const cert = certs [ i ] ;
36+ const expected = new X509Certificate ( expectedPems [ i ] ) ;
37+
2538 assert . ok ( Buffer . isBuffer ( cert ) ) ;
39+ assert . strictEqual ( cert . toString ( 'hex' ) , expected . raw . toString ( 'hex' ) ) ;
2640 }
2741}
2842
2943{
3044 const certs = tls . getCACertificates ( { type : 'default' } ) ;
31- assert . ok ( Array . isArray ( certs ) ) ;
32- assert . ok ( certs . length > 0 ) ;
45+ assert . strictEqual ( certs . length , expectedPems . length ) ;
3346 for ( const cert of certs ) {
3447 assert . strictEqual ( typeof cert , 'string' ) ;
3548 assert . ok ( cert . includes ( '-----BEGIN CERTIFICATE-----' ) ) ;
@@ -61,6 +74,6 @@ const { X509Certificate } = require('crypto');
6174 } , {
6275 name : 'TypeError' ,
6376 code : 'ERR_INVALID_ARG_VALUE' ,
64- message : " The argument 'type' is invalid. Received 'invalid'"
77+ message : / T h e a r g u m e n t ' t y p e ' i s i n v a l i d /
6578 } ) ;
6679}
0 commit comments