Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apn

Package Overview
Dependencies
Maintainers
2
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apn - npm Package Compare versions

Comparing version 2.1.5 to 2.2.0

.vscode/launch.json

4

ChangeLog.md
## Changelog
2.2.0:
* Proxy support (#163)
* Updated dependencies
2.1.5:

@@ -4,0 +8,0 @@ * Improve typescript type definitions (#536)

@@ -15,2 +15,3 @@ const debug = require("debug")("apn");

const tls = require("tls");
const http = require("http");

@@ -30,2 +31,3 @@ const framer = require("http2/lib/protocol/framer");

tls,
http,
protocol,

@@ -32,0 +34,0 @@ });

@@ -27,2 +27,3 @@ "use strict";

port: 443,
proxy: null,
rejectUnauthorized: true,

@@ -29,0 +30,0 @@ connectionRetryLimit: 10,

@@ -21,2 +21,3 @@ "use strict";

const tls = dependencies.tls;
const http = dependencies.http;
const protocol = dependencies.protocol;

@@ -27,5 +28,12 @@

this.options = options;
options.host = options.host || options.address;
options.servername = options.address;
this.options = Object.assign({}, options);
this.options.ALPNProtocols = ["h2"];
this.options.host = options.host || options.address;
this.options.servername = options.address;
if (options.proxy){
this.options.targetHost = this.options.host;
this.options.targetPort = this.options.port;
this.options.host = this.options.proxy.host;
this.options.port = this.options.proxy.port || this.options.port;
}

@@ -38,6 +46,3 @@ this._acquiredStreamSlots = 0;

options.ALPNProtocols = ["h2"];
this._connect();
this._setupHTTP2Pipeline();
this._heartBeatIntervalCheck = this._setupHTTP2HealthCheck();

@@ -83,3 +88,30 @@ }

Endpoint.prototype._connect = function connect() {
this._socket = tls.connect(this.options);
// Connecting directly to the remote host
if (!this.options.proxy) {
return this._socketOpened(tls.connect(this.options));
}
// Connecting through an HTTP proxy
const req = http.request({
host: this.options.host,
port: this.options.port,
method: "CONNECT",
headers: { Connection: "Keep-Alive" },
path: `${this.options.targetHost}:${this.options.targetPort}`,
});
req.end();
req.on("error", this._error.bind(this));
req.on("connect", (res, socket) => {
const optionsWithProxy = Object.assign({}, this.options, {
socket,
host: this.options.targetHost,
port: this.options.targetPort
});
this._socketOpened(tls.connect(optionsWithProxy));
});
};
Endpoint.prototype._socketOpened = function _socketOpened(socket) {
this._socket = socket;
this._socket.on("secureConnect", this._connected.bind(this));

@@ -94,2 +126,4 @@ this._socket.on("error", this._error.bind(this));

this._connection.on("GOAWAY", this._goaway.bind(this));
this._setupHTTP2Pipeline();
};

@@ -192,3 +226,3 @@

clearInterval(this._heartBeatIntervalCheck);
this._socket.destroy();
if(this._socket) this._socket.destroy();
};

@@ -195,0 +229,0 @@

16

package.json
{
"name": "apn",
"description": "An interface to the Apple Push Notification service for Node.js",
"version": "2.1.5",
"version": "2.2.0",
"author": "Andrew Naylor <argon@mkbot.net>",

@@ -31,14 +31,14 @@ "contributors": [

"dependencies": {
"debug": "^2.6.8",
"debug": "^3.1.0",
"http2": "https://github.com/node-apn/node-http2/archive/apn-2.1.4.tar.gz",
"node-forge": "^0.7.1",
"jsonwebtoken": "^7.4.1",
"jsonwebtoken": "^8.1.0",
"verror": "^1.10.0"
},
"devDependencies": {
"chai": "3.x",
"chai-as-promised": "*",
"mocha": "*",
"sinon": "^1.12.2",
"sinon-chai": "^2.6.0"
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"mocha": "^4.0.1",
"sinon": "^4.1.3",
"sinon-chai": "^2.14.0"
},

@@ -45,0 +45,0 @@ "scripts": {

@@ -40,3 +40,5 @@ [<p align="center"><img src="doc/logo.png" alt="node-apn" width="450" height="auto"></p>][node-apn]

$ npm install apn
```bash
$ npm install apn --save
```

@@ -77,2 +79,25 @@ ## Quick Start

#### Connecting through an HTTP proxy
If you need to connect through an HTTP proxy, you simply need to provide the `proxy: {host, port}` option when creating the provider. For example:
```javascript
var options = {
token: {
key: "path/to/APNsAuthKey_XXXXXXXXXX.p8",
keyId: "key-id",
teamId: "developer-team-id"
},
proxy: {
host: "192.168.10.92",
port: 8080
}
production: false
};
var apnProvider = new apn.Provider(options);
```
The provider will first send an HTTP CONNECT request to the specified proxy in order to establish an HTTP tunnel. Once established, it will create a new secure connection to the Apple Push Notification provider API through the tunnel.
### Sending a notification

@@ -79,0 +104,0 @@ To send a notification you will first need a device token from your app as a string

@@ -531,4 +531,6 @@ "use strict";

return promises.then( response => {
expect(response[1]).to.deep.equal({ device: "adfe5969", error: new Error("endpoint failed") });
expect(response[2]).to.deep.equal({ device: "abcd1335", error: new Error("endpoint failed") });
expect(response[1]).to.have.property("device", "adfe5969");
expect(response[1]).to.have.nested.property("error.message", "endpoint failed");
expect(response[2]).to.have.property("device", "abcd1335");
expect(response[2]).to.have.nested.property("error.message", "endpoint failed");
})

@@ -703,3 +705,3 @@ });

return expect(client.write(builtNotification(), "abcd1234")).to.eventually.have.deep.property("error.jse_shortmsg","Error 500, stream ended unexpectedly");
return expect(client.write(builtNotification(), "abcd1234")).to.eventually.have.nested.property("error.jse_shortmsg","Error 500, stream ended unexpectedly");
});

