diff --git a/resources/static/common/js/user.js b/resources/static/common/js/user.js index dced5541cfb9db855f5f8d29bde705990f91628b..122196c475ed1419d0abbb1a111b147b223883a8 100644 --- a/resources/static/common/js/user.js +++ b/resources/static/common/js/user.js @@ -17,7 +17,9 @@ BrowserID.User = (function() { addressCache = {}, primaryAuthCache = {}, complete = bid.Helpers.complete, - registrationComplete = false; + registrationComplete = false, + POLL_TIMEOUT = 3000, + pollTimeout = POLL_TIMEOUT; function prepareDeps() { if (!jwcrypto) { @@ -193,7 +195,7 @@ BrowserID.User = (function() { else complete(onSuccess, status); } else if (status === 'pending') { - pollTimeout = setTimeout(poll, 3000); + pollTimeout = setTimeout(poll, pollTimeout); } else if (onFailure) { onFailure(status); @@ -283,12 +285,17 @@ BrowserID.User = (function() { provisioning = config.provisioning; } + if (config.pollTimeout) { + pollTimeout = config.pollTimeout; + } + }, reset: function() { provisioning = BrowserID.Provisioning; User.resetCaches(); registrationComplete = false; + pollTimeout = POLL_TIMEOUT; }, resetCaches: function() { diff --git a/resources/static/test/cases/common/js/network.js b/resources/static/test/cases/common/js/network.js index 7000cf007a253c8277d90095f023326bef838fa4..fc153cacbf2c62429521c6f4c23e8fb99762756a 100644 --- a/resources/static/test/cases/common/js/network.js +++ b/resources/static/test/cases/common/js/network.js @@ -55,10 +55,7 @@ transport.useResult("complete"); network[funcName]("registered@testuser.com", function(status) { equal(status, "complete"); - network.checkAuth(function(auth_level) { - equal(auth_level, "password", "user can only be authenticated to password level after verification is complete"); - start(); - }); + start(); }, testHelpers.unexpectedFailure); }); } @@ -257,53 +254,11 @@ failureCheck(network.createUser, "validuser", "password", "origin"); }); - asyncTest("checkUserRegistration returns pending - pending status, user is not logged in", function() { - transport.useResult("pending"); - - // To properly check the user registration status, we first have to - // simulate the first checkAuth or else network has no context from which - // to work. - network.checkAuth(function(auth_status) { - equal(!!auth_status, false, "user not yet authenticated"); - network.checkUserRegistration("registered@testuser.com", function(status) { - equal(status, "pending"); - network.checkAuth(function(auth_status) { - equal(!!auth_status, false, "user not yet authenticated"); - start(); - }, testHelpers.unexpectedFailure); - }, testHelpers.unexpectedFailure); - }, testHelpers.unexpectedFailure); - }); + asyncTest("checkUserRegistration returns pending - pending status, user is not logged in", testVerificationPending.curry("checkUserRegistration")); - asyncTest("checkUserRegistration returns mustAuth - mustAuth status, user is not logged in", function() { - transport.useResult("mustAuth"); + asyncTest("checkUserRegistration returns mustAuth - mustAuth status, user is not logged in", testVerificationMustAuth.curry("checkUserRegistration")); - network.checkAuth(function(auth_status) { - equal(!!auth_status, false, "user not yet authenticated"); - network.checkUserRegistration("registered@testuser.com", function(status) { - equal(status, "mustAuth"); - network.checkAuth(function(auth_status) { - equal(!!auth_status, false, "user not yet authenticated"); - start(); - }, testHelpers.unexpectedFailure); - }, testHelpers.unexpectedFailure); - }, testHelpers.unexpectedFailure); - }); - - asyncTest("checkUserRegistration returns complete - complete status, user is logged in", function() { - transport.useResult("complete"); - - network.checkAuth(function(auth_status) { - equal(!!auth_status, false, "user not yet authenticated"); - network.checkUserRegistration("registered@testuser.com", function(status) { - equal(status, "complete"); - network.checkAuth(function(auth_status) { - equal(auth_status, "password", "user authenticated after checkUserRegistration returns complete"); - start(); - }, testHelpers.unexpectedFailure); - }, testHelpers.unexpectedFailure); - }, testHelpers.unexpectedFailure); - }); + asyncTest("checkUserRegistration returns complete - complete status, user is logged in", testVerificationComplete.curry("checkUserRegistration")); asyncTest("checkUserRegistration with XHR failure", function() { failureCheck(network.checkUserRegistration, "registered@testuser.com"); diff --git a/resources/static/test/cases/common/js/user.js b/resources/static/test/cases/common/js/user.js index f39ed418c20b87b8fd73f881e1f965cfcfb44aeb..d4e63d85f1de282bd88162ff84fe9d710ed663fc 100644 --- a/resources/static/test/cases/common/js/user.js +++ b/resources/static/test/cases/common/js/user.js @@ -320,13 +320,14 @@ ); }); - asyncTest("waitForUserValidation with `complete` response", function() { + asyncTest("waitForUserValidation with complete from backend, user not authed - `mustAuth` response", function() { storage.setReturnTo(testOrigin); + xhr.setContextInfo("auth_level", false); xhr.useResult("complete"); lib.waitForUserValidation("registered@testuser.com", function(status) { - equal(status, "complete", "complete response expected"); + equal(status, "mustAuth", "mustAuth response expected"); ok(!storage.getReturnTo(), "staged on behalf of is cleared when validation completes"); start(); @@ -844,8 +845,22 @@ }); - asyncTest("waitForEmailValidation `complete` response", function() { + asyncTest("waitForEmailValidation with `complete` backend response, user authenticated to assertion level - expect 'mustAuth'", function() { + storage.setReturnTo(testOrigin); + xhr.setContextInfo("auth_level", "assertion"); + + xhr.useResult("complete"); + lib.waitForEmailValidation("registered@testuser.com", function(status) { + ok(!storage.getReturnTo(), "staged on behalf of is cleared when validation completes"); + equal(status, "mustAuth", "mustAuth response expected"); + start(); + }, testHelpers.unexpectedXHRFailure); + }); + + + asyncTest("waitForEmailValidation with `complete` backend response, user authenticated to password level - expect 'complete'", function() { storage.setReturnTo(testOrigin); + xhr.setContextInfo("auth_level", "password"); xhr.useResult("complete"); lib.waitForEmailValidation("registered@testuser.com", function(status) { diff --git a/resources/static/test/cases/dialog/js/modules/check_registration.js b/resources/static/test/cases/dialog/js/modules/check_registration.js index 29c84236e7e2f0c9cf52801cfd678c04882145dc..12a7622998b22bcac9ae69f44a886ab51cb6d887 100644 --- a/resources/static/test/cases/dialog/js/modules/check_registration.js +++ b/resources/static/test/cases/dialog/js/modules/check_registration.js @@ -8,15 +8,17 @@ var controller, bid = BrowserID, + user = bid.User, xhr = bid.Mocks.xhr, network = bid.Network, testHelpers = bid.TestHelpers, register = testHelpers.register; - function createController(verifier, message, required) { + function createController(verifier, message, required, password) { controller = bid.Modules.CheckRegistration.create(); controller.start({ email: "registered@testuser.com", + password: password, verifier: verifier, verificationMessage: message, required: required, @@ -40,8 +42,8 @@ } }); - function testVerifiedUserEvent(event_name, message) { - createController("waitForUserValidation", event_name); + function testVerifiedUserEvent(event_name, message, password) { + createController("waitForUserValidation", event_name, false, password); register(event_name, function() { ok(true, message); start(); @@ -49,28 +51,60 @@ controller.startCheck(); } - asyncTest("user validation with mustAuth result - callback with email, type and known set to true", function() { - xhr.useResult("mustAuth"); - createController("waitForUserValidation"); - register("authenticate", function(msg, info) { + function testMustAuthUserEvent(event_name, message) { + createController("waitForUserValidation", event_name); + register(event_name, function(msg, info) { // we want the email, type and known all sent back to the caller so that // this information does not need to be queried again. + ok(true, message); equal(info.email, "registered@testuser.com", "correct email"); - ok(info.type, "type sent with info"); - ok(info.known, "email is known"); start(); }); controller.startCheck(); + } + + asyncTest("user validation with mustAuth result - callback with email, type and known set to true", function() { + xhr.useResult("mustAuth"); + testMustAuthUserEvent("authenticate_specified_email", "user must authenticate"); + }); + + asyncTest("user validation with pending->complete with auth_level = assertion, no authentication info given - authenticate_specified_email triggered", function() { + user.init({ pollTimeout: 100 }); + xhr.useResult("pending"); + xhr.setContextInfo("auth_level", "assertion"); + testMustAuthUserEvent("authenticate_specified_email", "user must authenticate"); + + // use setTimeout to simulate a delay in the user opening the email. + setTimeout(function() { + xhr.useResult("complete"); + }, 50); }); - asyncTest("user validation with pending->complete result ~3 seconds", function() { + + asyncTest("user validation with pending->complete with auth_level = assertion, authentication info given - user_verified triggered", function() { + user.init({ pollTimeout: 100 }); xhr.useResult("pending"); + xhr.setContextInfo("auth_level", "password"); + + testVerifiedUserEvent("user_verified", "user verified after authenticating", "password"); + + // use setTimeout to simulate a delay in the user opening the email. + setTimeout(function() { + xhr.useResult("complete"); + }, 50); + }); + + asyncTest("user validation with pending->complete with auth_level = password - user_verified triggered", function() { + user.init({ pollTimeout: 100 }); + xhr.useResult("pending"); + xhr.setContextInfo("auth_level", "password"); testVerifiedUserEvent("user_verified", "User verified"); + // use setTimeout to simulate a delay in the user opening the email. setTimeout(function() { xhr.useResult("complete"); - }, 500); + }, 50); }); asyncTest("user validation with XHR error - show error message", function() {