Comparing version 1.0.5 to 1.1.0
1.1.0 / 2014-03-11 | ||
================== | ||
* bug: streams emit empty reads in node 0.11 | ||
* Merge pull request #6 from lemonlabs/ft/mockagent | ||
* Extend MockAgent so it can simulate msg rejection on Apple side (err 8) | ||
1.0.5 / 2013-11-21 | ||
@@ -3,0 +10,0 @@ ================== |
@@ -11,3 +11,3 @@ /*! | ||
exports.version = '1.0.5'; | ||
exports.version = '1.1.0'; | ||
@@ -14,0 +14,0 @@ /*! |
@@ -23,3 +23,4 @@ /*! | ||
, errors = require('../errors') | ||
, util = require('../util'); | ||
, util = require('../util') | ||
, Device = require('../device'); | ||
@@ -47,2 +48,5 @@ /*! | ||
Base.call(this); | ||
// Messages sent to these devices will be rejected with error 8 BAD_TOKEN | ||
this.badDevices = [] | ||
} | ||
@@ -119,7 +123,28 @@ | ||
function shouldBeRejected (msgJson) { | ||
msgDevice = new Device(msgJson.deviceToken); | ||
reject = false; | ||
for (var i = 0; i < self.badDevices.length; i++) { | ||
reject = self.badDevices[i].equal(msgDevice) | ||
} | ||
return reject; | ||
} | ||
// data event is emitted for each message | ||
function emitter () { | ||
var json = this.read(); | ||
debug('(gateway) incoming message', json); | ||
self.emit('mock:message', json); | ||
if (!json) return; | ||
// Simulate message error at Apple side | ||
if (shouldBeRejected(json)) { | ||
var err = new errors.GatewayMessageError("Invalid token", {code: 8}) | ||
self.meta.gatewayError = err; | ||
debug('(gateway) incoming message error', err.toJSON(false)); | ||
self.emit('message:error', err, json); | ||
gateway.end(); | ||
} else { | ||
debug('(gateway) incoming message', json); | ||
self.emit('mock:message', json); | ||
} | ||
} | ||
@@ -195,2 +220,33 @@ | ||
/** | ||
* .setBadDevices () | ||
* | ||
* If, after setting tokens here, message is sent to one | ||
* of these token, it'll result in error 8 "Invalid token". | ||
* Connection then will be closed. | ||
* | ||
* Intended to be used by clients when testing their error | ||
* mitigation logics. | ||
* | ||
* @param {Array} Array of Device | ||
* @name setBadDevices | ||
* @api public | ||
*/ | ||
Mock.prototype.setBadDevices = function (devices) { | ||
// Validate input, crash early if smth is wrong - | ||
// better than search for a bug somewhere deep in code | ||
if (!(devices instanceof Array)) { | ||
throw new Error('Parameter "devices" should be an array of Device'); | ||
} else { | ||
for (var i = 0; i < devices.length; i++) { | ||
if (!(devices[i] instanceof Device)) { | ||
throw new Error('Parameter "devices" should be an array of Device') | ||
} | ||
} | ||
} | ||
// All good | ||
this.badDevices = devices; | ||
}; | ||
Mock.prototype._queueIterator = function (obj, next) { | ||
@@ -197,0 +253,0 @@ var self = this |
{ | ||
"name": "apnagent" | ||
, "version": "1.0.5" | ||
, "version": "1.1.0" | ||
, "description": "Node adapter for Apple Push Notification (APN) service." | ||
@@ -5,0 +5,0 @@ , "author": "Jake Luer <jake@qualiancy.com> (http://qualiancy.com)" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68537
2245