Skip to content

Commit

Permalink
Do not create sessionToken when requests come from cloudCode #1495
Browse files Browse the repository at this point in the history
  • Loading branch information
flovilmart committed Sep 3, 2016
1 parent 759fa1a commit e3098fc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
14 changes: 13 additions & 1 deletion spec/ParseServerRESTController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ describe('ParseServerRESTController', () => {
userId = user.id;
let sessionToken = user.getSessionToken();
return Parse.User.logOut().then(() => {
console.log('Sending request');
return RESTController.request("GET", "/classes/_User", undefined, {useMasterKey: true});
});
}).then((res) => {
Expand All @@ -104,4 +103,17 @@ describe('ParseServerRESTController', () => {
done();
});
});

it('ensures no session token is created on creating users', (done) => {
RESTController.request("POST", "/classes/_User", {username: "hello", password: "world"}).then(() => {
let query = new Parse.Query('_Session');
return query.find({useMasterKey: true});
}).then(sessions => {
expect(sessions.length).toBe(0);
done();
}, (err) => {
jfail(err);
done();
});
});
});
7 changes: 4 additions & 3 deletions src/ParseServerRESTController.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ function getSessionToken(options) {

function getAuth(options, config) {
if (options.useMasterKey) {
return Parse.Promise.as(new Auth.Auth({config, isMaster: true }));
return Parse.Promise.as(new Auth.Auth({config, isMaster: true, installationId: 'cloud' }));
}
return getSessionToken(options).then((sessionToken) => {
if (sessionToken) {
options.sessionToken = sessionToken;
return Auth.getAuthForSessionToken({
config,
sessionToken: sessionToken
sessionToken: sessionToken,
installationId: 'cloud'
});
} else {
return Parse.Promise.as(new Auth.Auth({ config }));
return Parse.Promise.as(new Auth.Auth({ config, installationId: 'cloud' }));
}
})
}
Expand Down
5 changes: 5 additions & 0 deletions src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@ RestWrite.prototype.createSessionTokenIfNeeded = function() {
}

RestWrite.prototype.createSessionToken = function() {
// cloud installationId from Cloud Code,
// never create session tokens from there.
if (this.auth.installationId && this.auth.installationId === 'cloud') {
return;
}
var token = 'r:' + cryptoUtils.newToken();

var expiresAt = this.config.generateSessionExpiresAt();
Expand Down

0 comments on commit e3098fc

Please sign in to comment.