@@ -706,0 +708,0 @@ });

@@ -30,2 +30,3 @@ "use strict";

port: 443,
proxy: null,
rejectUnauthorized: true,

@@ -32,0 +33,0 @@ connectionRetryLimit: 10,

@@ -49,3 +49,3 @@ "use strict";

fakes.parsePkcs12.withArgs("encryptedPfxData", "apntest").returns({ key: pfxKey, certificates: [pfxCert] });
fakes.parsePkcs12.withArgs("encryptedPfxData", sinon.match.any).throws(new Error("unable to read credentials, incorrect passphrase"));
fakes.parsePkcs12.withArgs("encryptedPfxData", sinon.match((value) => {return value !== "apntest"})).throws(new Error("unable to read credentials, incorrect passphrase"));
});

@@ -83,3 +83,3 @@

fakes.parsePemKey.withArgs("encryptedPemKeyData", "apntest").returns(pemKey);
fakes.parsePemKey.withArgs("encryptedPemKeyData", sinon.match.any).throws(new Error("unable to load key, incorrect passphrase"));
fakes.parsePemKey.withArgs("encryptedPemKeyData", sinon.match((value) => {return value !== "apntest"})).throws(new Error("unable to load key, incorrect passphrase"));
});

@@ -86,0 +86,0 @@

@@ -88,3 +88,3 @@ "use strict";

it("contains the CA data", function() {
return expect(credentials).to.have.deep.property("ca[0]", "myCaData");
return expect(credentials).to.have.nested.property("ca[0]", "myCaData");
});

@@ -91,0 +91,0 @@

@@ -20,3 +20,3 @@ "use strict";

note.alert = "hello";
expect(compiledOutput()).to.have.deep.property("aps.alert", "hello");
expect(compiledOutput()).to.have.nested.property("aps.alert", "hello");
});

@@ -26,4 +26,3 @@

note.alert = {"body": "hello"};
expect(compiledOutput()).to.have.deep.property("aps.alert")
.that.deep.equals({"body": "hello"});
expect(compiledOutput()).to.have.deep.nested.property("aps.alert", {"body": "hello"});
});

@@ -40,3 +39,3 @@

expect(note.setAlert("hello")).to.equal(note);
expect(compiledOutput()).to.have.deep.property("aps.alert", "hello");
expect(compiledOutput()).to.have.nested.property("aps.alert", "hello");
});

@@ -58,3 +57,3 @@ });

note.body = "Hello, world";
expect(compiledOutput()).to.have.deep.property("aps.alert", "Hello, world");
expect(compiledOutput()).to.have.nested.property("aps.alert", "Hello, world");
});

@@ -73,3 +72,3 @@

note.body = "Hello, world";
expect(compiledOutput()).to.have.deep.property("aps.alert.body", "Hello, world");
expect(compiledOutput()).to.have.nested.property("aps.alert.body", "Hello, world");
});

@@ -81,3 +80,3 @@ });

expect(note.setBody("hello")).to.equal(note);
expect(compiledOutput()).to.have.deep.property("aps.alert", "hello");
expect(compiledOutput()).to.have.nested.property("aps.alert", "hello");
});

@@ -90,3 +89,3 @@ });

note.locKey = "hello_world";
expect(compiledOutput()).to.have.deep.property("aps.alert.loc\-key", "hello_world");
expect(compiledOutput()).to.have.nested.property("aps.alert.loc\-key", "hello_world");
});

