From c4948dbc642d41a3bec02706f18aa438bf469865 Mon Sep 17 00:00:00 2001 From: Shane Tomlinson <stomlinson@mozilla.com> Date: Thu, 19 Jan 2012 12:13:59 +0000 Subject: [PATCH] Only do the code check if session_context returns a version. * Update network to allow for undefined code_version * Update unit tests. * Move code_check to static/shared/modules/ * Update build script for new location. issue #226 --- .../modules}/code_check.js | 24 +++++------ resources/static/shared/network.js | 4 +- .../modules}/code_check_unit_test.js | 42 +++++++++---------- resources/views/dialog_layout.ejs | 2 +- resources/views/layout.ejs | 1 + resources/views/test.ejs | 4 +- scripts/compress.sh | 4 +- 7 files changed, 38 insertions(+), 43 deletions(-) rename resources/static/{dialog/controllers => shared/modules}/code_check.js (78%) rename resources/static/test/qunit/{controllers => shared/modules}/code_check_unit_test.js (83%) diff --git a/resources/static/dialog/controllers/code_check.js b/resources/static/shared/modules/code_check.js similarity index 78% rename from resources/static/dialog/controllers/code_check.js rename to resources/static/shared/modules/code_check.js index 4543cda71..99798ba77 100644 --- a/resources/static/dialog/controllers/code_check.js +++ b/resources/static/shared/modules/code_check.js @@ -51,22 +51,18 @@ BrowserID.Modules.CodeCheck = (function() { data = data || {}; - self.checkRequired(data, "code_ver", "environment"); + self.checkRequired(data, "code_ver"); expectedCodeVer = data.code_ver; - if(data.environment === "PRODUCTION") { - getMostRecentCodeVersion.call(self, function(version) { - if(version) { - updateCodeIfNeeded.call(self, complete, version); - } - else { - complete(); - } - }); - } - else { - complete(true); - } + getMostRecentCodeVersion.call(self, function(version) { + if(version) { + updateCodeIfNeeded.call(self, complete, version); + } + else { + complete(true); + } + }); + sc.start.call(self, data); } }); diff --git a/resources/static/shared/network.js b/resources/static/shared/network.js index 47f1d9ad3..cf5710ce4 100644 --- a/resources/static/shared/network.js +++ b/resources/static/shared/network.js @@ -112,8 +112,7 @@ BrowserID.Network = (function() { }; domain_key_creation_time = result.domain_key_creation_time; auth_status = result.auth_level; - // XXX remove the ABC123 - code_version = result.code_version || "ABC123"; + code_version = result.code_version; // seed the PRNG // FIXME: properly abstract this out, probably by exposing a jwcrypto @@ -676,7 +675,6 @@ BrowserID.Network = (function() { codeVersion: function(onComplete, onFailure) { withContext(function() { try { - if (!code_version) throw "can't get code version!"; if (onComplete) onComplete(code_version); } catch(e) { if (onFailure) onFailure(e.toString()); diff --git a/resources/static/test/qunit/controllers/code_check_unit_test.js b/resources/static/test/qunit/shared/modules/code_check_unit_test.js similarity index 83% rename from resources/static/test/qunit/controllers/code_check_unit_test.js rename to resources/static/test/qunit/shared/modules/code_check_unit_test.js index 875ce63e9..90c2beb8c 100644 --- a/resources/static/test/qunit/controllers/code_check_unit_test.js +++ b/resources/static/test/qunit/shared/modules/code_check_unit_test.js @@ -7,22 +7,20 @@ "use strict"; var bid = BrowserID, - network = bid.Network, - xhr = bid.Mocks.xhr, + transport = bid.Mocks.xhr, helpers = bid.TestHelpers, controller; function createController(config) { var config = $.extend({ - code_ver: "ABC123", - environment: "PRODUCTION" + code_ver: "ABC123" }, config); controller = BrowserID.Modules.CodeCheck.create(); controller.start(config); } - module("controllers/code_check", { + module("shared/modules/code_check", { setup: function() { helpers.setup(); }, @@ -34,18 +32,29 @@ } }); - asyncTest("create controller with 'environment: DEBUG' - no code check performed", function() { + asyncTest("create controller with most recent scripts", function() { + createController({ + ready: function(mostRecent) { + equal(mostRecent, true, "scripts are the most recent"); + start(); + } + }); + }); + + asyncTest("create controller with no 'current' code_version given - do not update scripts", function() { + + transport.setContextInfo("code_version", undefined); + var scriptCount = $("head > script").length; createController({ - environment: "DEBUG", + code_ver: "ABC123", ready: function(mostRecent) { - equal(mostRecent, true, "working on the most recent version"); - + equal(mostRecent, true, "scripts are the most recent"); var scripts = $("head > script"); var scriptAdded = scripts.length !== scriptCount; - equal(scriptAdded, false, "a script was not added"); + equal(scriptAdded, false, "a script was not added to the dom"); if(scriptAdded) { // Only remove the last script if the script was actually added. @@ -56,18 +65,9 @@ } }); }); - - asyncTest("create controller with most recent scripts", function() { - createController({ - ready: function(mostRecent) { - equal(mostRecent, true, "scripts are the most recent"); - start(); - } - }); - }); - asyncTest("create controller with out of date scripts", function() { var scriptCount = $("head > script").length; + transport.setContextInfo("code_version", "ABC123"); createController({ code_ver: "ABC122", @@ -89,7 +89,7 @@ }); asyncTest("create controller with XHR error during script check", function() { - xhr.useResult("contextAjaxError"); + transport.useResult("contextAjaxError"); var scriptCount = $("head > script").length; createController({ diff --git a/resources/views/dialog_layout.ejs b/resources/views/dialog_layout.ejs index fb376bf3e..4a28e5f5a 100644 --- a/resources/views/dialog_layout.ejs +++ b/resources/views/dialog_layout.ejs @@ -88,12 +88,12 @@ <script src="/shared/modules/page_module.js"></script> <script src="/shared/modules/xhr_delay.js"></script> <script src="/shared/modules/xhr_disable_form.js"></script> + <script src="/shared/modules/code_check.js"></script> <script src="/dialog/resources/internal_api.js"></script> <script src="/dialog/resources/helpers.js"></script> <script src="/dialog/resources/state_machine.js"></script> - <script src="/dialog/controllers/code_check.js"></script> <script src="/dialog/controllers/actions.js"></script> <script src="/dialog/controllers/dialog.js"></script> <script src="/dialog/controllers/authenticate.js"></script> diff --git a/resources/views/layout.ejs b/resources/views/layout.ejs index 4f066eb83..2d1cdd797 100644 --- a/resources/views/layout.ejs +++ b/resources/views/layout.ejs @@ -49,6 +49,7 @@ <script src="/shared/modules/page_module.js"></script> <script src="/shared/modules/xhr_delay.js"></script> <script src="/shared/modules/xhr_disable_form.js"></script> + <script src="/shared/modules/code_check.js"></script> <script src="/pages/page_helpers.js"></script> <script src="/pages/index.js"></script> diff --git a/resources/views/test.ejs b/resources/views/test.ejs index d33f9facf..c21dd90fc 100644 --- a/resources/views/test.ejs +++ b/resources/views/test.ejs @@ -102,12 +102,12 @@ <script src="/shared/modules/page_module.js"></script> <script src="/shared/modules/xhr_delay.js"></script> <script src="/shared/modules/xhr_disable_form.js"></script> + <script src="/shared/modules/code_check.js"></script> <script src="/dialog/resources/internal_api.js"></script> <script src="/dialog/resources/helpers.js"></script> <script src="/dialog/resources/state_machine.js"></script> - <script src="/dialog/controllers/code_check.js"></script> <script src="/dialog/controllers/actions.js"></script> <script src="/dialog/controllers/pick_email.js"></script> <script src="/dialog/controllers/add_email.js"></script> @@ -147,6 +147,7 @@ <script src="qunit/shared/modules/page_module_unit_test.js"></script> <script src="qunit/shared/modules/xhr_delay_unit_test.js"></script> <script src="qunit/shared/modules/xhr_disable_form_unit_test.js"></script> + <script src="qunit/shared/modules/code_check_unit_test.js"></script> <script src="qunit/pages/browserid_unit_test.js"></script> <script src="qunit/pages/page_helpers_unit_test.js"></script> @@ -161,7 +162,6 @@ <script src="qunit/resources/helpers_unit_test.js"></script> <script src="qunit/resources/state_machine_unit_test.js"></script> - <script src="qunit/controllers/code_check_unit_test.js"></script> <script src="qunit/controllers/actions_unit_test.js"></script> <script src="qunit/controllers/pick_email_unit_test.js"></script> <script src="qunit/controllers/add_email_unit_test.js"></script> diff --git a/scripts/compress.sh b/scripts/compress.sh index f16ca016e..7e86abf6b 100755 --- a/scripts/compress.sh +++ b/scripts/compress.sh @@ -60,7 +60,7 @@ cd ../.. # produce the dialog js for locale in `../../scripts/production_locales`; do mkdir -p $BUILD_PATH/$locale - cat lib/jquery-1.7.1.min.js lib/winchan.js lib/underscore-min.js lib/vepbundle.js lib/ejs.js i18n/${locale}/client.json shared/gettext.js shared/browserid.js lib/hub.js lib/dom-jquery.js lib/module.js lib/jschannel.js shared/javascript-extensions.js shared/mediator.js shared/class.js shared/storage.js $BUILD_PATH/templates.js shared/renderer.js shared/error-display.js shared/screens.js shared/tooltip.js shared/validation.js shared/provisioning.js shared/network.js shared/user.js shared/error-messages.js shared/browser-support.js shared/wait-messages.js shared/helpers.js shared/modules/page_module.js shared/modules/xhr_delay.js shared/modules/xhr_disable_form.js dialog/resources/internal_api.js dialog/resources/helpers.js dialog/resources/state_machine.js dialog/controllers/code_check.js dialog/controllers/actions.js dialog/controllers/dialog.js dialog/controllers/authenticate.js dialog/controllers/forgot_password.js dialog/controllers/check_registration.js dialog/controllers/pick_email.js dialog/controllers/add_email.js dialog/controllers/required_email.js dialog/controllers/verify_primary_user.js dialog/controllers/provision_primary_user.js dialog/controllers/primary_user_provisioned.js dialog/controllers/email_chosen.js dialog/start.js > $BUILD_PATH/$locale/dialog.uncompressed.js + cat lib/jquery-1.7.1.min.js lib/winchan.js lib/underscore-min.js lib/vepbundle.js lib/ejs.js i18n/${locale}/client.json shared/gettext.js shared/browserid.js lib/hub.js lib/dom-jquery.js lib/module.js lib/jschannel.js shared/javascript-extensions.js shared/mediator.js shared/class.js shared/storage.js $BUILD_PATH/templates.js shared/renderer.js shared/error-display.js shared/screens.js shared/tooltip.js shared/validation.js shared/provisioning.js shared/network.js shared/user.js shared/error-messages.js shared/browser-support.js shared/wait-messages.js shared/helpers.js shared/modules/page_module.js shared/modules/xhr_delay.js shared/modules/xhr_disable_form.js shared/modules/code_check.js dialog/resources/internal_api.js dialog/resources/helpers.js dialog/resources/state_machine.js dialog/controllers/actions.js dialog/controllers/dialog.js dialog/controllers/authenticate.js dialog/controllers/forgot_password.js dialog/controllers/check_registration.js dialog/controllers/pick_email.js dialog/controllers/add_email.js dialog/controllers/required_email.js dialog/controllers/verify_primary_user.js dialog/controllers/provision_primary_user.js dialog/controllers/primary_user_provisioned.js dialog/controllers/email_chosen.js dialog/start.js > $BUILD_PATH/$locale/dialog.uncompressed.js done # produce the dialog css @@ -74,7 +74,7 @@ echo '****Building BrowserID.org HTML, CSS, and JS****' echo '' #produce the main site js -cat lib/vepbundle.js lib/jquery-1.7.1.min.js lib/underscore-min.js lib/ejs.js shared/javascript-extensions.js shared/browserid.js lib/dom-jquery.js lib/jschannel.js lib/winchan.js lib/hub.js $BUILD_PATH/templates.js shared/renderer.js shared/error-display.js shared/screens.js shared/error-messages.js shared/wait-messages.js shared/mediator.js shared/storage.js shared/network.js shared/provisioning.js shared/user.js shared/tooltip.js shared/validation.js shared/helpers.js shared/class.js shared/modules/page_module.js shared/modules/xhr_delay.js shared/modules/xhr_disable_form.js pages/page_helpers.js pages/start.js pages/index.js pages/add_email_address.js pages/verify_email_address.js pages/forgot.js pages/manage_account.js pages/signin.js pages/signup.js > $BUILD_PATH/browserid.uncompressed.js +cat lib/vepbundle.js lib/jquery-1.7.1.min.js lib/underscore-min.js lib/ejs.js shared/javascript-extensions.js shared/browserid.js lib/dom-jquery.js lib/jschannel.js lib/winchan.js lib/hub.js $BUILD_PATH/templates.js shared/renderer.js shared/error-display.js shared/screens.js shared/error-messages.js shared/wait-messages.js shared/mediator.js shared/storage.js shared/network.js shared/provisioning.js shared/user.js shared/tooltip.js shared/validation.js shared/helpers.js shared/class.js shared/modules/page_module.js shared/modules/xhr_delay.js shared/modules/xhr_disable_form.js shared/modules/code_check.js pages/page_helpers.js pages/start.js pages/index.js pages/add_email_address.js pages/verify_email_address.js pages/forgot.js pages/manage_account.js pages/signin.js pages/signup.js > $BUILD_PATH/browserid.uncompressed.js # produce the main site css cat css/common.css css/style.css css/m.css > $BUILD_PATH/browserid.uncompressed.css -- GitLab