diff --git a/resources/static/common/js/models/interaction_data.js b/resources/static/common/js/models/interaction_data.js index c1df7522cdaea83ba6545fd4c8b3eec39d7ded75..d40da5139bb7ea9923e14662c365911297b6f6a7 100644 --- a/resources/static/common/js/models/interaction_data.js +++ b/resources/static/common/js/models/interaction_data.js @@ -22,7 +22,8 @@ BrowserID.Models.InteractionData = (function() { 'number_sites_remembered', 'orphaned', 'new_account', - 'email_type' + 'email_type', + 'rp_api' ]; diff --git a/resources/static/dialog/js/modules/dialog.js b/resources/static/dialog/js/modules/dialog.js index 6566944dd2739f4fe43e9d56ad1aa8765189e436..00d6e8f8b6f27f888a3b8555a779f1e4ae94792a 100644 --- a/resources/static/dialog/js/modules/dialog.js +++ b/resources/static/dialog/js/modules/dialog.js @@ -110,6 +110,20 @@ BrowserID.Modules.Dialog = (function() { throw "must be an absolute path: (" + path + ")"; } + function validateRPAPI(rpAPI) { + var VALID_RP_API_VALUES = [ + "watch_without_onready", + "watch_with_onready", + "get", + "getVerifiedEmail", + "internal" + ]; + + if (_.indexOf(VALID_RP_API_VALUES, rpAPI) === -1) { + throw "invalid value for rp_api: " + rpAPI; + } + } + var Dialog = bid.Modules.PageModule.extend({ start: function(options) { var self=this; @@ -170,6 +184,13 @@ BrowserID.Modules.Dialog = (function() { // verify params try { + var rpAPI = paramsFromRP.rp_api; + if (rpAPI) { + // throws if an invalid rp_api value + validateRPAPI(rpAPI); + self.publish("kpi_data", { rp_api: rpAPI }); + } + if (paramsFromRP.requiredEmail) { helpers.log("requiredEmail has been deprecated"); } diff --git a/resources/static/test/cases/common/js/models/interaction_data.js b/resources/static/test/cases/common/js/models/interaction_data.js index deab52638ea8db94cd15649f2c3410dd09523e84..c0d79f4f4a44fdcdfb0282f0d5e77207ecafd251 100644 --- a/resources/static/test/cases/common/js/models/interaction_data.js +++ b/resources/static/test/cases/common/js/models/interaction_data.js @@ -100,7 +100,8 @@ number_sites_remembered: 3, orphaned: false, new_account: true, - email_type: "assertion" + email_type: "assertion", + rp_api: "watch_without_onready" }); model.stageCurrent(); @@ -123,7 +124,8 @@ number_sites_remembered: 3, orphaned: false, new_account: true, - email_type: "assertion" + email_type: "assertion", + rp_api: "watch_without_onready" }); testHelpers.testUndefined(mostRecentSessionData.local_timestamp, "non-whitelisted valued stripped"); diff --git a/resources/static/test/cases/dialog/js/modules/dialog.js b/resources/static/test/cases/dialog/js/modules/dialog.js index 5bb1d19f4636ed9c45f2213713bed1b97efd0a3b..052f05da04812b546db6305620948d3f5df232f7 100644 --- a/resources/static/test/cases/dialog/js/modules/dialog.js +++ b/resources/static/test/cases/dialog/js/modules/dialog.js @@ -68,6 +68,35 @@ controller.start(options); } + function testMessageNotExpected(msg) { + mediator.subscribe(msg, function(msg, info) { + ok(false, "unexpected message: " + msg); + }); + } + + function testExpectGetFailure(options, expectedErrorMessage) { + _.extend(options, { + ready: function() { + testMessageNotExpected("kpi_data"); + testMessageNotExpected("start"); + + var retval = controller.get(HTTPS_TEST_DOMAIN, options); + + if (expectedErrorMessage) { + equal(retval, expectedErrorMessage, "expected error: " + expectedErrorMessage); + } + else { + ok(retval, "error message returned"); + } + + testErrorVisible(); + start(); + } + }); + createController(options); + } + + module("dialog/js/modules/dialog", { setup: function() { winMock = new WinMock(); @@ -620,5 +649,26 @@ } }); }); + + asyncTest("get with valid rp_api - allowed", function() { + createController({ + ready: function() { + mediator.subscribe("kpi_data", function(msg, info) { + equal(info.rp_api, "get"); + start(); + }); + + controller.get(HTTPS_TEST_DOMAIN, { + rp_api: "get" + }); + } + }); + }); + + asyncTest("get with invalid rp_api - not allowed", function() { + testExpectGetFailure({ + rp_api: "invalid_value" + }, "invalid value for rp_api: invalid_value"); + }); }());