mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Add test for deferred registration with API token URL
This commit is contained in:
@@ -21,6 +21,30 @@ var ddpConnect = function (url) {
|
||||
return DDP.connect(url);
|
||||
};
|
||||
|
||||
var registrationUrlRegexp =
|
||||
/https:\/\/www\.meteor\.com\/setPassword\?([a-zA-Z0-9\+\/]+)/;
|
||||
|
||||
// Given a registration token created by doing a deferred registration
|
||||
// with `email`, makes a DDP connection to the accounts server and
|
||||
// finishes the registration process.
|
||||
var registerWithToken = function (token, username, password, email) {
|
||||
// XXX It might make more sense to hard-code the DDP url to
|
||||
// https://www.meteor.com, since that's who the sandboxes are talking
|
||||
// to.
|
||||
var accountsConn = ddpConnect(config.getAuthDDPUrl());
|
||||
var registrationTokenInfo = accountsConn.call('registrationTokenInfo',
|
||||
token);
|
||||
var registrationCode = registrationTokenInfo.code;
|
||||
accountsConn.call('register', {
|
||||
username: username,
|
||||
password: password,
|
||||
emails: [email],
|
||||
token: token,
|
||||
code: registrationCode
|
||||
});
|
||||
accountsConn.close();
|
||||
};
|
||||
|
||||
// Polls a guerrillamail.com inbox every 3 seconds looking for an email
|
||||
// that matches the given subject and body regexes. This could fail if
|
||||
// there is someone else polling this same inbox, so use a random email
|
||||
@@ -96,7 +120,7 @@ var waitForEmail = selftest.markStack(function (inbox, subjectRegExp,
|
||||
return match;
|
||||
});
|
||||
|
||||
selftest.define('deferred registration', ['net'], function () {
|
||||
selftest.define('deferred registration - email registration token', ['net', 'slow'], function () {
|
||||
var s = new Sandbox;
|
||||
s.createApp('deployapp', 'empty');
|
||||
s.cd('deployapp');
|
||||
@@ -112,7 +136,10 @@ selftest.define('deferred registration', ['net'], function () {
|
||||
run.waitSecs(90);
|
||||
// Check that we got a prompt to set a password on meteor.com.
|
||||
run.matchErr('set a password');
|
||||
run.matchErr('https://www.meteor.com');
|
||||
var urlMatch = run.matchErr(registrationUrlRegexp);
|
||||
if (! urlMatch || ! urlMatch[1]) {
|
||||
throw new Error("Missing registration URL");
|
||||
}
|
||||
run.expectExit(0);
|
||||
|
||||
// Check that we got a registration email in our inbox.
|
||||
@@ -121,28 +148,13 @@ selftest.define('deferred registration', ['net'], function () {
|
||||
|
||||
// Fish out the registration token and use to it to complete
|
||||
// registration.
|
||||
var token = /\/setPassword\?([a-zA-Z0-9\+\/]+)/.
|
||||
exec(registrationEmail.bodyPage);
|
||||
var token = registrationUrlRegexp.exec(registrationEmail.bodyPage);
|
||||
if (! token || ! token[1]) {
|
||||
throw new Error("No registration token in email");
|
||||
}
|
||||
token = token[1];
|
||||
|
||||
// XXX It might make more sense to hard-code the DDP url to
|
||||
// https://www.meteor.com, since that's who the sandboxes are talking
|
||||
// to.
|
||||
var accountsConn = ddpConnect(config.getAuthDDPUrl());
|
||||
var registrationTokenInfo = accountsConn.call('registrationTokenInfo',
|
||||
token);
|
||||
var registrationCode = registrationTokenInfo.code;
|
||||
accountsConn.call('register', {
|
||||
username: username,
|
||||
password: 'testtest',
|
||||
emails: [email],
|
||||
token: token,
|
||||
code: registrationCode
|
||||
});
|
||||
accountsConn.close();
|
||||
registerWithToken(token, username, 'testtest', email);
|
||||
|
||||
// Success! We should be able to log out and log back in with our new
|
||||
// password.
|
||||
@@ -153,9 +165,43 @@ selftest.define('deferred registration', ['net'], function () {
|
||||
// authorization to delete our app.
|
||||
testUtils.cleanUpApp(s, appName);
|
||||
|
||||
// XXX Test the api registration URLs
|
||||
// XXX Test that registration can only be done once (after using email
|
||||
// url, api url fails and vice versa, and after using each of them
|
||||
// using it again fails)
|
||||
// XXX Test that registration URLs get printed when they should
|
||||
// XXX Test registration while the tool is waiting on a DDP method to
|
||||
// return (e.g. deploy and login with an existing username that
|
||||
// doesn't have a password set yet)
|
||||
});
|
||||
|
||||
selftest.define(
|
||||
'deferred registration - api registration token',
|
||||
['net', 'slow'],
|
||||
function () {
|
||||
var s = new Sandbox;
|
||||
s.createApp('deployapp', 'empty');
|
||||
s.cd('deployapp');
|
||||
|
||||
// Deploy an app with a new email address.
|
||||
var email = testUtils.randomUserEmail();
|
||||
var username = testUtils.randomString(10);
|
||||
var appName = testUtils.randomAppName();
|
||||
var run = s.run('deploy', appName);
|
||||
run.waitSecs(testUtils.accountsCommandTimeoutSecs);
|
||||
run.matchErr('Email:');
|
||||
run.write(email + '\n');
|
||||
run.waitSecs(90);
|
||||
// Check that we got a prompt to set a password on meteor.com.
|
||||
run.matchErr('set a password');
|
||||
var urlMatch = run.matchErr(registrationUrlRegexp);
|
||||
if (! urlMatch || ! urlMatch.length || ! urlMatch[1]) {
|
||||
throw new Error("Missing registration token");
|
||||
}
|
||||
var token = urlMatch[1];
|
||||
registerWithToken(token, username, 'testtest', email);
|
||||
|
||||
testUtils.logout(s);
|
||||
testUtils.login(s, username, 'testtest');
|
||||
testUtils.cleanUpApp(s, appName);
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user