Skip to content

Commit

Permalink
Fix error when updating installation with useMasterKey (#2888)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
JeremyPlease authored and flovilmart committed Oct 19, 2016
1 parent 305b037 commit a6a6f7f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
23 changes: 23 additions & 0 deletions spec/ParseInstallation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit a6a6f7f

Please sign in to comment.