@@ -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 , 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" ;
@@ -192,6 +192,55 @@ describe('OIDCConfig', () => {
192
192
} ) ;
193
193
} ) ;
194
194
} ) ;
195
+
196
+ describe ( 'GRIST_OIDC_SP_HTTP_TIMEOUT' , function ( ) {
197
+ [
198
+ {
199
+ itMsg : 'when omitted should not override openid-client default value' ,
200
+ expectedUserDefinedHttpOptions : { }
201
+ } ,
202
+ {
203
+ itMsg : 'should reject when the provided value is not a number' ,
204
+ env : {
205
+ GRIST_OIDC_SP_HTTP_TIMEOUT : '__NOT_A_NUMBER__' ,
206
+ } ,
207
+ 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 / ,
208
+ } ,
209
+ {
210
+ itMsg : 'should override openid-client timeout accordingly to the provided value' ,
211
+ env : {
212
+ GRIST_OIDC_SP_HTTP_TIMEOUT : '10000' ,
213
+ } ,
214
+ shouldSetTimeout : true ,
215
+ expectedUserDefinedHttpOptions : {
216
+ timeout : 10000
217
+ }
218
+ } ,
219
+ {
220
+ itMsg : 'should allow disabling the timeout by having its value set to 0' ,
221
+ env : {
222
+ GRIST_OIDC_SP_HTTP_TIMEOUT : '0' ,
223
+ } ,
224
+ expectedUserDefinedHttpOptions : {
225
+ timeout : 0
226
+ }
227
+ }
228
+ ] . forEach ( ctx => {
229
+ it ( ctx . itMsg , async ( ) => {
230
+ const setHttpOptionsDefaultsStub = sandbox . stub ( custom , 'setHttpOptionsDefaults' ) ;
231
+ setEnvVars ( ) ;
232
+ Object . assign ( process . env , ctx . env ) ;
233
+ const promise = OIDCConfigStubbed . buildWithStub ( ) ;
234
+ if ( ctx . expectedErrorMsg ) {
235
+ await assert . isRejected ( promise , ctx . expectedErrorMsg ) ;
236
+ } else {
237
+ await assert . isFulfilled ( promise , 'initOIDC should have been fulfilled' ) ;
238
+ assert . isTrue ( setHttpOptionsDefaultsStub . calledOnce , 'Should have called custom.setHttpOptionsDefaults' ) ;
239
+ assert . deepEqual ( setHttpOptionsDefaultsStub . firstCall . args [ 0 ] , ctx . expectedUserDefinedHttpOptions ) ;
240
+ }
241
+ } ) ;
242
+ } ) ;
243
+ } ) ;
195
244
} ) ;
196
245
197
246
describe ( 'GRIST_OIDC_IDP_ENABLED_PROTECTIONS' , ( ) => {
0 commit comments