You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by ss...@apache.org on 2012/11/06 16:40:25 UTC
svn commit: r1406188 - in /shindig/trunk/features/src:
main/javascript/features/container/container.js
test/javascript/features/container/container_test.js
Author: ssievers
Date: Tue Nov 6 15:40:25 2012
New Revision: 1406188
URL: http://svn.apache.org/viewvc?rev=1406188&view=rev
Log:
SHINDIG-1880 | If metadata and tokens are preloaded, the security token TTL from the metadata is used
Modified:
shindig/trunk/features/src/main/javascript/features/container/container.js
shindig/trunk/features/src/test/javascript/features/container/container_test.js
Modified: shindig/trunk/features/src/main/javascript/features/container/container.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/container/container.js?rev=1406188&r1=1406187&r2=1406188&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/container/container.js (original)
+++ shindig/trunk/features/src/main/javascript/features/container/container.js Tue Nov 6 15:40:25 2012
@@ -446,10 +446,16 @@ osapi.container.Container.prototype.init
/**
* Add list of gadgets to preload list
- * @param {Object} response hash of gadgets data.
+ *
+ * @param {Object}
+ * response hash of gadgets data.
+ * @param {Object=}
+ * opt_tokenResponse hash of gadget token data. Used in the case where the container is
+ * initialized with tokens.
* @private
*/
-osapi.container.Container.prototype.addPreloadGadgets_ = function(response) {
+osapi.container.Container.prototype.addPreloadGadgets_ = function(response, opt_tokenResponse) {
+ var tokenResponse = opt_tokenResponse || {};
for (var id in response) {
if (response[id].error) {
var message = ['Failed to preload gadget ', id, '.'].join('');
@@ -460,8 +466,15 @@ osapi.container.Container.prototype.addP
} else {
this.addPreloadedGadgetUrl_(id);
if (response[id][osapi.container.MetadataResponse.NEEDS_TOKEN_REFRESH]) {
+ // Check the opt_tokenResponse for the TTL of any preloaded tokens
+ var tokenTTL;
+ if (tokenResponse[id]) {
+ tokenTTL = tokenResponse[id][osapi.container.TokenResponse.TOKEN_TTL];
+ } else {
+ tokenTTL = response[id][osapi.container.MetadataResponse.TOKEN_TTL];
+ }
// Safe to re-schedule many times.
- this.scheduleRefreshTokens_(response[id][osapi.container.MetadataResponse.TOKEN_TTL]);
+ this.scheduleRefreshTokens_(tokenTTL);
}
}
}
@@ -484,7 +497,7 @@ osapi.container.Container.prototype.prel
this.service_.addGadgetMetadatas(gadgets, refTime);
this.service_.addGadgetTokens(tokens, refTime);
- this.addPreloadGadgets_(gadgets);
+ this.addPreloadGadgets_(gadgets, tokens);
};
Modified: shindig/trunk/features/src/test/javascript/features/container/container_test.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/test/javascript/features/container/container_test.js?rev=1406188&r1=1406187&r2=1406188&view=diff
==============================================================================
--- shindig/trunk/features/src/test/javascript/features/container/container_test.js (original)
+++ shindig/trunk/features/src/test/javascript/features/container/container_test.js Tue Nov 6 15:40:25 2012
@@ -36,6 +36,9 @@ ContainerTest.prototype.setUp = function
window.__CONTAINER_URI = shindig.uri('http://container.com');
this.shindigContainerGadgetSite = osapi.container.GadgetSite;
this.gadgetsRpc = gadgets.rpc;
+ window._setTimeout = window.setTimeout;
+ window.setTimeout = function(fn, time) {};
+ setTimeout = window.setTimeout;
};
ContainerTest.prototype.tearDown = function() {
@@ -43,6 +46,7 @@ ContainerTest.prototype.tearDown = funct
window.__CONTAINER_URI = this.containerUri;
osapi.container.GadgetSite = this.shindigContainerGadgetSite;
gadgets.rpc = this.gadgetsRpc;
+ window.setTimeout = window._setTimeout;
};
ContainerTest.prototype.testUnloadGadget = function() {
@@ -102,6 +106,23 @@ ContainerTest.prototype.testPreloadCache
});
};
+ContainerTest.prototype.testPreloadConfigTokens = function() {
+ this.setupGadgetsRpcRegister();
+ var container = new osapi.container.Container(
+ { 'preloadMetadatas' : { 'preloaded1.xml' : {'tokenTTL' : 200, 'needsTokenRefresh' : true}},
+ 'preloadTokens' : { 'preloaded1.xml' : {'tokenTTL' : 100}}});
+ this.assertEquals(100*1000*0.8, container.tokenRefreshInterval_);
+
+ container = new osapi.container.Container(
+ { 'preloadMetadatas' : { 'preloaded1.xml' : {'tokenTTL' : 200, 'needsTokenRefresh' : true}}});
+ this.assertEquals(200*1000*0.8, container.tokenRefreshInterval_);
+
+ container = new osapi.container.Container(
+ { 'preloadMetadatas' : { 'preloaded1.xml' : {'tokenTTL' : 200, 'needsTokenRefresh' : true}},
+ 'preloadTokens' : { 'preloaded1.xml' : {'tokenTTL' : 300}}});
+ this.assertEquals(300*1000*0.8, container.tokenRefreshInterval_);
+};
+
ContainerTest.prototype.testNavigateGadget = function() {
this.setupGadgetsRpcRegister();
var container = new osapi.container.Container({