Fix error when updating installation with useMasterKey (#2888)
* Add failing test for updating installations with masterKey * Prevent auth.installationId from being used when using masterKey This allows masterKey to update any installation object Fixes ParsePlatform/parse-server##2887
This commit is contained in:
committed by
Florent Vilmart
parent
305b037176
commit
a6a6f7ff60
@@ -906,6 +906,29 @@ describe('Installations', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('allows you to update installation with masterKey', done => {
|
||||
let installId = '12345678-abcd-abcd-abcd-123456789abc';
|
||||
let device = 'android';
|
||||
let input = {
|
||||
'installationId': installId,
|
||||
'deviceType': device
|
||||
};
|
||||
rest.create(config, auth.nobody(config), '_Installation', input)
|
||||
.then(createResult => {
|
||||
let installationObj = Parse.Installation.createWithoutData(createResult.response.objectId);
|
||||
installationObj.set('customField', 'custom value');
|
||||
return installationObj.save(null, {useMasterKey: true});
|
||||
}).then(updateResult => {
|
||||
expect(updateResult).not.toBeUndefined();
|
||||
expect(updateResult.get('customField')).toEqual('custom value');
|
||||
done();
|
||||
}).catch(error => {
|
||||
console.log(error);
|
||||
fail('failed');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: Look at additional tests from installation_collection_test.go:882
|
||||
// TODO: Do we need to support _tombstone disabling of installations?
|
||||
// TODO: Test deletion, badge increments
|
||||
|
||||
@@ -578,8 +578,12 @@ RestWrite.prototype.handleInstallation = function() {
|
||||
this.data.installationId = this.data.installationId.toLowerCase();
|
||||
}
|
||||
|
||||
// If data.installationId is not set, we can lookup in the auth
|
||||
let installationId = this.data.installationId || this.auth.installationId;
|
||||
let installationId = this.data.installationId;
|
||||
|
||||
// If data.installationId is not set and we're not master, we can lookup in auth
|
||||
if (!installationId && !this.auth.isMaster) {
|
||||
installationId = this.auth.installationId;
|
||||
}
|
||||
|
||||
if (installationId) {
|
||||
installationId = installationId.toLowerCase();
|
||||
|
||||
Reference in New Issue
Block a user