Skip to content

Commit 86f3501

Browse files
authored
Fixes #2780 (#2810)
* Adds regression test for #2780 * Fixes #2780 - Make sure we compare installationId from the data and not the auth when rejecting update
1 parent 758975c commit 86f3501

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

spec/ParseInstallation.spec.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,55 @@ describe('Installations', () => {
929929
});
930930
});
931931

932+
it('should properly handle installation save #2780', done => {
933+
let installId = '12345678-abcd-abcd-abcd-123456789abc';
934+
let device = 'android';
935+
let input = {
936+
'installationId': installId,
937+
'deviceType': device
938+
};
939+
rest.create(config, auth.nobody(config), '_Installation', input).then(() => {
940+
let query = new Parse.Query(Parse.Installation);
941+
query.equalTo('installationId', installId);
942+
query.first({useMasterKey: true}).then((installation) => {
943+
return installation.save({
944+
key: 'value'
945+
}, {useMasterKey: true});
946+
}).then(() => {
947+
done();
948+
}, (err) => {
949+
jfail(err)
950+
done();
951+
});
952+
});
953+
});
954+
955+
it('should properly reject updating installationId', done => {
956+
let installId = '12345678-abcd-abcd-abcd-123456789abc';
957+
let device = 'android';
958+
let input = {
959+
'installationId': installId,
960+
'deviceType': device
961+
};
962+
rest.create(config, auth.nobody(config), '_Installation', input).then(() => {
963+
let query = new Parse.Query(Parse.Installation);
964+
query.equalTo('installationId', installId);
965+
query.first({useMasterKey: true}).then((installation) => {
966+
return installation.save({
967+
key: 'value',
968+
installationId: '22222222-abcd-abcd-abcd-123456789abc'
969+
}, {useMasterKey: true});
970+
}).then(() => {
971+
fail('should not succeed');
972+
done();
973+
}, (err) => {
974+
expect(err.code).toBe(136);
975+
expect(err.message).toBe('installationId may not be changed in this operation');
976+
done();
977+
});
978+
});
979+
});
980+
932981
// TODO: Look at additional tests from installation_collection_test.go:882
933982
// TODO: Do we need to support _tombstone disabling of installations?
934983
// TODO: Test deletion, badge increments

src/RestWrite.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,8 @@ RestWrite.prototype.handleInstallation = function() {
639639
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND,
640640
'Object not found for update.');
641641
}
642-
if (installationId && objectIdMatch.installationId &&
643-
installationId !== objectIdMatch.installationId) {
642+
if (this.data.installationId && objectIdMatch.installationId &&
643+
this.data.installationId !== objectIdMatch.installationId) {
644644
throw new Parse.Error(136,
645645
'installationId may not be changed in this ' +
646646
'operation');

0 commit comments

Comments
 (0)