Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloud Code: Allows user session creation with DIRECT_ACCESS #3156

Merged
merged 1 commit into from
Dec 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion spec/ParseServerRESTController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ describe('ParseServerRESTController', () => {
});

it('ensures no session token is created on creating users', (done) => {
RESTController.request("POST", "/classes/_User", {username: "hello", password: "world"}).then(() => {
RESTController.request("POST", "/classes/_User", {username: "hello", password: "world"}).then((user) => {
expect(user.sessionToken).toBeUndefined();
let query = new Parse.Query('_Session');
return query.find({useMasterKey: true});
}).then(sessions => {
Expand All @@ -115,4 +116,19 @@ describe('ParseServerRESTController', () => {
done();
});
});

it('ensures a session token is created when passing installationId != cloud', (done) => {
RESTController.request("POST", "/classes/_User", {username: "hello", password: "world"}, {installationId: 'my-installation'}).then((user) => {
expect(user.sessionToken).not.toBeUndefined();
let query = new Parse.Query('_Session');
return query.find({useMasterKey: true});
}).then(sessions => {
expect(sessions.length).toBe(1);
expect(sessions[0].get('installationId')).toBe('my-installation');
done();
}, (err) => {
jfail(err);
done();
});
});
});
9 changes: 5 additions & 4 deletions src/ParseServerRESTController.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@ function getSessionToken(options) {
return Parse.Promise.as(null);
}

function getAuth(options, config) {
function getAuth(options = {}, config) {
const installationId = options.installationId || 'cloud';
if (options.useMasterKey) {
return Parse.Promise.as(new Auth.Auth({config, isMaster: true, installationId: 'cloud' }));
return Parse.Promise.as(new Auth.Auth({config, isMaster: true, installationId }));
}
return getSessionToken(options).then((sessionToken) => {
if (sessionToken) {
options.sessionToken = sessionToken;
return Auth.getAuthForSessionToken({
config,
sessionToken: sessionToken,
installationId: 'cloud'
installationId
});
} else {
return Parse.Promise.as(new Auth.Auth({ config, installationId: 'cloud' }));
return Parse.Promise.as(new Auth.Auth({ config, installationId }));
}
})
}
Expand Down