Skip to content

Commit a6a6f7f

Browse files
JeremyPleaseflovilmart
authored andcommitted
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
1 parent 305b037 commit a6a6f7f

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

spec/ParseInstallation.spec.js

+23
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,29 @@ describe('Installations', () => {
906906
});
907907
});
908908

909+
it('allows you to update installation with masterKey', done => {
910+
let installId = '12345678-abcd-abcd-abcd-123456789abc';
911+
let device = 'android';
912+
let input = {
913+
'installationId': installId,
914+
'deviceType': device
915+
};
916+
rest.create(config, auth.nobody(config), '_Installation', input)
917+
.then(createResult => {
918+
let installationObj = Parse.Installation.createWithoutData(createResult.response.objectId);
919+
installationObj.set('customField', 'custom value');
920+
return installationObj.save(null, {useMasterKey: true});
921+
}).then(updateResult => {
922+
expect(updateResult).not.toBeUndefined();
923+
expect(updateResult.get('customField')).toEqual('custom value');
924+
done();
925+
}).catch(error => {
926+
console.log(error);
927+
fail('failed');
928+
done();
929+
});
930+
});
931+
909932
// TODO: Look at additional tests from installation_collection_test.go:882
910933
// TODO: Do we need to support _tombstone disabling of installations?
911934
// TODO: Test deletion, badge increments

src/RestWrite.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,12 @@ RestWrite.prototype.handleInstallation = function() {
578578
this.data.installationId = this.data.installationId.toLowerCase();
579579
}
580580

581-
// If data.installationId is not set, we can lookup in the auth
582-
let installationId = this.data.installationId || this.auth.installationId;
581+
let installationId = this.data.installationId;
582+
583+
// If data.installationId is not set and we're not master, we can lookup in auth
584+
if (!installationId && !this.auth.isMaster) {
585+
installationId = this.auth.installationId;
586+
}
583587

584588
if (installationId) {
585589
installationId = installationId.toLowerCase();

0 commit comments

Comments
 (0)