@@ -101,4 +100,3 @@

it("contains all expected properties", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert")
.that.deep.equals({body: "Test", "launch-image": "test.png", "loc-key": "hello_world"});
expect(compiledOutput()).to.have.deep.nested.property("aps.alert", {body: "Test", "launch-image": "test.png", "loc-key": "hello_world"});
});

@@ -114,7 +112,7 @@ });

it("retains the alert body correctly", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert.body", "Good Morning");
expect(compiledOutput()).to.have.nested.property("aps.alert.body", "Good Morning");
});
it("sets the aps.alert.loc-key property", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert.loc\-key", "good_morning");
expect(compiledOutput()).to.have.nested.property("aps.alert.loc\-key", "good_morning");
});

@@ -126,3 +124,3 @@ });

expect(note.setLocKey("good_morning")).to.equal(note);
expect(compiledOutput()).to.have.deep.property("aps.alert.loc\-key", "good_morning");
expect(compiledOutput()).to.have.nested.property("aps.alert.loc\-key", "good_morning");
});

@@ -135,4 +133,3 @@ });

note.locArgs = ["arg1", "arg2"];
expect(compiledOutput()).to.have.deep.property("aps.alert.loc\-args")
.that.deep.equals(["arg1", "arg2"]);
expect(compiledOutput()).to.have.deep.nested.property("aps.alert.loc\-args", ["arg1", "arg2"]);
});

@@ -147,4 +144,3 @@

it("contains all expected properties", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert")
.that.deep.equals({body: "Test", "launch-image": "test.png", "loc-args": ["Hi there"]});
expect(compiledOutput()).to.have.deep.nested.property("aps.alert", {body: "Test", "launch-image": "test.png", "loc-args": ["Hi there"]});
});

@@ -160,8 +156,7 @@ });

it("retains the alert body", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert.body", "Hello, world");
expect(compiledOutput()).to.have.nested.property("aps.alert.body", "Hello, world");
});
it("sets the aps.alert.loc-args property", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert.loc\-args")
.that.deep.equals(["Hi there"]);
expect(compiledOutput()).to.have.deep.nested.property("aps.alert.loc\-args", ["Hi there"]);
});

@@ -173,4 +168,3 @@ });

expect(note.setLocArgs(["Robert"])).to.equal(note);
expect(compiledOutput()).to.have.deep.property("aps.alert.loc\-args")
.that.deep.equals(["Robert"]);
expect(compiledOutput()).to.have.deep.nested.property("aps.alert.loc\-args", ["Robert"]);
});

@@ -183,3 +177,3 @@ });

note.title = "node-apn";
expect(compiledOutput()).to.have.deep.property("aps.alert.title", "node-apn");
expect(compiledOutput()).to.have.nested.property("aps.alert.title", "node-apn");
});

@@ -194,4 +188,3 @@

it("contains all expected properties", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert")
.that.deep.equals({body: "Test", "launch-image": "test.png", "title": "node-apn"});
expect(compiledOutput()).to.have.deep.nested.property("aps.alert", {body: "Test", "launch-image": "test.png", "title": "node-apn"});
});

@@ -207,7 +200,7 @@ });

it("retains the alert body", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert.body", "Hello, world");
expect(compiledOutput()).to.have.nested.property("aps.alert.body", "Hello, world");
});
it("sets the aps.alert.title property", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert.title", "Welcome");
expect(compiledOutput()).to.have.nested.property("aps.alert.title", "Welcome");
});

@@ -219,3 +212,3 @@ });

expect(note.setTitle("Bienvenue")).to.equal(note);
expect(compiledOutput()).to.have.deep.property("aps.alert.title", "Bienvenue");
expect(compiledOutput()).to.have.nested.property("aps.alert.title", "Bienvenue");
});

@@ -228,3 +221,3 @@ });

note.subtitle = "node-apn";
expect(compiledOutput()).to.have.deep.property("aps.alert.subtitle", "node-apn");
expect(compiledOutput()).to.have.nested.property("aps.alert.subtitle", "node-apn");
});

@@ -239,4 +232,3 @@

it("contains all expected properties", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert")
.that.deep.equals({body: "Test", "launch-image": "test.png", "subtitle": "node-apn"});
expect(compiledOutput()).to.have.deep.nested.property("aps.alert", {body: "Test", "launch-image": "test.png", "subtitle": "node-apn"});
});

@@ -252,7 +244,7 @@ });

it("retains the alert body", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert.body", "Hello, world");
expect(compiledOutput()).to.have.nested.property("aps.alert.body", "Hello, world");
});
it("sets the aps.alert.subtitle property", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert.subtitle", "Welcome");
expect(compiledOutput()).to.have.nested.property("aps.alert.subtitle", "Welcome");
});

