Merge branch 'pr/4971' into devel

Fixes #4971. Fixes #4970.
This commit is contained in:
David Glasser
2015-08-25 14:46:59 -07:00
3 changed files with 81 additions and 2 deletions

View File

@@ -213,7 +213,9 @@ Ap.callLoginMethod = function (options) {
// will occur before the callback from the resume login call.)
var onResultReceived = function (err, result) {
if (err || !result || !result.token) {
self.connection.onReconnect = null;
// Leave onReconnect alone if there was an error, so that if the user was
// already logged in they will still get logged in on reconnect.
// See issue #4970.
} else {
self.connection.onReconnect = function () {
reconnected = true;

View File

@@ -0,0 +1,75 @@
if (Meteor.isServer) {
Meteor.methods({
getConnectionUserId: function() {
return this.userId;
}
});
}
if (Meteor.isClient) {
Tinytest.addAsync('accounts - reconnect auto-login', function(test, done) {
var username1 = 'testuser1-' + Random.id();
var username2 = 'testuser2-' + Random.id();
var password1 = 'password1-' + Random.id();
var password2 = 'password2-' + Random.id();
var timeoutHandle;
var onLoginStopper;
loginAsUser1();
function loginAsUser1() {
Accounts.createUser({
username: username1,
password: password1
}, onUser1LoggedIn);
}
function onUser1LoggedIn(err) {
test.isUndefined(err, 'Unexpected error logging in as user1');
Accounts.createUser({
username: username2,
password: password2
}, onUser2LoggedIn);
}
function onUser2LoggedIn(err) {
test.isUndefined(err, 'Unexpected error logging in as user2');
onLoginStopper = Accounts.onLogin(onUser2LoggedInAfterReconnect);
Meteor.disconnect();
Meteor.reconnect();
}
function onUser2LoggedInAfterReconnect() {
onLoginStopper.stop();
Meteor.loginWithPassword('non-existent-user', 'or-wrong-password',
onFailedLogin);
}
function onFailedLogin(err) {
test.instanceOf(err, Meteor.Error, 'No Meteor.Error on login failure');
onLoginStopper = Accounts.onLogin(onUser2LoggedInAfterReconnectAfterFailedLogin);
Meteor.disconnect();
Meteor.reconnect();
timeoutHandle = Meteor.setTimeout(failTest, 1000);
}
function failTest() {
onLoginStopper.stop();
test.fail('Issue #4970 has occured.');
Meteor.call('getConnectionUserId', checkFinalState);
}
function onUser2LoggedInAfterReconnectAfterFailedLogin() {
onLoginStopper.stop();
Meteor.clearTimeout(timeoutHandle);
Meteor.call('getConnectionUserId', checkFinalState);
}
function checkFinalState(err, connectionUserId) {
test.isUndefined(err, 'Unexpected error calling getConnectionUserId');
test.equal(connectionUserId, Meteor.userId(),
'userId is different on client and server');
done();
}
});
}

View File

@@ -69,9 +69,11 @@ Package.onTest(function (api) {
'test-helpers',
'oauth-encryption',
'underscore',
'ddp'
'ddp',
'accounts-password'
]);
api.addFiles('accounts_tests.js', 'server');
api.addFiles("accounts_url_tests.js", "client");
api.addFiles("accounts_reconnect_tests.js");
});