File tree 2 files changed +15
-8
lines changed
2 files changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ describe("requestHandler", () => {
96
96
test ( "withhout auth" , async ( ) => {
97
97
const result = await request ( server ) . get ( certPath ) . expect ( 200 ) ;
98
98
99
- expect ( result . body . toString ( ) ) . toEqual ( settings . crypto . cert ) ;
99
+ expect ( result . body . toString ( ) ) . toEqual ( settings . crypto ? .cert ) ;
100
100
} ) ;
101
101
102
102
test ( "with auth" , async ( ) => {
Original file line number Diff line number Diff line change @@ -185,7 +185,12 @@ export default class RequestHandler {
185
185
}
186
186
187
187
root ( req : express . Request , res : express . Response ) : void {
188
- const certificate = forge . pki . certificateFromPem ( this . settings . crypto . cert ) ;
188
+ let certificate : forge . pki . Certificate | undefined ;
189
+ try {
190
+ certificate = forge . pki . certificateFromPem ( this . settings . crypto . cert ) ;
191
+ } catch ( e ) {
192
+ // This is fine, we just won't include that in the output
193
+ }
189
194
190
195
res . status ( 200 ) . json ( {
191
196
status : "OK" ,
@@ -195,12 +200,14 @@ export default class RequestHandler {
195
200
} ,
196
201
service : "Obsidian Local REST API" ,
197
202
authenticated : this . requestIsAuthenticated ( req ) ,
198
- certificateInfo : this . requestIsAuthenticated ( req )
199
- ? {
200
- validityDays : getCertificateValidityDays ( certificate ) ,
201
- regenerateRecommended : ! getCertificateIsUptoStandards ( certificate ) ,
202
- }
203
- : undefined ,
203
+ certificateInfo :
204
+ this . requestIsAuthenticated ( req ) && certificate
205
+ ? {
206
+ validityDays : getCertificateValidityDays ( certificate ) ,
207
+ regenerateRecommended :
208
+ ! getCertificateIsUptoStandards ( certificate ) ,
209
+ }
210
+ : undefined ,
204
211
} ) ;
205
212
}
206
213
You can’t perform that action at this time.
0 commit comments