From 5e8e08c4a045772e330894c1c19496c290c941dd Mon Sep 17 00:00:00 2001 From: Aleksej Tikhanovich Date: Mon, 3 Aug 2020 13:00:42 +0300 Subject: [PATCH 1/5] Added a property for disabling validation of tokens --- src/core/tokenHandler.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/core/tokenHandler.js b/src/core/tokenHandler.js index 2efaeb1..3115859 100644 --- a/src/core/tokenHandler.js +++ b/src/core/tokenHandler.js @@ -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 = { @@ -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); @@ -115,15 +119,16 @@ export default function tokenHandlerFactory(options) { * @returns {Promise} - 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 From 8d5f4c9420a051c4738f48abfb0aafa426e1149a Mon Sep 17 00:00:00 2001 From: Aleksej Tikhanovich Date: Mon, 3 Aug 2020 13:00:53 +0300 Subject: [PATCH 2/5] Added a test --- test/core/tokenHandler/test.html | 3 ++- test/core/tokenHandler/test.js | 44 +++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/test/core/tokenHandler/test.html b/test/core/tokenHandler/test.html index eeb5bf8..1c98b95 100644 --- a/test/core/tokenHandler/test.html +++ b/test/core/tokenHandler/test.html @@ -11,7 +11,8 @@ requirejs.config({ config: { 'core/tokenHandler': { - tokens: ['token1', 'token2', 'token3', 'token4', 'token5'] + tokens: ['token1', 'token2', 'token3', 'token4', 'token5'], + validateTokens: false } } }); diff --git a/test/core/tokenHandler/test.js b/test/core/tokenHandler/test.js index 2273d41..e801ce8 100644 --- a/test/core/tokenHandler/test.js +++ b/test/core/tokenHandler/test.js @@ -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); @@ -263,4 +263,46 @@ 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); + + Promise.all([]) + .then(function() { + return 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(); + }); + }); }); From f733efb9b93158284d6777725d602c819743a069 Mon Sep 17 00:00:00 2001 From: Aleksej Tikhanovich Date: Mon, 3 Aug 2020 13:01:07 +0300 Subject: [PATCH 3/5] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 94489cc..6b74a50 100644 --- a/package.json +++ b/package.json @@ -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", From 92bdc52ddfc06d7189273db21f360c6c9f8ac3ee Mon Sep 17 00:00:00 2001 From: Aleksej Tikhanovich Date: Tue, 4 Aug 2020 10:54:49 +0300 Subject: [PATCH 4/5] Added package-lock --- package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 4aa944b..de40b4c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@oat-sa/tao-core-sdk", - "version": "1.4.1", + "version": "1.5.0", "lockfileVersion": 1, "requires": true, "dependencies": { From d53f01c416905f1085bd977ef16f9b3399d4678f Mon Sep 17 00:00:00 2001 From: Aleksej Tihanovich Date: Tue, 4 Aug 2020 10:56:01 +0300 Subject: [PATCH 5/5] Update test/core/tokenHandler/test.js Co-authored-by: Andrii Ponamarov --- test/core/tokenHandler/test.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/core/tokenHandler/test.js b/test/core/tokenHandler/test.js index e801ce8..592fe6c 100644 --- a/test/core/tokenHandler/test.js +++ b/test/core/tokenHandler/test.js @@ -270,10 +270,7 @@ define(['core/promise', 'core/tokenHandler', 'jquery.mockjax'], function(Promise assert.expect(6); - Promise.all([]) - .then(function() { - return tokenHandler.getToken(); - }) + tokenHandler.getToken() .then(function($token) { assert.equal($token, 'token1', 'The token1 is correct'); return tokenHandler.getToken();