@@ -264,3 +256,3 @@ });

expect(note.setSubtitle("Bienvenue")).to.equal(note);
expect(compiledOutput()).to.have.deep.property("aps.alert.subtitle", "Bienvenue");
expect(compiledOutput()).to.have.nested.property("aps.alert.subtitle", "Bienvenue");
});

@@ -272,3 +264,3 @@ });

note.titleLocKey = "Warning";
expect(compiledOutput()).to.have.deep.property("aps.alert.title\-loc\-key", "Warning");
expect(compiledOutput()).to.have.nested.property("aps.alert.title\-loc\-key", "Warning");
});

@@ -283,4 +275,3 @@

it("contains all expected properties", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert")
.that.deep.equals({body: "Test", "launch-image": "test.png", "title-loc-key": "Warning"});
expect(compiledOutput()).to.have.deep.nested.property("aps.alert", {body: "Test", "launch-image": "test.png", "title-loc-key": "Warning"});
});

@@ -296,7 +287,7 @@ });

it("retains the alert body correctly", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert.body", "Hello, world");
expect(compiledOutput()).to.have.nested.property("aps.alert.body", "Hello, world");
});
it("sets the aps.alert.title-loc-key property", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert.title\-loc\-key", "Warning");
expect(compiledOutput()).to.have.nested.property("aps.alert.title\-loc\-key", "Warning");
});

@@ -308,3 +299,3 @@ });

expect(note.setTitleLocKey("greeting")).to.equal(note);
expect(compiledOutput()).to.have.deep.property("aps.alert.title\-loc\-key", "greeting");
expect(compiledOutput()).to.have.nested.property("aps.alert.title\-loc\-key", "greeting");
});

@@ -317,4 +308,3 @@ });

note.titleLocArgs = ["arg1", "arg2"];
expect(compiledOutput()).to.have.deep.property("aps.alert.title\-loc\-args")
.that.deep.equals(["arg1", "arg2"]);
expect(compiledOutput()).to.have.deep.nested.property("aps.alert.title\-loc\-args",["arg1", "arg2"]);
});

@@ -329,4 +319,3 @@

it("contains all expected properties", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert")
.that.deep.equals({body: "Test", "launch-image": "test.png", "title-loc-args": ["Hi there"]});
expect(compiledOutput()).to.have.deep.nested.property("aps.alert", {body: "Test", "launch-image": "test.png", "title-loc-args": ["Hi there"]});
});

@@ -342,8 +331,7 @@ });

it("retains the alert body", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert.body", "Hello, world");
expect(compiledOutput()).to.have.nested.property("aps.alert.body", "Hello, world");
});
it("sets the aps.alert.title-loc-args property", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert.title\-loc\-args")
.that.deep.equals(["Hi there"]);
expect(compiledOutput()).to.have.deep.nested.property("aps.alert.title\-loc\-args", ["Hi there"]);
});

@@ -355,4 +343,3 @@ });

expect(note.setTitleLocArgs(["iPhone 6s"])).to.equal(note);
expect(compiledOutput()).to.have.deep.property("aps.alert.title\-loc\-args")
.that.deep.equals(["iPhone 6s"]);
expect(compiledOutput()).to.have.deep.nested.property("aps.alert.title\-loc\-args", ["iPhone 6s"]);
});

@@ -365,3 +352,3 @@ });

note.action = "View";
expect(compiledOutput()).to.have.deep.property("aps.alert.action", "View");
expect(compiledOutput()).to.have.nested.property("aps.alert.action", "View");
});

@@ -376,4 +363,3 @@

it("contains all expected properties", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert")
.that.deep.equals({body: "Test", "launch-image": "test.png", "action": "View"});
expect(compiledOutput()).to.have.deep.nested.property("aps.alert", {body: "Test", "launch-image": "test.png", "action": "View"});
});

@@ -389,7 +375,7 @@ });

it("retains the alert body", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert.body", "Alert");
expect(compiledOutput()).to.have.nested.property("aps.alert.body", "Alert");
});
it("sets the aps.alert.action property", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert.action", "Investigate");
expect(compiledOutput()).to.have.nested.property("aps.alert.action", "Investigate");
});

@@ -401,3 +387,3 @@ });

expect(note.setAction("Reply")).to.equal(note);
expect(compiledOutput()).to.have.deep.property("aps.alert.action", "Reply");
expect(compiledOutput()).to.have.nested.property("aps.alert.action", "Reply");
});

@@ -410,3 +396,3 @@ });

note.actionLocKey = "reply_title";
expect(compiledOutput()).to.have.deep.property("aps.alert.action\-loc\-key", "reply_title");
expect(compiledOutput()).to.have.nested.property("aps.alert.action\-loc\-key", "reply_title");
});

