@@ -36,6 +36,25 @@ test('parameters must be a plain object', t => {
3636 } )
3737} )
3838
39+ Object . entries ( fixtures . PEM ) . forEach ( ( [ type , { private : priv , public : pub } ] ) => {
40+ test ( `${ type } private can be imported as a string` , t => {
41+ const k = importKey ( priv . toString ( 'ascii' ) )
42+ t . true ( k . private )
43+ } )
44+ test ( `${ type } public can be imported as a string` , t => {
45+ const k = importKey ( pub . toString ( 'ascii' ) )
46+ t . true ( k . public )
47+ } )
48+ test ( `${ type } private can be imported as a buffer` , t => {
49+ const k = importKey ( priv )
50+ t . true ( k . private )
51+ } )
52+ test ( `${ type } public can be imported as a buffer` , t => {
53+ const k = importKey ( pub )
54+ t . true ( k . public )
55+ } )
56+ } )
57+
3958test ( 'failed to import throws an error' , t => {
4059 t . throws ( ( ) => {
4160 importKey ( {
@@ -44,3 +63,16 @@ test('failed to import throws an error', t => {
4463 } )
4564 } , { instanceOf : errors . JWKImportFailed , code : 'ERR_JWK_IMPORT_FAILED' } )
4665} )
66+
67+ ; [
68+ `-----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEIHXLsXm1lsq5HtyqJwQyFmpfEluuf0KOqP6DqMgGxxDL\n-----END PRIVATE KEY-----` ,
69+ `-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAEXRYV3v5ucrHVR3mKqyPXxXqU34lASwc7Y7MoOvaqcs=\n-----END PUBLIC KEY-----` ,
70+ `-----BEGIN PRIVATE KEY-----\nMEcCAQAwBQYDK2VxBDsEObxytD95dGN3Hxk7kVk+Lig1rGYTRr3YdaHjRog++Sgk\nQD7KwKmxroBURtkE2N0JbQ3ctdrpGRB5DQ==\n-----END PRIVATE KEY-----` ,
71+ `-----BEGIN PUBLIC KEY-----\nMEMwBQYDK2VxAzoAIESY3jnpGdB5UVJDCznrv0vmBFIzgSMu+gafsbCX1rFtsJwR\nM6XUDQiEY7dk6rmm/Fktyawna5EA\n-----END PUBLIC KEY-----`
72+ ] . forEach ( ( unsupported , i ) => {
73+ test . skip ( `fails to import unsupported PEM ${ i + 1 } /4` , t => {
74+ t . throws ( ( ) => {
75+ importKey ( unsupported )
76+ } , { instanceOf : errors . JWKImportFailed , code : 'ERR_JWK_IMPORT_FAILED' } )
77+ } )
78+ } )
0 commit comments