From 54f9cbf46cf162d801d1a5a900f4b57778e3d64c Mon Sep 17 00:00:00 2001 From: Shane Tomlinson <stomlinson@mozilla.com> Date: Wed, 18 Apr 2012 14:59:05 +0100 Subject: [PATCH] TOS/PP updates to only show TOS/PP where needed. Show the BrowserID and RP TOS/PP at the correct time with the correct text. * BID TOS/PP is only displayed to new users. * RP TOS/PP is only displayed to new users, or users who have not been to a site before. Details: * Bring over rp_info.js from another branch. Module charged with displaying RP related info. * In authenticate, add_email, and pick_email controllers, trigger message to update "next" button text to be correct for the particular screen. * To dom-jquery, add hide and show functions. Call controllers that need to display the TOS/PP info with siteTOSPP parameter. This reduces the amount of data that needs to be passed around. issue #1240 --- .../static/dialog/controllers/actions.js | 8 ++-- .../static/dialog/controllers/add_email.js | 16 ++++--- .../static/dialog/controllers/authenticate.js | 22 ++++++--- resources/static/dialog/controllers/dialog.js | 6 +-- .../static/dialog/controllers/pick_email.js | 10 +++- .../static/dialog/controllers/rp_info.js | 7 ++- .../dialog/controllers/verify_primary_user.js | 11 +++-- resources/static/dialog/css/popup.css | 14 +++++- resources/static/dialog/resources/helpers.js | 10 +++- resources/static/dialog/resources/state.js | 46 +++++++++++++------ resources/static/dialog/views/add_email.ejs | 14 ------ .../static/dialog/views/authenticate.ejs | 17 ++++--- resources/static/dialog/views/pick_email.ejs | 14 +----- .../static/dialog/views/required_email.ejs | 14 ++---- resources/static/dialog/views/rp_info.ejs | 9 ++++ .../dialog/views/verify_primary_user.ejs | 44 ++++++++---------- resources/static/lib/dom-jquery.js | 6 +-- .../static/shared/modules/page_module.js | 1 + resources/static/shared/user.js | 8 ++++ .../static/test/cases/controllers/actions.js | 17 ++++++- .../test/cases/controllers/add_email.js | 10 ---- .../static/test/cases/controllers/dialog.js | 1 + .../static/test/cases/controllers/rp_info.js | 19 +++++++- .../cases/controllers/verify_primary_user.js | 14 +++--- .../static/test/cases/resources/state.js | 46 ++++++++++++++----- resources/static/test/cases/shared/user.js | 16 +++++++ resources/static/test/testHelpers/helpers.js | 18 ++++++-- 27 files changed, 261 insertions(+), 157 deletions(-) diff --git a/resources/static/dialog/controllers/actions.js b/resources/static/dialog/controllers/actions.js index 80435e522..1bf05562e 100644 --- a/resources/static/dialog/controllers/actions.js +++ b/resources/static/dialog/controllers/actions.js @@ -58,10 +58,6 @@ BrowserID.Modules.Actions = (function() { if(data.ready) _.defer(data.ready); }, - doRPInfo: function(info) { - startService("rp_info", info); - }, - doCancel: function() { if(onsuccess) onsuccess(null); }, @@ -157,6 +153,10 @@ BrowserID.Modules.Actions = (function() { doGenerateAssertion: function(info) { startService("generate_assertion", info); + }, + + doRPInfo: function(info) { + startService("rp_info", info); } }); diff --git a/resources/static/dialog/controllers/add_email.js b/resources/static/dialog/controllers/add_email.js index c9a8c638c..924d242c1 100644 --- a/resources/static/dialog/controllers/add_email.js +++ b/resources/static/dialog/controllers/add_email.js @@ -1,5 +1,5 @@ /*jshint browser:true, jQuery: true, forin: true, laxbreak:true */ -/*global _: true, BrowserID: true, PageController: true */ +/*global _: true, BrowserID: true, PageController: true, gettext: true */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ @@ -8,6 +8,7 @@ BrowserID.Modules.AddEmail = (function() { var bid = BrowserID, helpers = bid.Helpers, + user = bid.User, dialogHelpers = helpers.Dialog, errors = bid.Errors, complete = helpers.complete, @@ -33,12 +34,15 @@ BrowserID.Modules.AddEmail = (function() { var Module = bid.Modules.PageModule.extend({ start: function(options) { var self=this, - templateData = helpers.extend({}, options, { - privacy_url: options.privacyURL || null, - tos_url: options.tosURL || null - }); + originEmail = user.getOriginEmail(); - self.renderDialog("add_email", templateData); + self.renderDialog("add_email", options); + + // Only show the RP's TOS/PP if the user has not been to this site + // before. + if(!originEmail && options.siteTOSPP) { + dialogHelpers.showRPTosPP.call(self); + } self.click("#cancel", cancelAddEmail); Module.sc.start.call(self, options); diff --git a/resources/static/dialog/controllers/authenticate.js b/resources/static/dialog/controllers/authenticate.js index ac413aa99..de6a81d0b 100644 --- a/resources/static/dialog/controllers/authenticate.js +++ b/resources/static/dialog/controllers/authenticate.js @@ -18,6 +18,7 @@ BrowserID.Modules.Authenticate = (function() { dom = bid.DOM, lastEmail = "", addressInfo, + siteTOSPP, hints = ["returning","start","addressInfo"]; function getEmail() { @@ -33,6 +34,7 @@ BrowserID.Modules.Authenticate = (function() { } else { showHint("start"); + enterEmailState.call(self); complete(info.ready); } } @@ -96,7 +98,7 @@ BrowserID.Modules.Authenticate = (function() { function showHint(showSelector, callback) { _.each(hints, function(className) { if(className != showSelector) { - $("." + className).not("." + showSelector).hide(); + dom.hide("." + className + ":not(." + showSelector + ")"); } }); @@ -110,8 +112,8 @@ BrowserID.Modules.Authenticate = (function() { }); } - function enterEmailState(el) { - if (!$("#email").is(":disabled")) { + function enterEmailState() { + if (!dom.is("#email", ":disabled")) { this.submit = checkEmail; showHint("start"); } @@ -127,6 +129,8 @@ BrowserID.Modules.Authenticate = (function() { showHint("returning", function() { dom.focus("#password"); }); + + complete(callback); } @@ -156,12 +160,16 @@ BrowserID.Modules.Authenticate = (function() { var self=this; self.renderDialog("authenticate", { sitename: user.getHostname(), - email: lastEmail, - privacy_url: options.privacyURL, - tos_url: options.tosURL + email: lastEmail }); - $(".returning,.start").hide(); + dom.hide(".returning,.start"); + + // We have to show the TOS/PP agreement to *all* users here. Users who + // are already authenticated to their IdP but do not have a Persona + // account automatically have an account created with no further + // interaction. + dom.show(".tospp"); self.bind("#email", "keyup", emailKeyUp); self.click("#forgotPassword", forgotPassword); diff --git a/resources/static/dialog/controllers/dialog.js b/resources/static/dialog/controllers/dialog.js index 36e66dca6..7fc42259b 100644 --- a/resources/static/dialog/controllers/dialog.js +++ b/resources/static/dialog/controllers/dialog.js @@ -73,10 +73,6 @@ BrowserID.Modules.Dialog = (function() { channel && channel.detach(); } - function setOrigin(origin) { - user.setOrigin(origin); - } - function onWindowUnload() { this.publish("window_unload"); } @@ -139,7 +135,7 @@ BrowserID.Modules.Dialog = (function() { var self=this, hash = win.location.hash; - setOrigin(origin_url); + user.setOrigin(origin_url); if (startExternalDependencies) { diff --git a/resources/static/dialog/controllers/pick_email.js b/resources/static/dialog/controllers/pick_email.js index 4382645c7..95adea65b 100644 --- a/resources/static/dialog/controllers/pick_email.js +++ b/resources/static/dialog/controllers/pick_email.js @@ -83,6 +83,7 @@ BrowserID.Modules.PickEmail = (function() { var Module = bid.Modules.PageModule.extend({ start: function(options) { var origin = user.getOrigin(), + originEmail = user.getOriginEmail(), self=this; options = options || {}; @@ -95,10 +96,17 @@ BrowserID.Modules.PickEmail = (function() { self.renderDialog("pick_email", { identities: identities, - siteemail: storage.site.get(origin, "email"), + siteemail: originEmail, privacy_url: options.privacyURL, tos_url: options.tosURL }); + + // If the user has been to this site before, they have already implicitly + // agreed to TOS/PP agreement. Don't bug them a second time. + if (!originEmail && options.siteTOSPP) { + dialogHelpers.showRPTosPP.call(self); + } + dom.getElements("body").css("opacity", "1"); if (dom.getElements("#selectEmail input[type=radio]:visible").length === 0) { // If there is only one email address, the radio button is never shown, diff --git a/resources/static/dialog/controllers/rp_info.js b/resources/static/dialog/controllers/rp_info.js index 3bc9b20ed..b6f6b55cd 100644 --- a/resources/static/dialog/controllers/rp_info.js +++ b/resources/static/dialog/controllers/rp_info.js @@ -7,7 +7,8 @@ /** * Purpose: - * Display to the user RP related data such as hostname, name, and logo. + * Display to the user RP related data such as hostname, sitename, logo, + * TOS/PP, etc. */ BrowserID.Modules.RPInfo = (function() { "use strict"; @@ -32,7 +33,9 @@ BrowserID.Modules.RPInfo = (function() { renderer.render("#rp_info", "rp_info", { hostname: options.hostname, siteName: options.siteName, - siteLogo: options.siteLogo + siteLogo: options.siteLogo, + privacyURL: options.privacyURL, + tosURL: options.tosURL }); sc.start.call(this, options); diff --git a/resources/static/dialog/controllers/verify_primary_user.js b/resources/static/dialog/controllers/verify_primary_user.js index 9e38e6be1..e42deec4c 100644 --- a/resources/static/dialog/controllers/verify_primary_user.js +++ b/resources/static/dialog/controllers/verify_primary_user.js @@ -12,7 +12,9 @@ BrowserID.Modules.VerifyPrimaryUser = (function() { add, email, auth_url, + dom = bid.DOM, helpers = bid.Helpers, + dialogHelpers = helpers.Dialog, complete = helpers.complete; function verify(callback) { @@ -48,12 +50,15 @@ BrowserID.Modules.VerifyPrimaryUser = (function() { auth_url = data.auth_url; var templateData = helpers.extend({}, data, { - requiredEmail: data.requiredEmail || false, - privacy_url: data.privacyURL || null, - tos_url: data.tosURL || null + requiredEmail: data.requiredEmail || false }); self.renderDialog("verify_primary_user", templateData); + if(data.siteTOSPP) { + dialogHelpers.showRPTosPP.call(self); + } + dom.show(".tospp"); + self.click("#cancel", cancel); sc.start.call(self, data); diff --git a/resources/static/dialog/css/popup.css b/resources/static/dialog/css/popup.css index 39d97a1f5..5f5f7452e 100644 --- a/resources/static/dialog/css/popup.css +++ b/resources/static/dialog/css/popup.css @@ -389,9 +389,19 @@ div#required_email { margin-top: 10px; } +.submit > p + p:last-child { + margin-top: 15px; +} + .tospp { - color: #787878; - clear: right; + display: none; + font-size: 11px; + line-height: 1.2; +} + +#rp_info .tospp { + margin: 10px auto; + max-width: 280px; } a.emphasize { diff --git a/resources/static/dialog/resources/helpers.js b/resources/static/dialog/resources/helpers.js index 64225604a..7419a230c 100644 --- a/resources/static/dialog/resources/helpers.js +++ b/resources/static/dialog/resources/helpers.js @@ -11,7 +11,8 @@ complete = helpers.complete, user = bid.User, tooltip = bid.Tooltip, - errors = bid.Errors; + errors = bid.Errors, + dom = bid.DOM; function animateClose(callback) { var body = $("body"), @@ -133,6 +134,10 @@ }, self.getErrorDialog(errors.addEmail, callback)); } + function showRPTosPP() { + dom.show(".rptospp"); + } + helpers.Dialog = helpers.Dialog || {}; helpers.extend(helpers.Dialog, { @@ -143,7 +148,8 @@ addSecondaryEmail: addSecondaryEmail, resetPassword: resetPassword, cancelEvent: helpers.cancelEvent, - animateClose: animateClose + animateClose: animateClose, + showRPTosPP: showRPTosPP }); }()); diff --git a/resources/static/dialog/resources/state.js b/resources/static/dialog/resources/state.js index c56eee0dd..ad6947ecf 100644 --- a/resources/static/dialog/resources/state.js +++ b/resources/static/dialog/resources/state.js @@ -42,8 +42,7 @@ BrowserID.State = (function() { handleState("start", function(msg, info) { self.hostname = info.hostname; - self.privacyURL = info.privacyURL; - self.tosURL = info.tosURL; + self.siteTOSPP = !!(info.privacyURL && info.tosURL); requiredEmail = info.requiredEmail; startAction(false, "doRPInfo", info); @@ -77,8 +76,7 @@ BrowserID.State = (function() { self.email = requiredEmail; startAction("doAuthenticateWithRequiredEmail", { email: requiredEmail, - privacyURL: self.privacyURL, - tosURL: self.tosURL + siteTOSPP: self.siteTOSPP }); } else if (authenticated) { @@ -89,8 +87,8 @@ BrowserID.State = (function() { }); handleState("authenticate", function(msg, info) { - info.privacyURL = self.privacyURL; - info.tosURL = self.tosURL; + info = info || {}; + info.siteTOSPP = self.siteTOSPP; startAction("doAuthenticate", info); }); @@ -167,8 +165,7 @@ BrowserID.State = (function() { add: !!addPrimaryUser, email: email, requiredEmail: !!requiredEmail, - privacyURL: self.privacyURL, - tosURL: self.tosURL + siteTOSPP: self.siteTOSPP }); if (primaryVerificationInfo) { @@ -205,8 +202,7 @@ BrowserID.State = (function() { handleState("pick_email", function() { startAction("doPickEmail", { origin: self.hostname, - privacyURL: self.privacyURL, - tosURL: self.tosURL + siteTOSPP: self.siteTOSPP }); }); @@ -245,8 +241,7 @@ BrowserID.State = (function() { startAction("doAuthenticateWithRequiredEmail", { email: email, secondary_auth: true, - privacyURL: self.privacyURL, - tosURL: self.tosURL + siteTOSPP: self.siteTOSPP }); } else { @@ -309,6 +304,9 @@ BrowserID.State = (function() { // finally reset, the password_reset message will be raised where we must // await email confirmation. self.resetPasswordEmail = info.email; + info = helpers.extend(info || {}, { + siteTOSPP: self.siteTOSPP + }); startAction(false, "doForgotPassword", info); }); @@ -344,10 +342,28 @@ BrowserID.State = (function() { redirectToState("email_chosen", info); }); + handleState("reset_password", function(msg, info) { + info = info || {}; + // reset_password says the user has confirmed that they want to + // reset their password. doResetPassword will attempt to invoke + // the create_user wsapi. If the wsapi call is successful, + // the user will be shown the "go verify your account" message. + + // We have to save the staged email address here for when the user + // verifies their account and user_confirmed is called. + self.stagedEmail = info.email; + startAction(false, "doResetPassword", info); + }); + handleState("add_email", function(msg, info) { - info = helpers.extend(info, { - privacyURL: self.privacyURL, - tosURL: self.tosURL + // add_email indicates the user wishes to add an email to the account, + // the add_email screen must be displayed. After the user enters the + // email address they wish to add, add_email will trigger + // either 1) primary_user or 2) email_staged. #1 occurs if the email + // address is a primary address, #2 occurs if the address is a secondary + // and the verification email has been sent. + info = helpers.extend(info || {}, { + siteTOSPP: self.siteTOSPP }); startAction("doAddEmail", info); diff --git a/resources/static/dialog/views/add_email.ejs b/resources/static/dialog/views/add_email.ejs index 5af78c55b..b20fda347 100644 --- a/resources/static/dialog/views/add_email.ejs +++ b/resources/static/dialog/views/add_email.ejs @@ -30,22 +30,8 @@ </ul> <div class="submit cf"> - <% if (privacy_url && tos_url) { %> - <p class="tospp"> - <%= format( - gettext('By clicking %s, you confirm that you accept this site\'s <a %s>Terms of Use</a> and <a %s>Privacy Policy</a>.'), - [ gettext('add'), - format(' href="%s" target="_new"', [tos_url]), - format(' href="%s" target="_new"', [privacy_url]) - ]) %> - </p> - <p> - <% } %> <button id="addNewEmail"><%= gettext('add') %></button> <a href="#" id="cancel" class="action"><%= gettext('cancel') %></a> - <% if (privacy_url && tos_url) { %> - </p> - <% } %> </div> </div> diff --git a/resources/static/dialog/views/authenticate.ejs b/resources/static/dialog/views/authenticate.ejs index 06b6307b5..57d0fad23 100644 --- a/resources/static/dialog/views/authenticate.ejs +++ b/resources/static/dialog/views/authenticate.ejs @@ -58,16 +58,15 @@ <button class="start addressInfo" tabindex="3"><%= gettext('next') %></button> <button class="returning" tabindex="3"><%= gettext('sign in') %></button> </p> - <% if (privacy_url && tos_url) { %> - <p class="tospp"> - <%= format( - gettext('By clicking %s, you confirm that you accept this site\'s <a %s>Terms of Use</a> and <a %s>Privacy Policy</a>.'), - [ gettext('next'), - format(' href="%s" target="_new"', [tos_url]), - format(' href="%s" target="_new"', [privacy_url]) - ]) %> + + <p class="tospp bidtospp"> + <%= format( + gettext('By proceeding, you agree to %s\'s <a %s>Terms</a> and <a %s>Privacy Policy</a>.'), + [ "Persona", + ' href="https://browserid.org/tos" target="_new"', + ' href="https://browserid.org/privacy" target="_new"', + ]) %> </p> - <% } %> </div> </div> diff --git a/resources/static/dialog/views/pick_email.ejs b/resources/static/dialog/views/pick_email.ejs index c189f5210..059072425 100644 --- a/resources/static/dialog/views/pick_email.ejs +++ b/resources/static/dialog/views/pick_email.ejs @@ -23,18 +23,8 @@ <div class="submit add cf"> - <p class="cf"> - <button id="signInButton"><%= gettext('sign in') %></button> - </p> - <% if (privacy_url && tos_url) { %> - <p class="tospp"> - <%= format( - gettext('By clicking %s, you confirm that you accept this site\'s <a %s>Terms of Use</a> and <a %s>Privacy Policy</a>.'), - [ gettext('sign in'), - format(' href="%s" target="_new"', [tos_url]), - format(' href="%s" target="_new"', [privacy_url]) - ]) %> + <p class="cf"> + <button id="signInButton"><%= gettext('sign in') %></button> </p> - <% } %> </div> </div> diff --git a/resources/static/dialog/views/required_email.ejs b/resources/static/dialog/views/required_email.ejs index 04d38aaa2..ee613fa96 100644 --- a/resources/static/dialog/views/required_email.ejs +++ b/resources/static/dialog/views/required_email.ejs @@ -50,17 +50,15 @@ </ul> <div class="submit cf"> - <% if (privacy_url && tos_url) { %> - <p class="tospp"> + <p class="tospp bidtospp"> <%= format( - gettext('By clicking %s, you confirm that you accept this site\'s <a %s>Terms of Use</a> and <a %s>Privacy Policy</a>.'), - [ gettext('sign in'), - format(' href="%s" target="_new"', [tos_url]), - format(' href="%s" target="_new"', [privacy_url]) + gettext('By proceeding, you agree to %s\'s <a %s>Terms</a> and <a %s>Privacy Policy</a>.'), + [ "BrowserID", + ' href="https://browserid.org/tos" target="_new"', + ' href="https://browserid.org/privacy" target="_new"', ]) %> </p> <p> - <% } %> <% if (signin) { %> <button id="sign_in" tabindex="3"><%= gettext("sign in") %></button> <% } else if (verify) { %> @@ -70,8 +68,6 @@ <% if (secondary_auth) { %> <a href="#" id="cancel" class="action" tabindex="4"><%= gettext("cancel") %></a> <% } %> - <% if (privacy_url && tos_url) { %> </p> - <% } %> </div> </div> diff --git a/resources/static/dialog/views/rp_info.ejs b/resources/static/dialog/views/rp_info.ejs index 5928a18d6..84c22866b 100644 --- a/resources/static/dialog/views/rp_info.ejs +++ b/resources/static/dialog/views/rp_info.ejs @@ -19,3 +19,12 @@ <% } %> <% } %> +<% if(privacyURL && tosURL) { %> + <p class="rptospp tospp"> + <%= format(gettext("By proceeding, you agree to %s\'s <a %s>Terms</a> and <a %s>Privacy Policy</a>."), + [ sitename, + ' href="' + tosURL + '" id="rp_tos" target="_blank"', + ' href="' + privacyURL + '" id="rp_pp" target="_blank"' + ]) %> + </p> +<% } %> diff --git a/resources/static/dialog/views/verify_primary_user.ejs b/resources/static/dialog/views/verify_primary_user.ejs index fb80a0c65..d38606759 100644 --- a/resources/static/dialog/views/verify_primary_user.ejs +++ b/resources/static/dialog/views/verify_primary_user.ejs @@ -24,21 +24,17 @@ </ul> <div class="submit cf"> - <% if (privacy_url && tos_url) { %> - <p class="tospp"> - <%= format( - gettext('By clicking %s, you confirm that you accept this site\'s <a %s>Terms of Use</a> and <a %s>Privacy Policy</a>.'), - [ gettext('verify'), - format(' href="%s" target="_new"', [tos_url]), - format(' href="%s" target="_new"', [privacy_url]) - ]) %> + <p class="tospp bidtospp"> + <%= format( + gettext('By proceeding, you agree to %s\'s <a %s>Terms</a> and <a %s>Privacy Policy</a>.'), + [ "BrowserID", + ' href="https://browserid.org/tos" target="_new"', + ' href="https://browserid.org/privacy" target="_new"', + ]) %> </p> <p> - <% } %> - <button id="verifyWithPrimary"><%= gettext("verify") %></button> - <% if (privacy_url && tos_url) { %> + <button id="verifyWithPrimary"><%= gettext("verify") %></button> </p> - <% } %> </div> </div> @@ -52,22 +48,18 @@ </p> <div class="submit cf"> - <% if (privacy_url && tos_url) { %> - <p class="tospp"> - <%= format( - gettext('By clicking %s, you confirm that you accept this site\'s <a %s>Terms of Use</a> and <a %s>Privacy Policy</a>.'), - [ gettext('verify'), - format(' href="%s" target="_new"', [tos_url]), - format(' href="%s" target="_new"', [privacy_url]) - ]) %> - </p> - <p> - <% } %> + <p class="tospp bidtospp"> + <%= format( + gettext('By proceeding, you agree to %s\'s <a %s>Terms</a> and <a %s>Privacy Policy</a>.'), + [ "BrowserID", + ' href="https://browserid.org/tos" target="_new"', + ' href="https://browserid.org/privacy" target="_new"', + ]) %> + </p> + <p> <button id="verifyWithPrimary"><%= gettext("verify") %></button> <a href="#" id="cancel" class="action"><%= gettext("cancel") %></a> - <% if (privacy_url && tos_url) { %> - </p> - <% } %> + </p> </div> </div> diff --git a/resources/static/lib/dom-jquery.js b/resources/static/lib/dom-jquery.js index 6438fec06..0faeb1ccc 100644 --- a/resources/static/lib/dom-jquery.js +++ b/resources/static/lib/dom-jquery.js @@ -313,7 +313,7 @@ BrowserID.DOM = ( function() { }, /** - * Show an element/elements + * Show an element * @method show * @param {selector || element} elementToShow */ @@ -322,15 +322,13 @@ BrowserID.DOM = ( function() { }, /** - * Hide an element/elements + * Hide an element * @method hide * @param {selector || element} elementToHide */ hide: function( elementToHide ) { return jQuery( elementToHide ).hide(); } - - }; function isValBased( target ) { diff --git a/resources/static/shared/modules/page_module.js b/resources/static/shared/modules/page_module.js index 54b570841..f0e0f6854 100644 --- a/resources/static/shared/modules/page_module.js +++ b/resources/static/shared/modules/page_module.js @@ -129,6 +129,7 @@ BrowserID.Modules.PageModule = (function() { self.hideWait(); self.hideError(); self.hideDelay(); + dom.hide(".tospp"); screens.form.show(template, data); dom.focus("input:visible:not(:disabled):eq(0)"); diff --git a/resources/static/shared/user.js b/resources/static/shared/user.js index ab493ae9f..d6c1ad1cb 100644 --- a/resources/static/shared/user.js +++ b/resources/static/shared/user.js @@ -264,6 +264,14 @@ BrowserID.User = (function() { return origin; }, + setOriginEmail: function(email) { + storage.site.set(origin, "email", email); + }, + + getOriginEmail: function() { + return storage.site.get(origin, "email"); + }, + /** * Get the hostname for the set origin * @method getHostname diff --git a/resources/static/test/cases/controllers/actions.js b/resources/static/test/cases/controllers/actions.js index 8d90d69f8..27c54f781 100644 --- a/resources/static/test/cases/controllers/actions.js +++ b/resources/static/test/cases/controllers/actions.js @@ -88,7 +88,6 @@ testActionStartsModule('doGenerateAssertion', { email: TEST_EMAIL }, "generate_assertion"); }); - asyncTest("doStageUser with successful creation - trigger user_staged", function() { createController({ ready: function() { @@ -109,5 +108,21 @@ asyncTest("doForgotPassword - call the set_password controller with reset_password true", function() { testActionStartsModule('doForgotPassword', { email: TEST_EMAIL }, "set_password"); }); + + asyncTest("doRPInfo - start the rp_info service", function() { + createController({ + ready: function() { + var error; + try { + controller.doRPInfo({ name: "browserid.org" }); + } catch(e) { + error = e; + } + + equal(error, "module not registered for rp_info", "correct service started"); + start(); + } + }); + }); }()); diff --git a/resources/static/test/cases/controllers/add_email.js b/resources/static/test/cases/controllers/add_email.js index 6d635e822..43f19e385 100644 --- a/resources/static/test/cases/controllers/add_email.js +++ b/resources/static/test/cases/controllers/add_email.js @@ -41,16 +41,6 @@ controller.start(options || {}); } - test("privacyURL and tosURL specified - show TOS/PP", function() { - equal($(".tospp").length, 0, "tospp has not yet been added to the DOM"); - createController({ - privacyURL: "http://testuser.com/priv.html", - tosURL: "http://testuser.com/tos.html", - }); - - equal($(".tospp").length, 1, "tospp has been added to the DOM"); - }); - test("addEmail with specified email address - fill in email", function() { createController({ email: "testuser@testuser.com" }); ok($("#newEmail").val(), "testuser@testuser.com", "email prepopulated"); diff --git a/resources/static/test/cases/controllers/dialog.js b/resources/static/test/cases/controllers/dialog.js index aedd54d97..b1f6530bb 100644 --- a/resources/static/test/cases/controllers/dialog.js +++ b/resources/static/test/cases/controllers/dialog.js @@ -152,6 +152,7 @@ catch(e) { // do nothing, an exception will be thrown because no modules are // registered for the any services. + console.log(e); } } }); diff --git a/resources/static/test/cases/controllers/rp_info.js b/resources/static/test/cases/controllers/rp_info.js index 0b89868ab..6e2200b09 100644 --- a/resources/static/test/cases/controllers/rp_info.js +++ b/resources/static/test/cases/controllers/rp_info.js @@ -13,8 +13,11 @@ register = bid.TestHelpers.register, WindowMock = bid.Mocks.WindowMock, RP_HOSTNAME = "hostname.org", - RP_NAME = "RP Name", - RP_HTTPS_LOGO = "https://en.gravatar.com/userimage/6966791/c4feac761b8544cce13e0406f36230aa.jpg"; + RP_NAME = "The Planet's Most Awesome Site", + RP_TOS_URL = "https://browserid.org/TOS.html", + RP_PP_URL = "https://browserid.org/priv.html", + RP_HTTPS_LOGO = "https://en.gravatar.com/userimage/6966791/c4feac761b8544cce13e0406f36230aa.jpg", + mediator = bid.Mediator; module("controllers/rp_info", { setup: testHelpers.setup, @@ -84,5 +87,17 @@ equal($("#rp_logo").attr("src"), RP_HTTPS_LOGO, "rp logo shown"); }); + test("privacyURL, tosURL, nextText specified - show TOS/PP info with nextText inserted", function() { + createController({ + name: RP_NAME, + privacyURL: RP_PP_URL, + tosURL: RP_TOS_URL + }); + + equal($("#rp_name").text(), RP_NAME, "RP's name is set"); + equal($("#rp_tos").attr("href"), RP_TOS_URL, "RP's TOS is set"); + equal($("#rp_pp").attr("href"), RP_PP_URL, "RP's Privacy Policy is set"); + }); + }()); diff --git a/resources/static/test/cases/controllers/verify_primary_user.js b/resources/static/test/cases/controllers/verify_primary_user.js index 5203792b7..58573fa4a 100644 --- a/resources/static/test/cases/controllers/verify_primary_user.js +++ b/resources/static/test/cases/controllers/verify_primary_user.js @@ -10,6 +10,7 @@ controller, el, testHelpers = bid.TestHelpers, + testElementExists = testHelpers.testElementExists, WindowMock = bid.Mocks.WindowMock, win, mediator = bid.Mediator; @@ -33,17 +34,17 @@ } }); - test("create with privacyURL and tosURL defined - show TOS/PP", function() { + test("create siteTOSPP set to true - show TOS/PP", function() { createController({ window: win, add: false, email: "unregistered@testuser.com", auth_url: "http://testuser.com/sign_in", - privacyURL: "http://testuser.com/priv.html", - tosURL: "http://testuser.com/tos.html" + siteTOSPP: true }); - equal($(".tospp").length, 1, "tospp has been added to the DOM"); + // XXX There should be a generalized test for this. + testElementExists(".tospp", "tospp has been added to the DOM"); }); test("create with requiredEmail, privacyURL and tosURL defined - show TOS/PP", function() { @@ -53,11 +54,10 @@ requiredEmail: "unregistered@testuser.com", email: "unregistered@testuser.com", auth_url: "http://testuser.com/sign_in", - privacyURL: "http://testuser.com/priv.html", - tosURL: "http://testuser.com/tos.html" + siteTOSPP: true }); - equal($(".tospp").length, 1, "tospp has been added to the DOM"); + testElementExists(".tospp", "tospp has been added to the DOM"); }); asyncTest("submit with `add: false` option opens a new tab with CREATE_EMAIL URL", function() { diff --git a/resources/static/test/cases/resources/state.js b/resources/static/test/cases/resources/state.js index 1addb9623..1694a093c 100644 --- a/resources/static/test/cases/resources/state.js +++ b/resources/static/test/cases/resources/state.js @@ -34,6 +34,14 @@ } } + function testActionStarted(actionName, requiredOptions) { + ok(actions.called[actionName], actionName + "called"); + for(var key in requiredOptions) { + equal(actions.info[actionName][key], requiredOptions[key], + actionName + " called with " + key + "=" + requiredOptions[key]); + } + } + function createMachine() { machine = bid.State.create(); actions = new ActionsMock(); @@ -127,6 +135,17 @@ equal(actions.info.doResetPassword.email, TEST_EMAIL, "correct email sent to doResetPassword"); }); + test("start - RPInfo always started", function() { + mediator.publish("start", { + tosURL: "https://browserid.org/TOS.html", + privacyURL: "https://browserid.org/priv.html" + }); + + ok(actions.info.doRPInfo.sitename, "doRPInfo called with sitename added and set"); + ok(actions.info.doRPInfo.tosURL, "doRPInfo called with tosURL set"); + ok(actions.info.doRPInfo.privacyURL, "doRPInfo called with privacyURL set"); + }); + test("user_staged - call doConfirmUser", function() { mediator.publish("user_staged", { email: TEST_EMAIL }); @@ -250,13 +269,13 @@ mediator.publish("authenticated", { email: TEST_EMAIL }); }); - test("forgot_password", function() { + test("forgot_password - call doForgotPassword with correct options", function() { + mediator.publish("start", { privacyURL: "priv.html", tosURL: "tos.html" }); mediator.publish("forgot_password", { email: TEST_EMAIL, requiredEmail: true }); - equal(actions.info.doForgotPassword.email, TEST_EMAIL, "correct email passed"); - equal(actions.info.doForgotPassword.requiredEmail, true, "correct requiredEmail passed"); + testActionStarted("doForgotPassword", { email: TEST_EMAIL, requiredEmail: true, siteTOSPP: true }); }); test("password_reset to user_confirmed - call doUserStaged then doEmailConfirmed", function() { @@ -375,12 +394,11 @@ ok(actions.called.doNotMe, "doNotMe has been called"); }); - test("authenticate", function() { - mediator.publish("authenticate", { - email: TEST_EMAIL - }); + test("authenticate - call doAuthenticate with the correct options", function() { + mediator.publish("start", { privacyURL: "priv.html", tosURL: "tos.html" }); + mediator.publish("authenticate", { email: TEST_EMAIL }); - equal(actions.info.doAuthenticate.email, TEST_EMAIL, "authenticate with testuser@testuser.com"); + testActionStarted("doAuthenticate", { email: TEST_EMAIL, siteTOSPP: true }); }); test("start with no special parameters - go straight to checking auth", function() { @@ -406,16 +424,23 @@ }); + test("add_email - call doAddEmail with correct options", function() { + mediator.publish("start", { privacyURL: "priv.html", tosURL: "tos.html" }); + mediator.publish("add_email"); + testActionStarted("doAddEmail", { siteTOSPP: true }); + }); + asyncTest("email_chosen with secondary email, user must authenticate - call doAuthenticateWithRequiredEmail", function() { var email = TEST_EMAIL; storage.addEmail(email, { type: "secondary" }); xhr.setContextInfo("auth_level", "assertion"); + mediator.publish("start", { privacyURL: "priv.html", tosURL: "tos.html" }); mediator.publish("email_chosen", { email: email, complete: function() { - equal(actions.called.doAuthenticateWithRequiredEmail, true, "doAuthenticateWithRequiredEmail called"); + testActionStarted("doAuthenticateWithRequiredEmail", { siteTOSPP: true }); start(); } }); @@ -472,8 +497,7 @@ equal(actions.called.doPickEmail, true, "doPickEmail callled"); equal(actions.info.doPickEmail.origin, "http://example.com", "hostname preserved"); - equal(actions.info.doPickEmail.privacyURL, "http://example.com/priv.html", "privacyURL preserved"); - equal(actions.info.doPickEmail.tosURL, "http://example.com/tos.html", "tosURL preserved"); + equal(actions.info.doPickEmail.siteTOSPP, true, "siteTOSPP preserved"); }); test("add_email - call doAddEmail", function() { diff --git a/resources/static/test/cases/shared/user.js b/resources/static/test/cases/shared/user.js index a252cd357..723ed803f 100644 --- a/resources/static/test/cases/shared/user.js +++ b/resources/static/test/cases/shared/user.js @@ -91,6 +91,22 @@ var jwcrypto = require("./lib/jwcrypto"); equal(lib.getReturnTo(), returnTo, "get/setReturnTo work as expected"); }); + test("setOriginEmail/getOriginEmail", function() { + storage.addEmail("testuser@testuser.com", { type: "primary" }); + storage.addEmail("testuser2@testuser.com", { type: "primary" }); + + lib.setOrigin("http://testdomain.org"); + + lib.setOriginEmail("testuser@testuser.com"); + equal(lib.getOriginEmail(), "testuser@testuser.com", "correct email"); + + lib.setOrigin("http://othertestdomain.org"); + lib.setOriginEmail("testuser2@testuser.com"); + + lib.setOrigin("http://testdomain.org"); + equal(lib.getOriginEmail(), "testuser@testuser.com", "correct email"); + }); + test("getStoredEmailKeypairs without key - return all identities", function() { var identities = lib.getStoredEmailKeypairs(); equal("object", typeof identities, "object returned"); diff --git a/resources/static/test/testHelpers/helpers.js b/resources/static/test/testHelpers/helpers.js index 0a7130ef5..8b65177da 100644 --- a/resources/static/test/testHelpers/helpers.js +++ b/resources/static/test/testHelpers/helpers.js @@ -220,17 +220,25 @@ BrowserID.TestHelpers = (function() { } }, - testHasClass: function(selector, className, msg) { - ok($(selector).hasClass(className), - selector + " has className " + className + " - " + msg); - }, - testUndefined: function(toTest, msg) { equal(typeof toTest, "undefined", msg || "object is undefined"); }, testNotUndefined: function(toTest, msg) { notEqual(typeof toTest, "undefined", msg || "object is defined"); + }, + + testHasClass: function(selector, className, msg) { + ok($(selector).hasClass(className), + msg || (selector + " has className " + className)); + }, + + testElementDoesNotExist: function(selector, msg) { + equal($(selector).length, 0, msg || ("element '" + selector + "' does not exist")); + }, + + testElementExists: function(selector, msg) { + ok($(selector).length, msg || ("element '" + selector + "' exists")); } }; -- GitLab