@@ -421,4 +407,3 @@

it("contains all expected properties", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert")
.that.deep.equals({body: "Test", "launch-image": "test.png", "action-loc-key": "reply_title"});
expect(compiledOutput()).to.have.deep.nested.property("aps.alert", {body: "Test", "launch-image": "test.png", "action-loc-key": "reply_title"});
});

@@ -434,7 +419,7 @@ });

it("retains the alert body correctly", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert.body", "Hello, world");
expect(compiledOutput()).to.have.nested.property("aps.alert.body", "Hello, world");
});
it("sets the aps.alert.action-loc-key property", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert.action\-loc\-key", "ignore_title");
expect(compiledOutput()).to.have.nested.property("aps.alert.action\-loc\-key", "ignore_title");
});

@@ -446,3 +431,3 @@ });

expect(note.setActionLocKey("ignore_title")).to.equal(note);
expect(compiledOutput()).to.have.deep.property("aps.alert.action\-loc\-key", "ignore_title");
expect(compiledOutput()).to.have.nested.property("aps.alert.action\-loc\-key", "ignore_title");
});

@@ -455,4 +440,3 @@ });

note.launchImage = "testLaunch.png";
expect(compiledOutput()).to.have.deep.property("aps.alert.launch\-image")
.that.deep.equals("testLaunch.png");
expect(compiledOutput()).to.have.nested.property("aps.alert.launch\-image", "testLaunch.png");
});

@@ -467,4 +451,3 @@

it("contains all expected properties", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert")
.that.deep.equals({body: "Test", "title-loc-key": "node-apn", "launch-image": "apnLaunch.png"});
expect(compiledOutput()).to.have.deep.nested.property("aps.alert", {body: "Test", "title-loc-key": "node-apn", "launch-image": "apnLaunch.png"});
});

@@ -480,8 +463,7 @@ });

it("retains the alert body", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert.body", "Hello, world");
expect(compiledOutput()).to.have.nested.property("aps.alert.body", "Hello, world");
});
it("sets the aps.alert.launch-image property", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert.launch\-image")
.that.deep.equals("apnLaunch.png");
expect(compiledOutput()).to.have.nested.property("aps.alert.launch\-image", "apnLaunch.png");
})

@@ -493,3 +475,3 @@ });

expect(note.setLaunchImage("remoteLaunch.png")).to.equal(note);
expect(compiledOutput()).to.have.deep.property("aps.alert.launch\-image", "remoteLaunch.png");
expect(compiledOutput()).to.have.nested.property("aps.alert.launch\-image", "remoteLaunch.png");
});

@@ -501,3 +483,3 @@ });

it("defaults to undefined", function() {
expect(compiledOutput()).to.not.have.deep.property("aps.badge");
expect(compiledOutput()).to.not.have.nested.property("aps.badge");
});

@@ -508,3 +490,3 @@

expect(compiledOutput()).to.have.deep.property("aps.badge", 5);
expect(compiledOutput()).to.have.nested.property("aps.badge", 5);
});

@@ -516,3 +498,3 @@

expect(compiledOutput()).to.not.have.deep.property("aps.badge");
expect(compiledOutput()).to.not.have.nested.property("aps.badge");
});

@@ -523,3 +505,3 @@

expect(compiledOutput()).to.have.deep.property("aps.badge", 0);
expect(compiledOutput()).to.have.nested.property("aps.badge", 0);
});

@@ -530,3 +512,3 @@

expect(compiledOutput()).to.not.have.deep.property("aps.badge");
expect(compiledOutput()).to.not.have.nested.property("aps.badge");
});

@@ -537,3 +519,3 @@

expect(note.setBadge(7)).to.equal(note);
expect(compiledOutput()).to.have.deep.property("aps.badge", 7);
expect(compiledOutput()).to.have.nested.property("aps.badge", 7);
});

@@ -545,3 +527,3 @@ });

it("defaults to undefined", function() {
expect(compiledOutput()).to.not.have.deep.property("aps.sound");
expect(compiledOutput()).to.not.have.nested.property("aps.sound");
});

@@ -552,3 +534,3 @@

expect(compiledOutput()).to.have.deep.property("aps.sound", "sound.caf");
expect(compiledOutput()).to.have.nested.property("aps.sound", "sound.caf");
});

@@ -566,3 +548,3 @@

expect(compiledOutput()).to.not.have.deep.property("aps.sound");
expect(compiledOutput()).to.not.have.nested.property("aps.sound");
});

@@ -573,3 +555,3 @@

expect(note.setSound("bee.caf")).to.equal(note);
expect(compiledOutput()).to.have.deep.property("aps.sound", "bee.caf");
expect(compiledOutput()).to.have.nested.property("aps.sound", "bee.caf");
});

