Skip to content

Commit

Permalink
Merge branch 'release-1.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dresha-dev committed Aug 4, 2020
2 parents d222ef0 + ff89b9f commit f480e10
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oat-sa/tao-core-sdk",
"version": "1.4.1",
"version": "1.5.0",
"displayName": "TAO Core SDK",
"description": "Core libraries of TAO",
"homepage": "https://github.com/oat-sa/tao-core-sdk-fe#readme",
Expand Down
11 changes: 8 additions & 3 deletions src/core/tokenHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import module from 'module';
import tokenStoreFactory from 'core/tokenStore';
import promiseQueue from 'core/promiseQueue';

let validateTokensOpt = true;
let clientConfigFetched = false;

const defaults = {
Expand Down Expand Up @@ -89,7 +90,10 @@ export default function tokenHandlerFactory(options) {
if (queueSize > 0) {
// Token available, use it
return getFirstTokenValue();
} else if (!clientConfigFetched) {
} else if (!validateTokensOpt) {
return this.getClientConfigTokens()
.then(getFirstTokenValue);
}else if (!clientConfigFetched) {
// Client Config allowed! (first and only time)
return this.getClientConfigTokens()
.then(getFirstTokenValue);
Expand All @@ -115,15 +119,16 @@ export default function tokenHandlerFactory(options) {
* @returns {Promise<Boolean>} - resolves true when completed
*/
getClientConfigTokens() {
const {tokens} = module.config();
const {tokens, validateTokens} = module.config();
const clientTokens = (tokens || []).map(serverToken => ({
value: serverToken,
receivedAt: Date.now()
}));
// set validateToken options from the config
validateTokensOpt = validateTokens;

// Record that this function ran:
clientConfigFetched = true;

return Promise.resolve(clientTokens)
.then(newTokens => {
// Add the fetched tokens to the store
Expand Down
3 changes: 2 additions & 1 deletion test/core/tokenHandler/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
requirejs.config({
config: {
'core/tokenHandler': {
tokens: ['token1', 'token2', 'token3', 'token4', 'token5']
tokens: ['token1', 'token2', 'token3', 'token4', 'token5'],
validateTokens: false
}
}
});
Expand Down
41 changes: 40 additions & 1 deletion test/core/tokenHandler/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ define(['core/promise', 'core/tokenHandler', 'jquery.mockjax'], function(Promise
{name: 'getClientConfigTokens'},
{name: 'clearStore'},
{name: 'getQueueLength'},
{name: 'setMaxSize'}
{name: 'setMaxSize'},
]).test('instance API ', function(data, assert) {
var instance = tokenHandlerFactory();
assert.expect(1);
Expand Down Expand Up @@ -263,4 +263,43 @@ define(['core/promise', 'core/tokenHandler', 'jquery.mockjax'], function(Promise
ready();
});
});

QUnit.test('validateTokens', function(assert) {
var ready = assert.async();
var tokenHandler = new tokenHandlerFactory({ maxSize: 5, validateTokens: false});

assert.expect(6);

tokenHandler.getToken()
.then(function($token) {
assert.equal($token, 'token1', 'The token1 is correct');
return tokenHandler.getToken();
})
.then(function($token) {
assert.equal($token, 'token2', 'The token2 is correct');
return tokenHandler.getToken();
})
.then(function($token) {
assert.equal($token, 'token3', 'The token3 is correct');
return tokenHandler.getToken();
})
.then(function($token) {
assert.equal($token, 'token4', 'The token4 is correct');
return tokenHandler.getToken();
})
.then(function($token) {
assert.equal($token, 'token5', 'The token5 is correct');
return tokenHandler.getToken();
})
.then(function($token) {
assert.equal($token, 'token1', 'The token1 is correct');
})
.then(function() {
ready();
})
.catch(function(err) {
assert.ok(false, err.message);
ready();
});
});
});

0 comments on commit f480e10

Please sign in to comment.