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

apn

Package Overview
Dependencies
Maintainers
1
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 1.6.2 to 1.7.0

lib/credentials/APNCertificate.js

5

ChangeLog.md
## Changelog
1.7.0:
* Added: Credential validator to catch common configuration errors.
* Fixed: Documentation errors.
1.6.2:

@@ -4,0 +9,0 @@

41

lib/connection.js

@@ -9,3 +9,5 @@ var Errors = require('./errors');

var Device = require('./device');
var CredentialLoader = require('./credentials');
var loadCredentials = require('./credentials/load');
var parseCredentials = require("./credentials/parse");
var validateCredentials = require("./credentials/validate");

@@ -96,2 +98,10 @@ var createSocket = require('./socket');

}
else {
if (this.options.address == "gateway.push.apple.com") {
this.options.production = true;
}
else {
this.options.production = false;
}
}

@@ -143,3 +153,18 @@ if (this.options.pfx || this.options.pfxData) {

debug("Initialising module");
this.initializationPromise = CredentialLoader(this.options);
var production = this.options.production;
this.initializationPromise = loadCredentials(this.options)
.then(function(credentials) {
var parsed;
try {
parsed = parseCredentials(credentials);
}
catch (e) {
debug(e);
return credentials;
}
parsed.production = production;
validateCredentials(parsed);
return credentials;
});
}

@@ -161,3 +186,3 @@

this.deferredConnection = q.defer();
this.initialize().spread(function (pfxData, certData, keyData, caData) {
this.initialize().then(function(credentials) {
var socketOptions = {};

@@ -172,6 +197,6 @@

socketOptions.pfx = pfxData;
socketOptions.cert = certData;
socketOptions.key = keyData;
socketOptions.ca = caData;
socketOptions.pfx = credentials.pfx;
socketOptions.cert = credentials.cert;
socketOptions.key = credentials.key;
socketOptions.ca = credentials.ca;
socketOptions.passphrase = this.options.passphrase;

@@ -210,3 +235,3 @@ socketOptions.rejectUnauthorized = this.options.rejectUnauthorized;

this.terminated = true;
}.bind(this));
}.bind(this)).done();

@@ -213,0 +238,0 @@ return this.deferredConnection.promise;

@@ -1,2 +0,4 @@

var CredentialLoader = require('./credentials');
var loadCredentials = require('./credentials/load');
var parseCredentials = require('./credentials/parse');
var validateCredentials = require('./credentials/validate');
var Device = require('./device');

@@ -75,2 +77,10 @@ var Errors = require('./errors');

}
else {
if (this.options.address == "feedback.push.apple.com") {
this.options.production = true;
}
else {
this.options.production = false;
}
}

@@ -120,3 +130,18 @@ if (this.options.pfx || this.options.pfxData) {

debug("Initialising module");
this.initializationPromise = CredentialLoader(this.options);
var production = this.options.production;
this.initializationPromise = loadCredentials(this.options)
.then(function(credentials) {
var parsed;
try {
parsed = parseCredentials(credentials);
}
catch (e) {
debug(e);
return credentials;
}
parsed.production = production;
validateCredentials(parsed);
return credentials;
});
}

@@ -138,3 +163,3 @@

this.deferredConnection = q.defer();
this.initialize().spread(function(pfxData, certData, keyData, caData) {
this.initialize().then(function(credentials) {
var socketOptions = {};

@@ -144,6 +169,6 @@

socketOptions.host = this.options.address;
socketOptions.pfx = pfxData;
socketOptions.cert = certData;
socketOptions.key = keyData;
socketOptions.ca = caData;
socketOptions.pfx = credentials.pfx;
socketOptions.cert = credentials.cert;
socketOptions.key = credentials.key;
socketOptions.ca = credentials.ca;
socketOptions.passphrase = this.options.passphrase;

@@ -168,3 +193,3 @@ socketOptions.rejectUnauthorized = this.options.rejectUnauthorized;

this.deferredConnection = null;
}.bind(this));
}.bind(this)).done();

