adds ability to pass custom installationId to create sessions in cloud code (#3156)
This commit is contained in:
@@ -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 => {
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -11,9 +11,10 @@ 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) {
|
||||
@@ -21,10 +22,10 @@ function getAuth(options, config) {
|
||||
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 }));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user