@@ -12,7 +12,6 @@ describe("Utils tests", function () {
1212 pemAsArray [ pemAsArray . length - 1 ]
1313 } `;
1414
15- // @ts -expect-error FIXME
1615 expect ( utils . derToPem ( nonNormalizedPem ) ) . to . equal ( normalizedPem ) ;
1716 } ) ;
1817
@@ -25,8 +24,45 @@ describe("Utils tests", function () {
2524 } ) ;
2625
2726 it ( "will throw if the format is neither PEM nor DER" , function ( ) {
28- // @ts -expect-error FIXME
2927 expect ( ( ) => utils . derToPem ( "not a pem" ) ) . to . throw ( ) ;
3028 } ) ;
29+
30+ it ( "will return a normalized PEM format when given a DER Buffer" , function ( ) {
31+ const normalizedPem = fs . readFileSync ( "./test/static/client_public.pem" , "latin1" ) ;
32+ const derBuffer = fs . readFileSync ( "./test/static/client_public.der" ) ;
33+
34+ expect ( utils . derToPem ( derBuffer , "CERTIFICATE" ) ) . to . equal ( normalizedPem ) ;
35+ } ) ;
36+
37+ it ( "will return a normalized PEM format when given a base64 string with line breaks" , function ( ) {
38+ const normalizedPem = fs . readFileSync ( "./test/static/client_public.pem" , "latin1" ) ;
39+ const base64String = fs . readFileSync ( "./test/static/client_public.der" , "base64" ) ;
40+
41+ expect ( utils . derToPem ( base64String , "CERTIFICATE" ) ) . to . equal ( normalizedPem ) ;
42+ } ) ;
43+
44+ it ( "will throw if the DER string is not base64 encoded" , function ( ) {
45+ expect ( ( ) => utils . derToPem ( "not base64" , "CERTIFICATE" ) ) . to . throw ( ) ;
46+ } ) ;
47+
48+ it ( "will throw if the PEM label is not provided" , function ( ) {
49+ const derBuffer = fs . readFileSync ( "./test/static/client_public.der" ) ;
50+ expect ( ( ) => utils . derToPem ( derBuffer ) ) . to . throw ( ) ;
51+ } ) ;
52+ } ) ;
53+
54+ describe ( "pemToDer" , function ( ) {
55+ it ( "will return a Buffer of binary DER when given a normalized PEM format" , function ( ) {
56+ const pem = fs . readFileSync ( "./test/static/client_public.pem" , "latin1" ) ;
57+ const derBuffer = fs . readFileSync ( "./test/static/client_public.der" ) ;
58+
59+ const result = utils . pemToDer ( pem ) ;
60+ expect ( result ) . to . be . instanceOf ( Buffer ) ;
61+ expect ( result ) . to . deep . equal ( derBuffer ) ;
62+ } ) ;
63+
64+ it ( "will throw if the format is not PEM" , function ( ) {
65+ expect ( ( ) => utils . pemToDer ( "not a pem" ) ) . to . throw ( ) ;
66+ } ) ;
3167 } ) ;
3268} ) ;
0 commit comments