@@ -16,6 +16,7 @@ describe('common methods', () => {
1616 req = {
1717 body : { } ,
1818 params : { } ,
19+ headers : { } ,
1920 bitgo,
2021 } as express . Request ;
2122 next = ( ) => undefined ;
@@ -52,6 +53,36 @@ describe('common methods', () => {
5253 result . body . should . deepEqual ( { success : true } ) ;
5354 } ) ;
5455
56+ it ( 'should forward X-BitGo-OTP header when present' , async ( ) => {
57+ const url = 'https://example.com/api' ;
58+ const setStub = sandbox . stub ( ) ;
59+ const response = { res : { statusCode : 200 } , result : async ( ) => ( { success : true } ) , set : setStub } ;
60+ sandbox
61+ . stub ( bitgo , 'get' )
62+ . withArgs ( url )
63+ . returns ( response as any ) ;
64+
65+ req . headers = { 'x-bitgo-otp' : '123456' } as any ;
66+ const result = await redirectRequest ( bitgo , 'GET' , url , req , next ) ;
67+ result . status . should . equal ( 200 ) ;
68+ setStub . calledWith ( 'x-bitgo-otp' , '123456' ) . should . be . true ( ) ;
69+ } ) ;
70+
71+ it ( 'should not forward X-BitGo-OTP header when not present' , async ( ) => {
72+ const url = 'https://example.com/api' ;
73+ const setStub = sandbox . stub ( ) ;
74+ const response = { res : { statusCode : 200 } , result : async ( ) => ( { success : true } ) , set : setStub } ;
75+ sandbox
76+ . stub ( bitgo , 'get' )
77+ . withArgs ( url )
78+ . returns ( response as any ) ;
79+
80+ req . headers = { } as any ;
81+ const result = await redirectRequest ( bitgo , 'GET' , url , req , next ) ;
82+ result . status . should . equal ( 200 ) ;
83+ setStub . calledWith ( 'x-bitgo-otp' ) . should . be . false ( ) ;
84+ } ) ;
85+
5586 it ( 'should handle error response and return status and body' , async ( ) => {
5687 const url = 'https://example.com/api' ;
5788 const response = {
0 commit comments