@@ -5,7 +5,7 @@ import {Sessions} from "app/server/lib/Sessions";
5
5
import log from "app/server/lib/log" ;
6
6
import { assert } from "chai" ;
7
7
import Sinon from "sinon" ;
8
- import { Client , generators , errors as OIDCError } from "openid-client" ;
8
+ import { Client , custom , CustomHttpOptionsProvider , generators , errors as OIDCError } from "openid-client" ;
9
9
import express from "express" ;
10
10
import _ from "lodash" ;
11
11
import { RequestWithLogin } from "app/server/lib/Authorizer" ;
@@ -38,6 +38,7 @@ class ClientStub {
38
38
public callback = Sinon . stub ( ) . returns ( { } ) ;
39
39
public userinfo = Sinon . stub ( ) . returns ( undefined ) ;
40
40
public endSessionUrl = Sinon . stub ( ) . returns ( undefined ) ;
41
+ public [ custom . http_options ] : CustomHttpOptionsProvider ;
41
42
public issuer : {
42
43
metadata : {
43
44
end_session_endpoint : string | undefined ;
@@ -192,6 +193,55 @@ describe('OIDCConfig', () => {
192
193
} ) ;
193
194
} ) ;
194
195
} ) ;
196
+
197
+ describe ( 'GRIST_OIDC_SP_HTTP_TIMEOUT' , function ( ) {
198
+ [
199
+ {
200
+ itMsg : 'when omitted should not override openid-client default value' ,
201
+ expectedUserDefinedHttpOptions : { }
202
+ } ,
203
+ {
204
+ itMsg : 'should reject when the provided value is not a number' ,
205
+ env : {
206
+ GRIST_OIDC_SP_HTTP_TIMEOUT : '__NOT_A_NUMBER__' ,
207
+ } ,
208
+ expectedErrorMsg : / _ _ N O T _ A _ N U M B E R _ _ d o e s n o t l o o k l i k e a n u m b e r / ,
209
+ } ,
210
+ {
211
+ itMsg : 'should override openid-client timeout accordingly to the provided value' ,
212
+ env : {
213
+ GRIST_OIDC_SP_HTTP_TIMEOUT : '10000' ,
214
+ } ,
215
+ shouldSetTimeout : true ,
216
+ expectedUserDefinedHttpOptions : {
217
+ timeout : 10000
218
+ }
219
+ } ,
220
+ {
221
+ itMsg : 'should allow disabling the timeout by having its value set to 0' ,
222
+ env : {
223
+ GRIST_OIDC_SP_HTTP_TIMEOUT : '0' ,
224
+ } ,
225
+ expectedUserDefinedHttpOptions : {
226
+ timeout : 0
227
+ }
228
+ }
229
+ ] . forEach ( ctx => {
230
+ it ( ctx . itMsg , async ( ) => {
231
+ setEnvVars ( ) ;
232
+ Object . assign ( process . env , ctx . env ) ;
233
+ const clientStub = new ClientStub ( ) ;
234
+ const promise = OIDCConfigStubbed . buildWithStub ( clientStub . asClient ( ) ) ;
235
+ if ( ctx . expectedErrorMsg ) {
236
+ await assert . isRejected ( promise , ctx . expectedErrorMsg ) ;
237
+ } else {
238
+ await assert . isFulfilled ( promise , 'initOIDC should have been fulfilled' ) ;
239
+ const userDefinedOptions = ( clientStub [ custom . http_options ] as Function ) ( ) ;
240
+ assert . deepEqual ( userDefinedOptions , ctx . expectedUserDefinedHttpOptions ) ;
241
+ }
242
+ } ) ;
243
+ } ) ;
244
+ } ) ;
195
245
} ) ;
196
246
197
247
describe ( 'GRIST_OIDC_IDP_ENABLED_PROTECTIONS' , ( ) => {
0 commit comments