diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3e0d81de39..c29e98ea45 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,6 +4,23 @@ We really want Parse to be yours, to see it grow and thrive in the open source community. +##### Parse-server running on master + +Get started by cloning the [parser-server-example](https://github.com/parse-community/parse-server-example) repository and running `npm install` inside it. Update `parse-clients-config.json` inside the repo. + +Then add parse-server from master branch as a submodule + +``` +git submodule add https://github.com/parse-community/parse-server + +``` + +Now link parse-server to use the repo instead of the package + +``` +npm link parse-server ./parse-server +``` + ##### Please Do's * Take testing seriously! Aim to increase the test coverage with every pull request. diff --git a/spec/PushController.spec.js b/spec/PushController.spec.js index 1eb1607daf..e8956ee0d9 100644 --- a/spec/PushController.spec.js +++ b/spec/PushController.spec.js @@ -657,4 +657,38 @@ describe('PushController', () => { done(); }); }); + + it('sends push only when a deviceToken is set', (done) => { + var config = new Config(Parse.applicationId); + var auth = { + isMaster: true + } + var pushAdapter = { + send: function(body, installations) { + return successfulTransmissions(body, installations); + }, + getValidPushTypes: function() { + return ["ios", "android"]; + } + } + + var pushController = new PushController(); + const payload = { + data: { + alert: 'hello', + }, + push_time: new Date().getTime() + } + + reconfigureServer({ + push: { adapter: pushAdapter } + }).then(() => { + return pushController.sendPush(payload, {}, config, auth); + }).then(() => { + done(); + }, (err) => { + jfail(err); + done(); + }); + }); }); diff --git a/src/Controllers/PushController.js b/src/Controllers/PushController.js index 4e25b7ad52..eb5a707067 100644 --- a/src/Controllers/PushController.js +++ b/src/Controllers/PushController.js @@ -15,6 +15,11 @@ export class PushController { // Replace the expiration_time and push_time with a valid Unix epoch milliseconds time body.expiration_time = PushController.getExpirationTime(body); body.push_time = PushController.getPushTime(body); + // Intend to allow pushes only to valid installations + var hasDeviceToken = where.hasOwnProperty('deviceToken'); + if (!hasDeviceToken) { + where["deviceToken"] = {"$exists":true}; + } // TODO: If the req can pass the checking, we return immediately instead of waiting // pushes to be sent. We probably change this behaviour in the future. let badgeUpdate = () => {