@@ -45,8 +45,11 @@ describe('Request', function () {
4545 . onGet ( '/timeout' ) . timeout ( )
4646 . onGet ( '/authError' ) . reply ( 400 , { error : 'invalid_request' , error_description : 'Missing parameters, "username" and "password" are required' } )
4747 . onGet ( '/appError' ) . reply ( 400 , { error : { code : 1 , message : 'Access token is missing' } } )
48- . onGet ( '/tokenExpired401' ) . reply ( 401 , { error : { code : 3 , message : 'Access token expired' } } )
49- . onGet ( '/tokenExpired403' ) . reply ( 403 , { error : { code : 3 , message : 'Access token expired' } } )
48+ . onGet ( '/tokenExpired401' ) . replyOnce ( 401 , { error : { code : 3 , message : 'Access token expired' } } )
49+ . onGet ( '/tokenExpired401' ) . reply ( 200 , { body : '401' } )
50+ . onGet ( '/tokenExpired403' ) . replyOnce ( 403 , { error : { code : 3 , message : 'Access token expired' } } )
51+ . onGet ( '/tokenExpired403' ) . reply ( 200 , { body : '403' } )
52+ . onPost ( '/oauth2/token' ) . reply ( 200 , authResult )
5053 . onGet ( '/noMessageError' ) . reply ( 500 , { error : { code : 99 } } )
5154 . onAny ( ) . reply ( 404 )
5255 } )
@@ -75,6 +78,16 @@ describe('Request', function () {
7578 await client . authenticate ( authResult . access_token , undefined , 3600 + Date . now ( ) / 1000 )
7679 await assert . rejects ( async ( ) => { await client . request ( 'GET' , '/noMessageError' ) } , new Error ( 'HTTP request /noMessageError failed: {"code":99} (500)' ) )
7780 } )
81+ it ( 'should retry in case of HTTP 401 expired token' , async function ( ) {
82+ await client . authenticate ( authResult . access_token , authResult . refresh_token , 3600 + Date . now ( ) / 1000 )
83+ const result = await client . request ( 'GET' , '/tokenExpired401' )
84+ assert . deepStrictEqual ( result , { body : '401' } )
85+ } )
86+ it ( 'should retry in case of HTTP 403 expired token' , async function ( ) {
87+ await client . authenticate ( authResult . access_token , authResult . refresh_token , 3600 + Date . now ( ) / 1000 )
88+ const result = await client . request ( 'GET' , '/tokenExpired403' )
89+ assert . deepStrictEqual ( result , { body : '403' } )
90+ } )
7891} )
7992
8093describe ( 'Authentication' , function ( ) {
0 commit comments