@@ -171,0 +196,0 @@ return this.deferredConnection.promise;

13

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

@@ -30,11 +30,14 @@ "contributors": [

"dependencies": {
"q": "1.x"
"node-forge": "^0.6.20",
"q": "1.1.x"
},
"devDependencies": {
"chai": "*",
"chai-as-promised": "*",
"mocha": "*",
"chai": "*",
"chai-as-promised": "*"
"sinon": "^1.12.2",
"sinon-chai": "^2.6.0"
},
"scripts": {
"test": "node_modules/.bin/mocha -w"
"test": "node_modules/.bin/mocha"
},

@@ -41,0 +44,0 @@ "engines": {

@@ -1,4 +0,7 @@

var apn = require("../");
var fs = require("fs");
var rewire = require("rewire");
var Connection = rewire("../lib/connection");
var sinon = require("sinon");
var Q = require("q");
describe("Connection", function() {

@@ -22,3 +25,3 @@ describe('constructor', function () {

it("should use gateway.sandbox.push.apple.com as the default connection address", function () {
apn.Connection().options.address.should.equal("gateway.sandbox.push.apple.com");
expect(Connection().options.address).to.equal("gateway.sandbox.push.apple.com");
});

@@ -28,3 +31,3 @@

process.env.NODE_ENV = "production";
apn.Connection().options.address.should.equal("gateway.push.apple.com");
expect(Connection().options.address).to.equal("gateway.push.apple.com");
});

@@ -34,20 +37,309 @@

process.env.NODE_ENV = "production";
apn.Connection({ production: false }).options.address.should.equal("gateway.sandbox.push.apple.com");
expect(Connection({ production: false }).options.address).to.equal("gateway.sandbox.push.apple.com");
});
it("should use gateway.push.apple.com when production:true", function () {
apn.Connection({production:true}).options.address.should.equal("gateway.push.apple.com");
expect(Connection({production:true}).options.address).to.equal("gateway.push.apple.com");
});
it("should use a custom address when passed", function () {
apn.Connection({address: "testaddress"}).options.address.should.equal("testaddress");
expect(Connection({address: "testaddress"}).options.address).to.equal("testaddress");
});
describe("address is passed", function() {
it("sets production to true when using production address", function() {
expect(Connection({address: "gateway.push.apple.com"}).options.production).to.be.true;
});
it("sets production to false when using sandbox address", function() {
process.env.NODE_ENV = "production";
expect(Connection({address: "gateway.sandbox.push.apple.com"}).options.production).to.be.false;
});
});
});
describe('#initialize', function () {
it("should be fulfilled", function () {
return apn.Connection({ pfx: "test/support/initializeTest.pfx" })
.initialize().should.be.fulfilled;
var loadStub, parseStub, validateStub, removeStubs;
beforeEach(function() {
loadStub = sinon.stub();
loadStub.displayName = "loadCredentials";
parseStub = sinon.stub();
parseStub.displayName = "parseCredentials";
validateStub = sinon.stub();
validateStub.displayName = "validateCredentials";
removeStubs = Connection.__set__({
"loadCredentials": loadStub,
"parseCredentials": parseStub,
"validateCredentials": validateStub,
});
});
afterEach(function() {
removeStubs();
});
it("only loads credentials once", function() {
loadStub.returns(Q({}));
var connection = Connection();
connection.initialize();
connection.initialize();
expect(loadStub).to.be.calledOnce;
});
describe("with valid credentials", function() {
var initialization;
var testOptions = {
pfx: "myCredentials.pfx", cert: "myCert.pem", key: "myKey.pem", ca: "myCa.pem",
passphrase: "apntest", production: true
};
beforeEach(function() {
loadStub.withArgs(sinon.match(function(v) {
return v.pfx == "myCredentials.pfx" && v.cert == "myCert.pem" && v.key == "myKey.pem" &&
v.ca == "myCa.pem" && v.passphrase == "apntest";
})).returns(Q({ pfx: "myPfxData", cert: "myCertData", key: "myKeyData", ca: ["myCaData"], passphrase: "apntest" }));
parseStub.returnsArg(0);
initialization = Connection(testOptions).initialize();
});
it("should be fulfilled", function () {
return expect(initialization).to.be.fulfilled;
});
describe("the validation stage", function() {
it("is called once", function() {
return initialization.finally(function() {
expect(validateStub).to.be.calledOnce;
});
});
it("is passed the production flag", function() {
return initialization.finally(function() {
expect(validateStub.getCall(0).args[0]).to.have.property("production", true);
});
});
describe("passed credentials", function() {
it("contains the PFX data", function() {
return initialization.finally(function() {
expect(validateStub.getCall(0).args[0]).to.have.property("pfx", "myPfxData");
});
});
it("contains the key data", function() {
return initialization.finally(function() {
expect(validateStub.getCall(0).args[0]).to.have.property("key", "myKeyData");
});
});
it("contains the certificate data", function() {
return initialization.finally(function() {
expect(validateStub.getCall(0).args[0]).to.have.property("cert", "myCertData");
});
});
it("includes passphrase", function() {
return initialization.finally(function() {
expect(validateStub.getCall(0).args[0]).to.have.property("passphrase", "apntest");
});
});
});
});
describe("resolution value", function() {
it("contains the PFX data", function() {
return expect(initialization).to.eventually.have.property("pfx", "myPfxData");
});
it("contains the key data", function() {
return expect(initialization).to.eventually.have.property("key", "myKeyData");
});
it("contains the certificate data", function() {
return expect(initialization).to.eventually.have.property("cert", "myCertData");
});
it("contains the CA data", function() {
return expect(initialization).to.eventually.have.deep.property("ca[0]", "myCaData");
});
it("includes passphrase", function() {
return expect(initialization).to.eventually.have.property("passphrase", "apntest");
});
});
});
describe("credential file cannot be parsed", function() {
beforeEach(function() {
loadStub.returns(Q({ cert: "myCertData", key: "myKeyData" }));
parseStub.throws(new Error("unable to parse key"));
});
it("should resolve with the credentials", function() {
var initialization = Connection({ cert: "myUnparseableCert.pem", key: "myUnparseableKey.pem" }).initialize();
return expect(initialization).to.become({ cert: "myCertData", key: "myKeyData" });
});
it("should log an error", function() {
var debug = sinon.spy();
var reset = Connection.__set__("debug", debug);
var initialization = Connection({ cert: "myUnparseableCert.pem", key: "myUnparseableKey.pem" }).initialize();
return initialization.finally(function() {
reset();
expect(debug).to.be.calledWith(sinon.match(function(err) {
return err.message ? err.message.match(/unable to parse key/) : false;
}, "\"unable to parse key\""));
});
});
it("should not attempt to validate", function() {
var initialization = Connection({ cert: "myUnparseableCert.pem", key: "myUnparseableKey.pem" }).initialize();
return initialization.finally(function() {
expect(validateStub).to.not.be.called;
});
});
});
describe("credential validation fails", function() {
it("should be rejected", function() {
loadStub.returns(Q({ cert: "myCertData", key: "myMismatchedKeyData" }));
parseStub.returnsArg(0);
validateStub.throws(new Error("certificate and key do not match"));
var initialization = Connection({ cert: "myCert.pem", key: "myMistmatchedKey.pem" }).initialize();
return expect(initialization).to.eventually.be.rejectedWith(/certificate and key do not match/);
});
});
describe("credential file cannot be loaded", function() {
it("should be rejected", function() {
loadStub.returns(Q.reject(new Error("ENOENT, no such file or directory")));
var initialization = Connection({ cert: "noSuchFile.pem", key: "myKey.pem" }).initialize();
return expect(initialization).to.eventually.be.rejectedWith("ENOENT, no such file or directory");
});
});
});
describe("connect", function() {
var socketStub, removeSocketStub;
before(function() {
var initializeStub = sinon.stub(Connection.prototype, "initialize");
initializeStub.returns(Q({
pfx: "pfxData",
key: "keyData",
cert: "certData",
ca: ["caData1", "caData2"],
passphrase: "apntest" }));
});
beforeEach(function() {
socketStub = sinon.stub();
socketStub.callsArg(2);
socketStub.returns({ on: function() {}, once: function() {}, end: function() {} });
removeSocketStub = Connection.__set__("createSocket", socketStub);
});
afterEach(function() {
removeSocketStub();
});
it("initializes the module", function(done) {
var connection = Connection({ pfx: "myCredentials.pfx" });
return connection.connect().finally(function() {
expect(connection.initialize).to.have.been.calledOnce;
done();
});
});
describe("with valid credentials", function() {
it("resolves", function() {
var connection = Connection({
cert: "myCert.pem",
key: "myKey.pem"
});
return expect(connection.connect()).to.be.fulfilled;
});
describe("the call to create socket", function() {
var connect;
it("passes PFX data", function() {
connect = Connection({
pfx: "myCredentials.pfx",
passphrase: "apntest"
}).connect();
return connect.then(function() {
var socketOptions = socketStub.args[0][1];
expect(socketOptions.pfx).to.equal("pfxData");
});
});
it("passes the passphrase", function() {
connect = Connection({
passphrase: "apntest",
cert: "myCert.pem",
key: "myKey.pem"
}).connect();
return connect.then(function() {
var socketOptions = socketStub.args[0][1];
expect(socketOptions.passphrase).to.equal("apntest");
});
});
it("passes the cert", function() {
connect = Connection({
cert: "myCert.pem",
key: "myKey.pem"
}).connect();
return connect.then(function() {
var socketOptions = socketStub.args[0][1];
expect(socketOptions.cert).to.equal("certData");
});
});
it("passes the key", function() {
connect = Connection({
cert: "test/credentials/support/cert.pem",
key: "test/credentials/support/key.pem"
}).connect();
return connect.then(function() {
var socketOptions = socketStub.args[0][1];
expect(socketOptions.key).to.equal("keyData");
});
});
it("passes the ca certificates", function() {
connect = Connection({
cert: "test/credentials/support/cert.pem",
key: "test/credentials/support/key.pem",
ca: [ "test/credentials/support/issuerCert.pem" ]
}).connect();
return connect.then(function() {
var socketOptions = socketStub.args[0][1];
expect(socketOptions.ca[0]).to.equal("caData1");
});
});
});
});
describe("intialization failure", function() {
it("is rejected", function() {
var connection = Connection({ pfx: "a-non-existant-file-which-really-shouldnt-exist.pfx" });
connection.on("error", function() {});
connection.initialize.returns(Q.reject(new Error("initialize failed")));
return expect(connection.connect()).to.be.rejectedWith("initialize failed");
});
});
});
});

