Skip to content

Commit

Permalink
Always clear sessions when user password is updated (#3821)
Browse files Browse the repository at this point in the history
* Adds repro to  issue #3289

* Always clear sessions when password is updated
  • Loading branch information
flovilmart authored and Arthur Cinader committed May 16, 2017
1 parent 9dbb89a commit 17a2d26
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
5 changes: 1 addition & 4 deletions spec/ParseServerRESTController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ describe('ParseServerRESTController', () => {
}).then(sessions => {
expect(sessions.length).toBe(0);
done();
}, (err) => {
jfail(err);
done();
});
}, done.fail);
});

it('ensures a session token is created when passing installationId != cloud', (done) => {
Expand Down
17 changes: 17 additions & 0 deletions spec/ParseUser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2935,4 +2935,21 @@ describe('Parse.User testing', () => {
done();
});
});

it('should revoke sessions when setting paswword with masterKey (#3289)', (done) => {
let user;
Parse.User.signUp('username', 'password')
.then((newUser) => {
user = newUser;
user.set('password', 'newPassword');
return user.save(null, {useMasterKey: true});
}).then(() => {
const query = new Parse.Query('_Session');
query.equalTo('user', user);
return query.find({useMasterKey: true});
}).then((results) => {
expect(results.length).toBe(0);
done();
}, done.fail);
});
});
7 changes: 5 additions & 2 deletions src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,12 @@ RestWrite.prototype.transformUser = function() {
return Promise.resolve();
}

if (this.query && !this.auth.isMaster) {
if (this.query) {
this.storage['clearSessions'] = true;
this.storage['generateNewSession'] = true;
// Generate a new session only if the user requested
if (!this.auth.isMaster) {
this.storage['generateNewSession'] = true;
}
}

return this._validatePasswordPolicy().then(() => {
Expand Down

0 comments on commit 17a2d26

Please sign in to comment.