Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions spec/ParseInstallation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,127 @@ describe('Installations', () => {
});
});

it('update fails to clear installationId via Delete op', done => {
Comment thread
AdrianCurtin marked this conversation as resolved.
const installId = '12345678-abcd-abcd-abcd-123456789abc';
const input = {
installationId: installId,
deviceType: 'ios',
};
rest
.create(config, auth.nobody(config), '_Installation', input)
.then(() => database.adapter.find('_Installation', installationSchema, {}, {}))
.then(results => {
expect(results.length).toEqual(1);
return rest.update(
config,
auth.nobody(config),
'_Installation',
{ objectId: results[0].objectId },
{ installationId: { __op: 'Delete' } }
);
})
.then(() => {
fail('Updating the installation should have failed.');
done();
})
.catch(error => {
expect(error.code).toEqual(136);
done();
});
});

it('update fails to clear installationId via null', done => {
Comment thread
AdrianCurtin marked this conversation as resolved.
const installId = '12345678-abcd-abcd-abcd-123456789abc';
const input = {
installationId: installId,
deviceType: 'ios',
};
rest
.create(config, auth.nobody(config), '_Installation', input)
.then(() => database.adapter.find('_Installation', installationSchema, {}, {}))
.then(results => {
expect(results.length).toEqual(1);
return rest.update(
config,
auth.nobody(config),
'_Installation',
{ objectId: results[0].objectId },
{ installationId: null }
);
})
.then(() => {
fail('Updating the installation should have failed.');
done();
})
.catch(error => {
expect(error.code).toEqual(136);
done();
});
});

it('create fails when installationId is the Delete op (no real ID provided)', done => {
const input = {
installationId: { __op: 'Delete' },
deviceType: 'ios',
};
rest
.create(config, auth.nobody(config), '_Installation', input)
.then(() => {
fail('Creating the installation should have failed.');
done();
})
.catch(error => {
expect(error.code).toEqual(135);
done();
});
});

it('create fails when installationId is null (no real ID provided)', done => {
Comment thread
AdrianCurtin marked this conversation as resolved.
const input = {
installationId: null,
deviceType: 'ios',
};
rest
.create(config, auth.nobody(config), '_Installation', input)
.then(() => {
fail('Creating the installation should have failed.');
done();
})
.catch(error => {
expect(error.code).toEqual(135);
done();
});
Comment thread
AdrianCurtin marked this conversation as resolved.
});

it('master key cannot clear installationId', done => {
const installId = '12345678-abcd-abcd-abcd-123456789abc';
const input = {
installationId: installId,
deviceType: 'ios',
};
rest
.create(config, auth.master(config), '_Installation', input)
.then(() => database.adapter.find('_Installation', installationSchema, {}, {}))
.then(results => {
expect(results.length).toEqual(1);
return rest.update(
config,
auth.master(config),
'_Installation',
{ objectId: results[0].objectId },
{ installationId: { __op: 'Delete' } }
);
})
.then(() => {
fail('Master key clearing of installationId should have been rejected.');
done();
})
.catch(error => {
expect(error.code).toEqual(136);
done();
});
Comment thread
AdrianCurtin marked this conversation as resolved.
});

it('update fails to change deviceType', done => {
const installId = '12345678-abcd-abcd-abcd-123456789abc';
let input = {
Expand Down
21 changes: 21 additions & 0 deletions src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,27 @@ RestWrite.prototype.handleInstallation = function () {
return;
}

// installationId is the row's primary identity (used by the SDK auth
// header to bind a client request to its row). Reject any attempt to
// clear it via null or { __op: 'Delete' } before the lookup logic
// below runs — { __op: 'Delete' } would otherwise crash on
// `.toLowerCase()` (TypeError → 500) and null would silently orphan
// the row. Mirrors the existing 136 guard against changing
// installationId from one value to another.
const clearingInstallationId =
this.data.installationId === null ||
(typeof this.data.installationId === 'object' &&
this.data.installationId !== null &&
this.data.installationId.__op === 'Delete');
Comment thread
AdrianCurtin marked this conversation as resolved.
if (clearingInstallationId) {
if (this.query) {
throw new Parse.Error(136, 'installationId may not be changed in this operation');
Comment thread
AdrianCurtin marked this conversation as resolved.
Outdated
}
// Create path: drop the operator/null so the "must specify ID"
// guard below fires with the correct 135 error.
delete this.data.installationId;
}

if (
!this.query &&
!this.data.deviceToken &&
Expand Down
Loading