@@ -8,15 +8,15 @@ var apn = require("../");

it("should error when given a device string which contains no hex characters and results in 0 length token", function () {
(function () {
expect(function () {
apn.Device("som string without hx lttrs");
}).should.throw();
}).to.throw();
});
it("should error when given a device string which contains an odd number of hex characters", function () {
(function () {
expect(function () {
apn.Device("01234");
}).should.throw();
}).to.throw();
});
it("should return a Device object containing the correct token when given a hex string", function () {
apn.Device("<0123 4567 89AB CDEF>").toString().should.equal("0123456789abcdef");
expect(apn.Device("<0123 4567 89AB CDEF>").toString()).to.equal("0123456789abcdef");
});

@@ -26,5 +26,5 @@

var buf = new Buffer([1, 35, 69, 103, 137, 171, 205, 239]);
apn.Device(buf).toString().should.equal("0123456789abcdef");
expect(apn.Device(buf).toString()).to.equal("0123456789abcdef");
});
});
});

@@ -1,12 +0,23 @@

var apn = require("../");
var fs = require("fs");
var rewire = require("rewire");
var Feedback = rewire("../lib/feedback");
var sinon = require("sinon");
var Q = require("q");
describe("Feedback", function() {
var startMethod;
before(function() {
// Constructor has side effects :-(
startMethod = Feedback.prototype.start;
Feedback.prototype.start = function() { };
});
after(function() {
Feedback.prototype.start = startMethod;
});
describe('constructor', function () {
var requestMethod, originalEnv;
var originalEnv;
before(function() {
requestMethod = apn.Feedback.prototype.request;
apn.Feedback.prototype.request = function() { };
originalEnv = process.env.NODE_ENV;

@@ -16,3 +27,2 @@ });

after(function() {
apn.Feedback.prototype.request = requestMethod;
process.env.NODE_ENV = originalEnv;

@@ -27,3 +37,3 @@ });

it("should use feedback.sandbox.push.apple.com as the default Feedback address", function () {
apn.Feedback().options.address.should.equal("feedback.sandbox.push.apple.com");
expect(Feedback().options.address).to.equal("feedback.sandbox.push.apple.com");
});

@@ -33,7 +43,7 @@

process.env.NODE_ENV = "production";
apn.Feedback().options.address.should.equal("feedback.push.apple.com");
expect(Feedback().options.address).to.equal("feedback.push.apple.com");
});
it("should use feedback.push.apple.com when production:true", function () {
apn.Feedback({production:true}).options.address.should.equal("feedback.push.apple.com");
expect(Feedback({production:true}).options.address).to.equal("feedback.push.apple.com");
});

@@ -43,17 +53,305 @@

process.env.NODE_ENV = "production";
apn.Feedback({ production: false }).options.address.should.equal("feedback.sandbox.push.apple.com");
expect(Feedback({ production: false }).options.address).to.equal("feedback.sandbox.push.apple.com");
});
it("should use a custom address when passed", function () {
apn.Feedback({address: "testaddress"}).options.address.should.equal("testaddress");
expect(Feedback({address: "testaddress"}).options.address).to.equal("testaddress");
});
describe("address is passed", function() {
it("sets production to true when using production address", function() {
expect(Feedback({address: "feedback.push.apple.com"}).options.production).to.be.true;
});
it("sets production to false when using sandbox address", function() {
process.env.NODE_ENV = "production";
expect(Feedback({address: "feedback.sandbox.push.apple.com"}).options.production).to.be.false;
});
});
});
describe('#initialize', function () {
var loadStub, parseStub, validateStub, removeStubs;
beforeEach(function() {
loadStub = sinon.stub();
loadStub.displayName = "loadCredentials";
it("should be fulfilled", function () {
return apn.Feedback({ pfx: "test/support/initializeTest.pfx" })
.initialize().should.be.fulfilled;
parseStub = sinon.stub();
parseStub.displayName = "parseCredentials";
validateStub = sinon.stub();
validateStub.displayName = "validateCredentials";
removeStubs = Feedback.__set__({
"loadCredentials": loadStub,
"parseCredentials": parseStub,
"validateCredentials": validateStub,
});
});
afterEach(function() {
removeStubs();
});
it("only loads credentials once", function() {
loadStub.returns(Q({}));
var feedback = Feedback();
feedback.initialize();
feedback.initialize();
expect(loadStub).to.be.calledOnce;
});
describe("with valid credentials", function() {
var initialization;
var testOptions = {
pfx: "myCredentials.pfx", cert: "myCert.pem", key: "myKey.pem", ca: "myCa.pem",
passphrase: "apntest", production: true
};
beforeEach(function() {
loadStub.withArgs(sinon.match(function(v) {
return v.pfx == "myCredentials.pfx" && v.cert == "myCert.pem" && v.key == "myKey.pem" &&
v.ca == "myCa.pem" && v.passphrase == "apntest";
})).returns(Q({ pfx: "myPfxData", cert: "myCertData", key: "myKeyData", ca: ["myCaData"], passphrase: "apntest" }));
parseStub.returnsArg(0);
initialization = Feedback(testOptions).initialize();
});
it("should be fulfilled", function () {
return expect(initialization).to.be.fulfilled;
});
describe("the validation stage", function() {
it("is called once", function() {
return initialization.finally(function() {
expect(validateStub).to.be.calledOnce;
});
});
it("is passed the production flag", function() {
return initialization.finally(function() {
expect(validateStub.getCall(0).args[0]).to.have.property("production", true);
});
});
describe("passed credentials", function() {
it("contains the PFX data", function() {
return initialization.finally(function() {
expect(validateStub.getCall(0).args[0]).to.have.property("pfx", "myPfxData");
});
});
it("contains the key data", function() {
return initialization.finally(function() {
expect(validateStub.getCall(0).args[0]).to.have.property("key", "myKeyData");
});
});
it("contains the certificate data", function() {
return initialization.finally(function() {
expect(validateStub.getCall(0).args[0]).to.have.property("cert", "myCertData");
});
});
it("includes passphrase", function() {
return initialization.finally(function() {
expect(validateStub.getCall(0).args[0]).to.have.property("passphrase", "apntest");
});
});
});
});
describe("resolution value", function() {
it("contains the PFX data", function() {
return expect(initialization).to.eventually.have.property("pfx", "myPfxData");
});
it("contains the key data", function() {
return expect(initialization).to.eventually.have.property("key", "myKeyData");
});
it("contains the certificate data", function() {
return expect(initialization).to.eventually.have.property("cert", "myCertData");
});
it("contains the CA data", function() {
return expect(initialization).to.eventually.have.deep.property("ca[0]", "myCaData");
});
it("includes passphrase", function() {
return expect(initialization).to.eventually.have.property("passphrase", "apntest");
});
});
});
describe("credential file cannot be parsed", function() {
beforeEach(function() {
loadStub.returns(Q({ cert: "myCertData", key: "myKeyData" }));
parseStub.throws(new Error("unable to parse key"));
});
it("should resolve with the credentials", function() {
var initialization = Feedback({ cert: "myUnparseableCert.pem", key: "myUnparseableKey.pem" }).initialize();
return expect(initialization).to.become({ cert: "myCertData", key: "myKeyData" });
});
it("should log an error", function() {
var debug = sinon.spy();
var reset = Feedback.__set__("debug", debug);
var initialization = Feedback({ cert: "myUnparseableCert.pem", key: "myUnparseableKey.pem" }).initialize();
return initialization.finally(function() {
reset();
expect(debug).to.be.calledWith(sinon.match(function(err) {
return err.message ? err.message.match(/unable to parse key/) : false;
}, "\"unable to parse key\""));
});
});
it("should not attempt to validate", function() {
var initialization = Feedback({ cert: "myUnparseableCert.pem", key: "myUnparseableKey.pem" }).initialize();
return initialization.finally(function() {
expect(validateStub).to.not.be.called;
});
});
});
describe("credential validation fails", function() {
it("should be rejected", function() {
loadStub.returns(Q({ cert: "myCertData", key: "myMismatchedKeyData" }));
parseStub.returnsArg(0);
validateStub.throws(new Error("certificate and key do not match"));
var initialization = Feedback({ cert: "myCert.pem", key: "myMistmatchedKey.pem" }).initialize();
return expect(initialization).to.eventually.be.rejectedWith(/certificate and key do not match/);
});
});
describe("credential file cannot be loaded", function() {
it("should be rejected", function() {
loadStub.returns(Q.reject(new Error("ENOENT, no such file or directory")));
var initialization = Feedback({ cert: "noSuchFile.pem", key: "myKey.pem" }).initialize();
return expect(initialization).to.eventually.be.rejectedWith("ENOENT, no such file or directory");
});
});
});
describe("connect", function() {
var socketStub, removeSocketStub;
before(function() {
var initializeStub = sinon.stub(Feedback.prototype, "initialize");
initializeStub.returns(Q({
pfx: "pfxData",
key: "keyData",
cert: "certData",
ca: ["caData1", "caData2"],
passphrase: "apntest" }));
});
beforeEach(function() {
socketStub = sinon.stub();
socketStub.callsArg(2);
socketStub.returns({ on: function() {}, once: function() {}, end: function() {} });
removeSocketStub = Feedback.__set__("createSocket", socketStub);
});
afterEach(function() {
removeSocketStub();
});
it("initializes the module", function(done) {
var feedback = Feedback({ pfx: "myCredentials.pfx" });
return feedback.connect().finally(function() {
expect(feedback.initialize).to.have.been.calledOnce;
done();
});
});
describe("with valid credentials", function() {
it("resolves", function() {
var feedback = Feedback({
cert: "myCert.pem",
key: "myKey.pem"
});
return expect(feedback.connect()).to.be.fulfilled;
});
describe("the call to create socket", function() {
var connect;
it("passes PFX data", function() {
connect = Feedback({
pfx: "myCredentials.pfx",
passphrase: "apntest"
}).connect();
return connect.then(function() {
var socketOptions = socketStub.args[0][1];
expect(socketOptions.pfx).to.equal("pfxData");
});
});
it("passes the passphrase", function() {
connect = Feedback({
passphrase: "apntest",
cert: "myCert.pem",
key: "myKey.pem"
}).connect();
return connect.then(function() {
var socketOptions = socketStub.args[0][1];
expect(socketOptions.passphrase).to.equal("apntest");
});
});
it("passes the cert", function() {
connect = Feedback({
cert: "myCert.pem",
key: "myKey.pem"
}).connect();
return connect.then(function() {
var socketOptions = socketStub.args[0][1];
expect(socketOptions.cert).to.equal("certData");
});
});
it("passes the key", function() {
connect = Feedback({
cert: "test/credentials/support/cert.pem",
key: "test/credentials/support/key.pem"
}).connect();
return connect.then(function() {
var socketOptions = socketStub.args[0][1];
expect(socketOptions.key).to.equal("keyData");
});
});
it("passes the ca certificates", function() {
connect = Feedback({
cert: "test/credentials/support/cert.pem",
key: "test/credentials/support/key.pem",
ca: [ "test/credentials/support/issuerCert.pem" ]
}).connect();
return connect.then(function() {
var socketOptions = socketStub.args[0][1];
expect(socketOptions.ca[0]).to.equal("caData1");
});
});
});
});
describe("intialization failure", function() {
it("is rejected", function() {
var feedback = Feedback({ pfx: "a-non-existant-file-which-really-shouldnt-exist.pfx" });
feedback.on('error', function() {});
feedback.initialize.returns(Q.reject(new Error("initialize failed")));
return expect(feedback.connect()).to.be.rejectedWith("initialize failed");
});
});
});
});

@@ -13,3 +13,3 @@ var apn = require("../");

note.trim();
note.length().should.equal(2048);
expect(note.length()).to.equal(2048);
});

@@ -22,3 +22,3 @@

note.trim();
note.length().should.equal(2048);
expect(note.length()).to.equal(2048);
});

@@ -29,3 +29,3 @@

note.trim(256);
note.length().should.equal(256);
expect(note.length()).to.equal(256);
});

@@ -36,3 +36,3 @@

note.trim(256);
note.length().should.equal(255);
expect(note.length()).to.equal(255);
});

@@ -43,3 +43,3 @@

note.trim(256);
note.length().should.be.at.most(256);
expect(note.length()).to.be.at.most(256);
});

@@ -50,5 +50,5 @@

note.trim(256);
note.length().should.be.at.most(256);
expect(note.length()).to.be.at.most(256);
});
});

@@ -5,4 +5,8 @@ "use strict";

var chaiAsPromised = require("chai-as-promised");
var sinonChai = require("sinon-chai");
chai.should();
chai.use(chaiAsPromised);
chai.config.includeStack = true;
chai.use(chaiAsPromised);
chai.use(sinonChai);
global.expect = chai.expect;

Sorry, the diff of this file is not supported yet

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