@@ -581,3 +563,3 @@ });

it("defaults to undefined", function() {
expect(compiledOutput()).to.not.have.deep.property("aps.content\-available");
expect(compiledOutput()).to.not.have.nested.property("aps.content\-available");
});

@@ -588,3 +570,3 @@

expect(compiledOutput()).to.have.deep.property("aps.content\-available", 1);
expect(compiledOutput()).to.have.nested.property("aps.content\-available", 1);
});

@@ -595,3 +577,3 @@

expect(compiledOutput()).to.have.deep.property("aps.content\-available", 1);
expect(compiledOutput()).to.have.nested.property("aps.content\-available", 1);
});

@@ -603,3 +585,3 @@

expect(compiledOutput()).to.not.have.deep.property("aps.content\-available");
expect(compiledOutput()).to.not.have.nested.property("aps.content\-available");
});

@@ -610,3 +592,3 @@

expect(note.setContentAvailable(true)).to.equal(note);
expect(compiledOutput()).to.have.deep.property("aps.content\-available", 1);
expect(compiledOutput()).to.have.nested.property("aps.content\-available", 1);
});

@@ -618,3 +600,3 @@ });

it("defaults to undefined", function() {
expect(compiledOutput()).to.not.have.deep.property("aps.mutable\-content");
expect(compiledOutput()).to.not.have.nested.property("aps.mutable\-content");
});

@@ -625,3 +607,3 @@

expect(compiledOutput()).to.have.deep.property("aps.mutable\-content", 1);
expect(compiledOutput()).to.have.nested.property("aps.mutable\-content", 1);
});

@@ -632,3 +614,3 @@

expect(compiledOutput()).to.have.deep.property("aps.mutable\-content", 1);
expect(compiledOutput()).to.have.nested.property("aps.mutable\-content", 1);
});

@@ -640,3 +622,3 @@

expect(compiledOutput()).to.not.have.deep.property("aps.mutable\-content");
expect(compiledOutput()).to.not.have.nested.property("aps.mutable\-content");
});

@@ -647,3 +629,3 @@

expect(note.setMutableContent(true)).to.equal(note);
expect(compiledOutput()).to.have.deep.property("aps.mutable\-content", 1);
expect(compiledOutput()).to.have.nested.property("aps.mutable\-content", 1);
});

@@ -655,3 +637,3 @@ });

it("defaults to undefined", function() {
expect(compiledOutput()).to.not.have.deep.property("mdm");
expect(compiledOutput()).to.not.have.nested.property("mdm");
});

@@ -669,3 +651,3 @@

expect(compiledOutput()).to.not.have.deep.property("mdm");
expect(compiledOutput()).to.not.have.property("mdm");
});

@@ -683,3 +665,3 @@

expect(note.setMdm("hello")).to.equal(note);
expect(compiledOutput()).to.have.deep.property("mdm", "hello");
expect(compiledOutput()).to.have.property("mdm", "hello");
});

@@ -691,3 +673,3 @@ });

it("defaults to undefined", function() {
expect(compiledOutput()).to.not.have.deep.property("aps.url\-args");
expect(compiledOutput()).to.not.have.nested.property("aps.url\-args");
});

@@ -698,4 +680,3 @@

expect(compiledOutput()).to.have.deep.property("aps.url\-args")
.that.deep.equals(["arg1", "arg2"]);
expect(compiledOutput()).to.have.deep.nested.property("aps.url\-args", ["arg1", "arg2"]);
});

@@ -707,3 +688,3 @@

expect(compiledOutput()).to.not.have.deep.property("aps.url\-args");
expect(compiledOutput()).to.not.have.nested.property("aps.url\-args");
});

@@ -714,4 +695,3 @@

expect(note.setUrlArgs(["A318", "BA001"])).to.equal(note);
expect(compiledOutput()).to.have.deep.property("aps.url\-args")
.that.deep.equals(["A318", "BA001"]);
expect(compiledOutput()).to.have.deep.nested.property("aps.url\-args", ["A318", "BA001"]);
});

@@ -723,3 +703,3 @@ });

it("defaults to undefined", function() {
expect(compiledOutput()).to.not.have.deep.property("aps.category");
expect(compiledOutput()).to.not.have.nested.property("aps.category");
});

@@ -729,3 +709,3 @@

note.category = "the-category";
expect(compiledOutput()).to.have.deep.property("aps.category", "the-category");
expect(compiledOutput()).to.have.nested.property("aps.category", "the-category");
});

@@ -736,3 +716,3 @@

note.category = undefined;
expect(compiledOutput()).to.not.have.deep.property("aps.category");
expect(compiledOutput()).to.not.have.nested.property("aps.category");
});

@@ -743,3 +723,3 @@

