mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Tests for reset password flow
This commit is contained in:
56
packages/accounts-passwords/email_tests.js
Normal file
56
packages/accounts-passwords/email_tests.js
Normal file
@@ -0,0 +1,56 @@
|
||||
(function () {
|
||||
var email = Meteor.uuid() + "-intercept@example.com";
|
||||
var resetPasswordToken;
|
||||
|
||||
testAsyncMulti("accounts emails - reset password flow", [
|
||||
function (test, expect) {
|
||||
Meteor.createUser({email: email, password: 'foobar'},
|
||||
expect(function (error) {
|
||||
test.equal(error, undefined);
|
||||
}));
|
||||
},
|
||||
function (test, expect) {
|
||||
Meteor.forgotPassword({email: email}, expect(function (error) {
|
||||
test.equal(error, undefined);
|
||||
}));
|
||||
},
|
||||
function (test, expect) {
|
||||
Meteor.call("getInterceptedEmails", email, expect(function (error, result) {
|
||||
test.notEqual(result, undefined);
|
||||
test.equal(result.length, 1);
|
||||
var content = result[0];
|
||||
|
||||
var match = content.match(
|
||||
new RegExp(window.location.protocol + "//" +
|
||||
window.location.host + "/#\\?reset-password/(\\S*)"));
|
||||
test.isTrue(match);
|
||||
resetPasswordToken = match[1];
|
||||
console.log(resetPasswordToken);
|
||||
}));
|
||||
},
|
||||
function (test, expect) {
|
||||
Meteor.resetPassword(resetPasswordToken, "newPassword", expect(function(error) {
|
||||
test.isFalse(error);
|
||||
}));
|
||||
},
|
||||
function (test, expect) {
|
||||
Meteor.logout(expect(function (error) {
|
||||
test.equal(error, undefined);
|
||||
test.equal(Meteor.user(), null);
|
||||
}));
|
||||
},
|
||||
function (test, expect) {
|
||||
Meteor.loginWithPassword(
|
||||
{email: email}, "newPassword",
|
||||
expect(function (error) {
|
||||
test.isFalse(error);
|
||||
}));
|
||||
},
|
||||
function (test, expect) {
|
||||
Meteor.logout(expect(function (error) {
|
||||
test.equal(error, undefined);
|
||||
test.equal(Meteor.user(), null);
|
||||
}));
|
||||
}
|
||||
]);
|
||||
}) ();
|
||||
26
packages/accounts-passwords/email_tests_setup.js
Normal file
26
packages/accounts-passwords/email_tests_setup.js
Normal file
@@ -0,0 +1,26 @@
|
||||
(function () {
|
||||
//
|
||||
// a mechanism to intercept emails sent to addressing including
|
||||
// the string "intercept", storing them in an array that can then
|
||||
// be retrieved using the getInterceptedEmails method
|
||||
//
|
||||
var oldMeteorMailSend = Meteor.mail.send;
|
||||
var interceptedEmails = {}; // (email address) -> (array of contents)
|
||||
|
||||
Meteor.mail.send = function (email, content) {
|
||||
if (email.indexOf('intercept') === -1) {
|
||||
oldMeteorMailSend(email, content);
|
||||
} else {
|
||||
if (!interceptedEmails[email])
|
||||
interceptedEmails[email] = [];
|
||||
|
||||
interceptedEmails[email].push(content);
|
||||
}
|
||||
};
|
||||
|
||||
Meteor.methods({
|
||||
getInterceptedEmails: function (email) {
|
||||
return interceptedEmails[email];
|
||||
}
|
||||
});
|
||||
}) ();
|
||||
@@ -15,4 +15,6 @@ Package.on_test(function(api) {
|
||||
api.use(['accounts-passwords', 'tinytest', 'test-helpers']);
|
||||
api.add_files('passwords_tests_setup.js', 'server');
|
||||
api.add_files('passwords_tests.js', 'client');
|
||||
api.add_files('email_tests_setup.js', 'server');
|
||||
api.add_files('email_tests.js', 'client');
|
||||
});
|
||||
|
||||
@@ -131,7 +131,7 @@
|
||||
// @param options {Object}
|
||||
// - email: (email)
|
||||
// @param callback (optional) {Function(error|undefined)}
|
||||
Meteor.forgotPassword = function(options) {
|
||||
Meteor.forgotPassword = function(options, callback) {
|
||||
if (!options.email)
|
||||
throw new Error("Must pass options.email");
|
||||
options.baseUrl = window.location.protocol + "//"
|
||||
|
||||
@@ -1 +1,8 @@
|
||||
Meteor.accounts.passwords = {};
|
||||
Meteor.accounts.passwords = {};
|
||||
|
||||
// internal email validation tokens collection. Never published.
|
||||
Meteor.accounts._emailValidationTokens = new Meteor.Collection(
|
||||
"accounts._emailValidationTokens",
|
||||
null /*manager*/,
|
||||
null /*driver*/,
|
||||
true /*preventAutopublish*/);
|
||||
Reference in New Issue
Block a user