Skip to content

Commit b910a99

Browse files
committed
Disables find on installation from clients
- fixes #1372
1 parent 18906f1 commit b910a99

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

spec/ParseInstallation.spec.js

+44
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,50 @@ describe('Installations', () => {
119119
}).catch((error) => { console.log(error); });
120120
});
121121

122+
it('should properly fail queying installations', (done) => {
123+
var installId = '12345678-abcd-abcd-abcd-123456789abc';
124+
var device = 'android';
125+
var input = {
126+
'installationId': installId,
127+
'deviceType': device
128+
};
129+
rest.create(config, auth.nobody(config), '_Installation', input)
130+
.then(() => {
131+
let query = new Parse.Query(Parse.Installation);
132+
return query.find()
133+
}).then((results) => {
134+
fail('Should not succeed!');
135+
done();
136+
}).catch((error) => {
137+
expect(error.code).toBe(119);
138+
expect(error.message).toBe('Clients aren\'t allowed to perform the find operation on the installation collection.')
139+
done();
140+
});
141+
});
142+
143+
it('should properly queying installations with masterKey', (done) => {
144+
var installId = '12345678-abcd-abcd-abcd-123456789abc';
145+
var device = 'android';
146+
var input = {
147+
'installationId': installId,
148+
'deviceType': device
149+
};
150+
rest.create(config, auth.nobody(config), '_Installation', input)
151+
.then(() => {
152+
let query = new Parse.Query(Parse.Installation);
153+
return query.find({useMasterKey: true});
154+
}).then((results) => {
155+
expect(results.length).toEqual(1);
156+
var obj = results[0].toJSON();
157+
expect(obj.installationId).toEqual(installId);
158+
expect(obj.deviceType).toEqual(device);
159+
done();
160+
}).catch((error) => {
161+
fail('Should not fail');
162+
done();
163+
});
164+
});
165+
122166
it('fails with missing ids', (done) => {
123167
var input = {
124168
'deviceType': 'android',

src/rest.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ function update(config, auth, className, objectId, restObject) {
119119

120120
// Disallowing access to the _Role collection except by master key
121121
function enforceRoleSecurity(method, className, auth) {
122-
if (method === 'delete' && className === '_Installation' && !auth.isMaster) {
123-
throw new Parse.Error(Parse.Error.OPERATION_FORBIDDEN,
124-
'Clients aren\'t allowed to perform the ' +
125-
'delete operation on the installation collection.');
126-
122+
if (className === '_Installation' && !auth.isMaster) {
123+
if (method === 'delete' || method === 'find') {
124+
let error = `Clients aren't allowed to perform the ${method} operation on the installation collection.`
125+
throw new Parse.Error(Parse.Error.OPERATION_FORBIDDEN, error);
126+
}
127127
}
128128
}
129129

0 commit comments

Comments
 (0)