expect(note.setCategory("reminder")).to.equal(note);
expect(compiledOutput()).to.have.deep.property("aps.category", "reminder");
expect(compiledOutput()).to.have.nested.property("aps.category", "reminder");
});

@@ -751,3 +731,3 @@ });

it("defaults to undefined", function() {
expect(compiledOutput()).to.not.have.deep.property("aps.thread\-id");
expect(compiledOutput()).to.not.have.nested.property("aps.thread\-id");
});

@@ -758,3 +738,3 @@

expect(compiledOutput()).to.have.deep.property("aps.thread\-id", "the-thread-id");
expect(compiledOutput()).to.have.nested.property("aps.thread\-id", "the-thread-id");
});

@@ -766,3 +746,3 @@

expect(compiledOutput()).to.not.have.deep.property("aps.thread\-id");
expect(compiledOutput()).to.not.have.nested.property("aps.thread\-id");
});

@@ -773,3 +753,3 @@

expect(note.setThreadId("the-thread-id")).to.equal(note);
expect(compiledOutput()).to.have.deep.property("aps.thread\-id", "the-thread-id");
expect(compiledOutput()).to.have.nested.property("aps.thread\-id", "the-thread-id");
});

@@ -776,0 +756,0 @@ });

@@ -21,3 +21,3 @@ "use strict";

expect(note.topic).to.equal("io.apn.node");
expect(compiledOutput()).to.have.deep.property("aps.badge", 5);
expect(compiledOutput()).to.have.nested.property("aps.badge", 5);
});

@@ -67,4 +67,4 @@ });

it("contains the correct aps properties", function() {
expect(compiledOutput()).to.have.deep.property("aps.badge", 1);
expect(compiledOutput()).to.have.deep.property("aps.alert", "Hi there!");
expect(compiledOutput()).to.have.nested.property("aps.badge", 1);
expect(compiledOutput()).to.have.nested.property("aps.alert", "Hi there!");
});

@@ -71,0 +71,0 @@ });

@@ -5,2 +5,3 @@ "use strict";

const stream = require("stream");
const EventEmitter = require("events");

