File tree 3 files changed +20
-2
lines changed
3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change 24
24
"dependencies" : {
25
25
"@types/jsonwebtoken" : " ^7.1.33" ,
26
26
"faye-websocket" : " 0.9.3" ,
27
- "jsonwebtoken" : " 7.1.9"
27
+ "jsonwebtoken" : " 7.1.9" ,
28
+ "node-forge" : " 0.7.1"
28
29
},
29
30
"devDependencies" : {
30
31
"@types/chai" : " ^3.4.34" ,
Original file line number Diff line number Diff line change 15
15
*/
16
16
17
17
import * as jwt from 'jsonwebtoken' ;
18
+ import * as forge from 'node-forge' ;
18
19
19
20
// Use untyped import syntax for Node built-ins
20
21
import fs = require( 'fs' ) ;
@@ -167,6 +168,14 @@ export class Certificate {
167
168
if ( typeof errorMessage !== 'undefined' ) {
168
169
throw new FirebaseAppError ( AppErrorCodes . INVALID_CREDENTIAL , errorMessage ) ;
169
170
}
171
+
172
+ try {
173
+ forge . pki . privateKeyFromPem ( this . privateKey ) ;
174
+ } catch ( error ) {
175
+ throw new FirebaseAppError (
176
+ AppErrorCodes . INVALID_CREDENTIAL ,
177
+ 'Failed to parse private key: ' + error ) ;
178
+ }
170
179
}
171
180
}
172
181
Original file line number Diff line number Diff line change @@ -171,7 +171,7 @@ describe('Credential', () => {
171
171
} ) . to . throw ( 'Certificate object must contain a string "client_email" property' ) ;
172
172
} ) ;
173
173
174
- it ( 'should throw if certificate object does not contain a valid "private_key"' , ( ) => {
174
+ it ( 'should throw if certificate object does not contain a "private_key"' , ( ) => {
175
175
mockCertificateObject . private_key = '' ;
176
176
177
177
expect ( ( ) => {
@@ -185,6 +185,14 @@ describe('Credential', () => {
185
185
} ) . to . throw ( 'Certificate object must contain a string "private_key" property' ) ;
186
186
} ) ;
187
187
188
+ it ( 'should throw if certificate object does not contain a valid "private_key"' , ( ) => {
189
+ mockCertificateObject . private_key = 'invalid.key' ;
190
+
191
+ expect ( ( ) => {
192
+ return new Certificate ( mockCertificateObject ) ;
193
+ } ) . to . throw ( 'Failed to parse private key: Error: Invalid PEM formatted message.' ) ;
194
+ } ) ;
195
+
188
196
it ( 'should not throw given a valid certificate object' , ( ) => {
189
197
expect ( ( ) => {
190
198
return new Certificate ( mockCertificateObject ) ;
You can’t perform that action at this time.
0 commit comments