@@ -295,6 +295,142 @@ describe('node-vault', () => {
295295 } ) ;
296296 } ) ;
297297
298+ describe ( 'config.requestOptions forwarding' , ( ) => {
299+ let requestWithOpts = null ;
300+ let vaultWithOpts = null ;
301+
302+ const agentOpts = {
303+ securityOptions : 'SSL_OP_LEGACY_SERVER_CONNECT' ,
304+ } ;
305+
306+ function getURIWithOpts ( path ) {
307+ return [ vaultWithOpts . endpoint , vaultWithOpts . apiVersion , path ] . join ( '/' ) ;
308+ }
309+
310+ function assertRequestWithOpts ( thisRequest , params , done ) {
311+ return ( ) => {
312+ thisRequest . should . have . calledOnce ( ) ;
313+ thisRequest . calledWithMatch ( params ) . should . be . ok ( ) ;
314+ return done ( ) ;
315+ } ;
316+ }
317+
318+ beforeEach ( ( ) => {
319+ requestWithOpts = sinon . stub ( ) ;
320+ const resp = sinon . stub ( ) ;
321+ resp . statusCode = 200 ;
322+
323+ requestWithOpts . returns ( {
324+ then ( fn ) {
325+ return fn ( resp ) ;
326+ } ,
327+ catch ( fn ) {
328+ return fn ( ) ;
329+ } ,
330+ } ) ;
331+
332+ vaultWithOpts = index ( {
333+ endpoint : 'http://localhost:8200' ,
334+ token : '123' ,
335+ 'request-promise' : {
336+ defaults : ( ) => requestWithOpts ,
337+ } ,
338+ requestOptions : {
339+ agentOptions : agentOpts ,
340+ } ,
341+ } ) ;
342+ } ) ;
343+
344+ it ( 'should forward agentOptions from config.requestOptions in help()' , ( done ) => {
345+ const path = 'sys/policy' ;
346+ const params = {
347+ method : 'GET' ,
348+ uri : `${ getURIWithOpts ( path ) } ?help=1` ,
349+ agentOptions : agentOpts ,
350+ } ;
351+ vaultWithOpts . help ( path )
352+ . then ( assertRequestWithOpts ( requestWithOpts , params , done ) )
353+ . catch ( done ) ;
354+ } ) ;
355+
356+ it ( 'should forward agentOptions from config.requestOptions in read()' , ( done ) => {
357+ const path = 'secret/hello' ;
358+ const params = {
359+ method : 'GET' ,
360+ uri : getURIWithOpts ( path ) ,
361+ agentOptions : agentOpts ,
362+ } ;
363+ vaultWithOpts . read ( path )
364+ . then ( assertRequestWithOpts ( requestWithOpts , params , done ) )
365+ . catch ( done ) ;
366+ } ) ;
367+
368+ it ( 'should forward agentOptions from config.requestOptions in write()' , ( done ) => {
369+ const path = 'secret/hello' ;
370+ const params = {
371+ method : 'POST' ,
372+ uri : getURIWithOpts ( path ) ,
373+ agentOptions : agentOpts ,
374+ } ;
375+ vaultWithOpts . write ( path , { value : 'world' } )
376+ . then ( assertRequestWithOpts ( requestWithOpts , params , done ) )
377+ . catch ( done ) ;
378+ } ) ;
379+
380+ it ( 'should forward agentOptions from config.requestOptions in delete()' , ( done ) => {
381+ const path = 'secret/hello' ;
382+ const params = {
383+ method : 'DELETE' ,
384+ uri : getURIWithOpts ( path ) ,
385+ agentOptions : agentOpts ,
386+ } ;
387+ vaultWithOpts . delete ( path )
388+ . then ( assertRequestWithOpts ( requestWithOpts , params , done ) )
389+ . catch ( done ) ;
390+ } ) ;
391+
392+ it ( 'should forward agentOptions from config.requestOptions in list()' , ( done ) => {
393+ const path = 'secret/hello' ;
394+ const params = {
395+ method : 'LIST' ,
396+ uri : getURIWithOpts ( path ) ,
397+ agentOptions : agentOpts ,
398+ } ;
399+ vaultWithOpts . list ( path )
400+ . then ( assertRequestWithOpts ( requestWithOpts , params , done ) )
401+ . catch ( done ) ;
402+ } ) ;
403+
404+ it ( 'should forward agentOptions from config.requestOptions in generated functions' , ( done ) => {
405+ const name = 'myTestFunction' ;
406+ vaultWithOpts . generateFunction ( name , {
407+ method : 'GET' ,
408+ path : '/myroute' ,
409+ } ) ;
410+ const params = {
411+ agentOptions : agentOpts ,
412+ } ;
413+ vaultWithOpts [ name ] ( )
414+ . then ( assertRequestWithOpts ( requestWithOpts , params , done ) )
415+ . catch ( done ) ;
416+ } ) ;
417+
418+ it ( 'should allow per-call requestOptions to override config.requestOptions' , ( done ) => {
419+ const path = 'secret/hello' ;
420+ const overrideOpts = {
421+ securityOptions : 'SSL_OP_NO_SSLv3' ,
422+ } ;
423+ const params = {
424+ method : 'GET' ,
425+ uri : getURIWithOpts ( path ) ,
426+ agentOptions : overrideOpts ,
427+ } ;
428+ vaultWithOpts . read ( path , { agentOptions : overrideOpts } )
429+ . then ( assertRequestWithOpts ( requestWithOpts , params , done ) )
430+ . catch ( done ) ;
431+ } ) ;
432+ } ) ;
433+
298434 describe ( 'unwrap(options)' , ( ) => {
299435 it ( 'should return original response' , ( done ) => {
300436 const path = 'sys/wrapping/unwrap' ;
0 commit comments