@@ -19,3 +20,3 @@ const bunyanLogger = sinon.match({

beforeEach(function () {
beforeEach(function () {
fakes = {

@@ -25,2 +26,5 @@ tls: {

},
http: {
request: sinon.stub()
},
protocol: {

@@ -36,8 +40,9 @@ Connection: sinon.stub(),

streams = {
socket: new stream.PassThrough(),
connection: new stream.PassThrough(),
serializer: new stream.PassThrough(),
deserializer: new stream.PassThrough(),
compressor: new stream.PassThrough(),
decompressor: new stream.PassThrough(),
socket: new stream.PassThrough(),
tunneledSocket: new stream.PassThrough(),
connection: new stream.PassThrough(),
serializer: new stream.PassThrough(),
deserializer: new stream.PassThrough(),
compressor: new stream.PassThrough(),
decompressor: new stream.PassThrough(),
};

@@ -49,2 +54,3 @@

sinon.stub(streams.socket, "pipe");
sinon.stub(streams.tunneledSocket, "pipe");
sinon.stub(streams.connection, "pipe");

@@ -113,6 +119,6 @@

context("host is not omitted", function () {
it("falls back on 'address'", function () {
new Endpoint({
address: "localtest", port: 443
});
it("falls back on 'address'", function () {
new Endpoint({
address: "localtest", port: 443
});

@@ -172,2 +178,134 @@ expect(fakes.tls.connect).to.be.calledWith(sinon.match({

context("using an HTTP proxy", function () {
let endpointOptions;
let fakeHttpRequest;
beforeEach(function(){
endpointOptions = {
address: "localtest",
port: 443,
proxy: {host: "proxyaddress", port: 8080}
};
fakeHttpRequest = new EventEmitter();
Object.assign(fakeHttpRequest, {
end: sinon.stub()
});
fakes.http.request
.withArgs(sinon.match({
host: "proxyaddress",
port: 8080,
method: "CONNECT",
headers: { Connection: "Keep-Alive" },
path: "localtest:443",
}))
.returns(fakeHttpRequest);
});
it("sends an HTTP CONNECT request to the proxy", function () {
const endpoint = new Endpoint(endpointOptions);
expect(fakeHttpRequest.end).to.have.been.calledOnce;
});
it("bubbles error events from the HTTP request", function () {
const endpoint = new Endpoint(endpointOptions);
const errorSpy = sinon.spy();
endpoint.on("error", errorSpy);
fakeHttpRequest.emit("error", "this should be bubbled");
expect(errorSpy).to.have.been.calledWith("this should be bubbled");
});
it("opens tls socket using the tunnel socket from the HTTP request", function() {
const endpoint = new Endpoint(endpointOptions);
const httpSocket = {the: "HTTP socket"};
fakeHttpRequest.emit("connect", null, httpSocket);
expect(fakes.tls.connect).to.have.been.calledOnce;
expect(fakes.tls.connect).to.have.been.calledWith(sinon.match({
socket: httpSocket,
host: "localtest",
port: 443
}));
});
it("uses all the additional options when openning the tls socket using the tunnel socket from the HTTP request", function() {
endpointOptions = Object.assign(endpointOptions, {
address: "localtestaddress", host: "localtest", port: 443,
pfx: "pfxData", cert: "certData",
key: "keyData", passphrase: "p4ssphr4s3",
rejectUnauthorized: true,
ALPNProtocols: ["h2"]
});
const endpoint = new Endpoint(endpointOptions);
const httpSocket = {the: "HTTP socket"};
fakeHttpRequest.emit("connect", null, httpSocket);
expect(fakes.tls.connect).to.have.been.calledWith(sinon.match({
socket: httpSocket,
host: "localtest",
port: 443,
servername: "localtestaddress",
pfx: "pfxData", cert: "certData",
key: "keyData", passphrase: "p4ssphr4s3",
rejectUnauthorized: true,
ALPNProtocols: ["h2"]
}));
});
context("tunnel established", function () {
let endpoint;
let httpSocket;
beforeEach(function(){
endpoint = new Endpoint(endpointOptions);
httpSocket = {the: "HTTP socket"};
fakes.tls.connect.withArgs(sinon.match({
socket: httpSocket,
host: "localtest",
port: 443
})).returns(streams.tunneledSocket);
sinon.spy(streams.tunneledSocket, "write");
fakeHttpRequest.emit("connect", null, httpSocket);
});
it("writes the HTTP/2 prelude", function () {
const HTTP2_PRELUDE = Buffer.from("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n");
expect(streams.tunneledSocket.write.firstCall).to.be.calledWith(HTTP2_PRELUDE);
});
it("emits 'connect' event once secure connection with end host is established", function () {
const connect = sinon.spy();
endpoint.on("connect", connect);
streams.tunneledSocket.emit("secureConnect");
expect(connect).to.be.calledOnce;
});
it("bubbles error events", function () {
const errorSpy = sinon.spy();
endpoint.on("error", errorSpy);
streams.tunneledSocket.emit("error", "this should be bubbled");
expect(errorSpy).to.have.been.calledWith("this should be bubbled");
});
it("bubbles end events", function () {
const endSpy = sinon.spy();
endpoint.on("end", endSpy);
streams.tunneledSocket.emit("end");
expect(endSpy).to.have.been.calledOnce;
});
});
});
describe("HTTP/2 layer", function () {

@@ -732,3 +870,3 @@ let endpoint;

expect(streams.socket.destroy).to.be.called.once;
expect(streams.socket.destroy).to.be.calledOnce;
});

@@ -741,3 +879,3 @@ });

streams.connection.ping = (a) => {};
sinon.stub(streams.connection, "ping", (callback) => {
sinon.stub(streams.connection, "ping").callsFake((callback) => {
callback();

@@ -744,0 +882,0 @@ });

@@ -59,3 +59,3 @@ "use strict";

const endpoint = fakes.Endpoint.firstCall.returnValue;
expect(endpoint.destroy).to.be.called.once;
expect(endpoint.destroy).to.be.calledOnce;
});

@@ -242,3 +242,3 @@

it("is destroyed", function () {
expect(endpoint.destroy).to.be.called.once;
expect(endpoint.destroy).to.be.calledOnce;
});

@@ -245,0 +245,0 @@

@@ -144,8 +144,7 @@ "use strict";

return promise.then( (response) => {
expect(response.failed).to.deep.equal([
{ device: "adfe5969", status: "400", response: { reason: "MissingTopic" }},
{ device: "abcd1335", status: "410", response: { reason: "BadDeviceToken", timestamp: 123456789 }},
{ device: "aabbc788", status: "413", response: { reason: "PayloadTooLarge" }},
{ device: "fbcde238", error: new Error("connection failed") },
]);
expect(response.failed[0]).to.deep.equal({ device: "adfe5969", status: "400", response: { reason: "MissingTopic" }});
expect(response.failed[1]).to.deep.equal({ device: "abcd1335", status: "410", response: { reason: "BadDeviceToken", timestamp: 123456789 }});
expect(response.failed[2]).to.deep.equal({ device: "aabbc788", status: "413", response: { reason: "PayloadTooLarge" }});
expect(response.failed[3]).to.have.property("device", "fbcde238");
expect(response.failed[3]).to.have.nested.property("error.message", "connection failed");
});

@@ -152,0 +151,0 @@ });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc