Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
fix(test): Fix test-latest functional tests.
Browse files Browse the repository at this point in the history
Several problems:
* When running against remote servers, Selenium moves very quickly.
* The email index being searched for was not being passed to restmail, so it would return as long as one email existed.
* OAuth tests depended on each other
* Signing out of 123done was not done correctly and state would hang around.
* Clearing content server state was being done before the content server was loaded, which ended up in a 500 error.

What we do now:
* Simplify the OAuth sign in tests so there is no cross-test dependencies.
* In the OAuth sign in tests, use the FxaClient to pre-generate users. We are testing sign in, not sign up.
* Ensure the content server page is loaded before clearing its state.
* Ensure the user is logged out of 123done when clearing its state - do so by calling XHR requests directly.
* Ensure the index of the email we are waiting for makes it to restmail.

fixes #1690
  • Loading branch information
Shane Tomlinson committed Oct 10, 2014
1 parent 8ba4336 commit 37696cb
Show file tree
Hide file tree
Showing 6 changed files with 276 additions and 238 deletions.
66 changes: 63 additions & 3 deletions tests/functional/lib/helpers.js
Expand Up @@ -13,8 +13,33 @@ define([
var config = intern.config;
var CONTENT_SERVER = config.fxaContentRoot;
var EMAIL_SERVER_ROOT = config.fxaEmailRoot;
var OAUTH_APP = config.fxaOauthApp;

function clearBrowserState(context) {
function clearBrowserState(context, options) {
options = options || {};

if (! ('contentServer' in options)) {
options.contentServer = true;
}

if (! ('123done' in options)) {
options['123done'] = false;
}

return context.get('remote')
.then(function () {
if (options.contentServer) {
return clearContentServerState(context);
}
})
.then(function () {
if (options['123done']) {
return clear123DoneState(context);
}
});
}

function clearContentServerState(context) {
// clear localStorage to avoid polluting other tests.
return context.get('remote')
// always go to the content server so the browser state is cleared
Expand All @@ -24,7 +49,9 @@ define([
// only load up the content server if we aren't
// already at the content server.
if (url.indexOf(CONTENT_SERVER) === -1) {
return context.get('remote').get(require.toUrl(CONTENT_SERVER));
return context.get('remote').get(require.toUrl(CONTENT_SERVER + 'clear'))
.setFindTimeout(config.pageLoadTimeout)
.findById('fxa-clear-storage-header');
}
})
.execute(function () {
Expand All @@ -41,6 +68,38 @@ define([
}, []);
}

function clear123DoneState(context) {
/**
* Clearing state for 123done is a bit of a hack.
* When the user clicks "Sign out", the buttons to signup/signin
* are shown without waiting for the XHR request to complete.
* If Selenium moves too quickly and loads another page before the XHR
* request completes, the request is aborted and the user never signs out,
* causing state to hang around and problems later on.
*
* To get around this, manually sign the user out by calling the
* logout endpoint on the server, then notify Selenium when that request
* completes by adding an element to the DOM. Selenium will look for
* the added element.
*/
return context.get('remote')
.setFindTimeout(config.pageLoadTimeout)
.get(require.toUrl(OAUTH_APP))

.findByCssSelector('#footer-main')
.end()

.execute(function () {
/* global $ */
$.post('/api/logout/')
.always(function () {
$('body').append('<div id="loggedout">Logged out</div>');
});
})
.findByCssSelector('#loggedout')
.end();
}

function clearSessionStorage(context) {
// clear localStorage to avoid polluting other tests.
return context.get('remote')
Expand Down Expand Up @@ -85,7 +144,8 @@ define([
}

function getVerificationHeaders(user, index) {
return restmail(EMAIL_SERVER_ROOT + '/mail/' + user)
// restmail takes an index that is 1 based instead of 0 based.
return restmail(EMAIL_SERVER_ROOT + '/mail/' + user, index + 1)
.then(function (emails) {
return emails[index].headers;
});
Expand Down
24 changes: 15 additions & 9 deletions tests/functional/oauth_preverified_sign_up.js
Expand Up @@ -16,7 +16,6 @@ define([
'use strict';

var config = intern.config;
var CONTENT_SERVER = config.fxaContentRoot;
var OAUTH_APP = config.fxaOauthApp;
var TOO_YOUNG_YEAR = new Date().getFullYear() - 13;

Expand All @@ -33,17 +32,13 @@ define([
},

beforeEach: function () {
var self = this;
// clear localStorage to avoid polluting other tests.
// Without the clear, /signup tests fail because of the info stored
// in prefillEmail
return self.get('remote')
// always go to the content server so the browser state is cleared
.get(require.toUrl(CONTENT_SERVER))
.setFindTimeout(intern.config.pageLoadTimeout)
.then(function () {
return FunctionalHelpers.clearBrowserState(self);
});
return FunctionalHelpers.clearBrowserState(this, {
contentServer: true,
'123done': true
});
},

'preverified sign up': function () {
Expand Down Expand Up @@ -78,7 +73,18 @@ define([
.click()
.end()

// user is redirected to 123done, wait for the footer first,
// and then for the loggedin user to be visible. If we go
// straight for the loggedin user, visibleByQSA blows up
// because 123done isn't loaded yet and it complains about
// the unload event of the content server.
.findByCssSelector('#footer-main')
.end()

// user is pre-verified and sent directly to the RP.
.then(FunctionalHelpers.visibleByQSA('#loggedin'))
.end()

.findByCssSelector('#loggedin')
.getVisibleText()
.then(function (text) {
Expand Down
15 changes: 8 additions & 7 deletions tests/functional/oauth_reset_password.js
Expand Up @@ -50,15 +50,13 @@ define([
})
.then(function () {
// clear localStorage to avoid polluting other tests.
return FunctionalHelpers.clearBrowserState(self);
return FunctionalHelpers.clearBrowserState(self, {
contentServer: true,
'123done': true
});
});
},

teardown: function () {
// clear localStorage to avoid polluting other tests.
return FunctionalHelpers.clearBrowserState(this);
},

'oauth reset password': function () {
var self = this;

Expand Down Expand Up @@ -195,7 +193,10 @@ define([
.then(function () {
// clear all browser state, simulate opening in a new
// browser
return FunctionalHelpers.clearBrowserState(self);
return FunctionalHelpers.clearBrowserState(self, {
contentServer: true,
'123done': true
});
})
.then(function () {
return FunctionalHelpers.getVerificationLink(user, 1);
Expand Down

0 comments on commit 37696cb

Please sign in to comment.