|
@@ -84,6 +84,19 @@ describe( 'Token', () => {
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ it( 'should not refresh token if autoRefresh is disabled in options', async () => {
|
|
|
|
|
+ const clock = sinon.useFakeTimers( { toFake: [ 'setTimeout' ] } );
|
|
|
|
|
+ const tokenInitValue = `header.${ btoa( JSON.stringify( { exp: Date.now() + 3600000 } ) ) }.signature`;
|
|
|
|
|
+
|
|
|
|
|
+ const token = new Token( 'http://token-endpoint', { initValue: tokenInitValue, autoRefresh: false } );
|
|
|
|
|
+
|
|
|
|
|
+ await token.init();
|
|
|
|
|
+
|
|
|
|
|
+ await clock.tickAsync( 1800000 );
|
|
|
|
|
+
|
|
|
|
|
+ expect( requests ).to.be.empty;
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
it( 'should refresh token with time specified in token `exp` payload property', async () => {
|
|
it( 'should refresh token with time specified in token `exp` payload property', async () => {
|
|
|
const clock = sinon.useFakeTimers( { toFake: [ 'setTimeout' ] } );
|
|
const clock = sinon.useFakeTimers( { toFake: [ 'setTimeout' ] } );
|
|
|
const tokenInitValue = `header.${ btoa( JSON.stringify( { exp: Date.now() + 3600000 } ) ) }.signature`;
|
|
const tokenInitValue = `header.${ btoa( JSON.stringify( { exp: Date.now() + 3600000 } ) ) }.signature`;
|
|
@@ -262,5 +275,16 @@ describe( 'Token', () => {
|
|
|
|
|
|
|
|
requests[ 0 ].respond( 200, '', 'token-value' );
|
|
requests[ 0 ].respond( 200, '', 'token-value' );
|
|
|
} );
|
|
} );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should use default options when none passed', done => {
|
|
|
|
|
+ Token.create( 'http://token-endpoint' )
|
|
|
|
|
+ .then( token => {
|
|
|
|
|
+ expect( token._options ).to.eql( { autoRefresh: true } );
|
|
|
|
|
+
|
|
|
|
|
+ done();
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ requests[ 0 ].respond( 200, '', 'token-value' );
|
|
|
|
|
+ } );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|