Skip to content

Commit

Permalink
Add test parameter so we only expire tokens for our user, not everyone.
Browse files Browse the repository at this point in the history
  • Loading branch information
n1mmy committed Oct 8, 2013
1 parent bc8406d commit f9504f2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions packages/accounts-base/accounts_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,22 +197,26 @@ var removeLoginToken = function (userId, loginToken) {
var expireTokenInterval;

// Deletes expired tokens from the database and closes all open connections
// associated with these tokens. Exported for tests. oldestValidDate is used
// only by tests to simulate expiring tokens without waiting for them to
// actually expire.
var expireTokens = Accounts._expireTokens = function (oldestValidDate) {
// associated with these tokens.
//
// Exported for tests. Also, the arguments are only used by
// tests. oldestValidDate is simulate expiring tokens without waiting
// for them to actually expire. userId is used by tests to only expire
// tokens for the test user.
var expireTokens = Accounts._expireTokens = function (oldestValidDate, userId) {
var tokenLifetimeMs = getTokenLifetimeMs();
oldestValidDate = oldestValidDate ||
(new Date(new Date() - tokenLifetimeMs));
var userFilter = userId ? {_id: userId} : {};

// Backwards compatible with older versions of meteor that stored login token
// timestamps as numbers.
Meteor.users.update({
Meteor.users.update(_.extend(userFilter, {
$or: [
{ "services.resume.loginTokens.when": { $lt: oldestValidDate } },
{ "services.resume.loginTokens.when": { $lt: +oldestValidDate } }
]
}, {
}), {
$pull: {
"services.resume.loginTokens": {
$or: [
Expand Down
2 changes: 1 addition & 1 deletion packages/accounts-password/password_tests_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Meteor.methods({
},

expireTokens: function () {
Accounts._expireTokens(new Date());
Accounts._expireTokens(new Date(), this.userId);
},
removeUser: function (username) {
Meteor.users.remove({ "username": username });
Expand Down

0 comments on commit f9504f2

Please sign in to comment.