Skip to content

Commit

Permalink
Remove useless masterKey validation in PushController.sendPush.
Browse files Browse the repository at this point in the history
  • Loading branch information
nlutsenko committed Mar 7, 2016
1 parent 4b0f84e commit b2a8292
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 38 deletions.
25 changes: 0 additions & 25 deletions spec/PushController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,6 @@ var PushController = require('../src/Controllers/PushController').PushController
var Config = require('../src/Config');

describe('PushController', () => {
it('can check valid master key of request', (done) => {
// Make mock request
var auth = {
isMaster: true
}

expect(() => {
PushController.validateMasterKey(auth);
}).not.toThrow();
done();
});

it('can check invalid master key of request', (done) => {
// Make mock request
var auth = {
isMaster: false
}

expect(() => {
PushController.validateMasterKey(auth);
}).toThrow();
done();
});


it('can validate device type when no device type is set', (done) => {
// Make query condition
var where = {
Expand Down
14 changes: 1 addition & 13 deletions src/Controllers/PushController.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,13 @@ export class PushController extends AdaptableController {
}
}
}

/**
* Check whether the api call has master key or not.
* @param {Object} request A request object
*/
static validateMasterKey(auth = {}) {
if (!auth.isMaster) {
throw new Parse.Error(Parse.Error.PUSH_MISCONFIGURED,
'Master key is invalid, you should only use master key to send push');
}
}

sendPush(body = {}, where = {}, config, auth) {
var pushAdapter = this.adapter;
if (!pushAdapter) {
throw new Parse.Error(Parse.Error.PUSH_MISCONFIGURED,
'Push adapter is not available');
}
PushController.validateMasterKey(auth);
PushController.validatePushType(where, pushAdapter.getValidPushTypes());
// Replace the expiration_time with a valid Unix epoch milliseconds time
body['expiration_time'] = PushController.getExpirationTime(body);
Expand Down Expand Up @@ -140,6 +128,6 @@ export class PushController extends AdaptableController {
expectedAdapterType() {
return PushAdapter;
}
};
}

export default PushController;

0 comments on commit b2a8292

Please sign in to comment.