Comparing version 1.5.1 to 1.5.2
## Changelog | ||
1.5.2: | ||
* Fixed #169, #170: Undesirable behaviour when PFX files are specified | ||
* Fixes several problems identified after adding further test coverage. | ||
1.5.0/1.5.1: | ||
@@ -4,0 +9,0 @@ |
@@ -84,2 +84,11 @@ var Errors = require('./errors'); | ||
if (this.options.pfx || this.options.pfxData) { | ||
if (!options.cert) { | ||
this.options.cert = null; | ||
} | ||
if (!options.key) { | ||
this.options.key = null; | ||
} | ||
} | ||
this.initializationPromise = null; | ||
@@ -137,3 +146,3 @@ this.deferredConnection = null; | ||
} | ||
else { | ||
else if(this.options.cert){ | ||
// Nothing has matched so attempt to load from disk | ||
@@ -151,3 +160,3 @@ certPromise = readFile(this.options.cert); | ||
} | ||
else { | ||
else if(this.options.key) { | ||
keyPromise = readFile(this.options.key); | ||
@@ -166,3 +175,3 @@ } | ||
} | ||
else { | ||
else if (ca){ | ||
caPromises.push(readFile(ca)); | ||
@@ -183,6 +192,9 @@ } | ||
function checkPEMType(input, type) { | ||
if (input == null) { | ||
return; | ||
} | ||
var matches = input.match(/\-\-\-\-\-BEGIN ([A-Z\s*]+)\-\-\-\-\-/); | ||
if (matches != null) { | ||
return matches[1].indexOf(type) > 0; | ||
return matches[1].indexOf(type) >= 0; | ||
} | ||
@@ -189,0 +201,0 @@ return false; |
@@ -38,3 +38,5 @@ var Device = require('./device'); | ||
function Feedback(options) { | ||
if(false === (this instanceof Feedback)) { | ||
return new Feedback(options); | ||
} | ||
this.options = { | ||
@@ -67,2 +69,11 @@ cert: 'cert.pem', /* Certificate file */ | ||
if (this.options.pfx || this.options.pfxData) { | ||
if (!options.cert) { | ||
this.options.cert = null; | ||
} | ||
if (!options.key) { | ||
this.options.key = null; | ||
} | ||
} | ||
this.initializationPromise = null; | ||
@@ -109,3 +120,3 @@ this.deferredConnection = null; | ||
var pfxPromise = null; | ||
if(this.options.pfx !== null || this.options.pfxData !== null) { | ||
if(this.options.pfx != null || this.options.pfxData != null) { | ||
if(this.options.pfxData) { | ||
@@ -127,6 +138,6 @@ pfxPromise = this.options.pfxData; | ||
} | ||
else if(Buffer.isBuffer(this.options.key) || checkPEMType(this.options.cert, "CERTIFICATE")) { | ||
else if(Buffer.isBuffer(this.options.cert) || checkPEMType(this.options.cert, "CERTIFICATE")) { | ||
certPromise = this.options.cert; | ||
} | ||
else { | ||
else if(this.options.cert) { | ||
// Nothing has matched so attempt to load from disk | ||
@@ -144,3 +155,3 @@ certPromise = readFile(this.options.cert); | ||
} | ||
else { | ||
else if(this.options.key){ | ||
keyPromise = readFile(this.options.key); | ||
@@ -159,3 +170,3 @@ } | ||
} | ||
else { | ||
else if(ca) { | ||
caPromises.push(readFile(ca)); | ||
@@ -176,6 +187,9 @@ } | ||
function checkPEMType(input, type) { | ||
if(input == null) { | ||
return false; | ||
} | ||
var matches = input.match(/\-\-\-\-\-BEGIN ([A-Z\s*]+)\-\-\-\-\-/); | ||
if (matches != null) { | ||
return matches[1].indexOf(type) > 0; | ||
return matches[1].indexOf(type) >= 0; | ||
} | ||
@@ -182,0 +196,0 @@ return false; |
{ | ||
"name": "apn", | ||
"description": "An interface to the Apple Push Notification service for Node.js", | ||
"version": "1.5.1", | ||
"version": "1.5.2", | ||
"author": "Andrew Naylor <argon@mkbot.net>", | ||
@@ -30,7 +30,8 @@ "contributors": [ | ||
"dependencies": { | ||
"q": "0.9.x" | ||
"q": "1.x" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*", | ||
"should": "3.x.x" | ||
"chai": "*", | ||
"chai-as-promised": "*" | ||
}, | ||
@@ -37,0 +38,0 @@ "scripts": { |
var apn = require("../"); | ||
var fs = require("fs"); | ||
@@ -8,3 +9,6 @@ describe("Connection", function() { | ||
it("should use gateway.sandbox.push.apple.com as the default connection address", function () { | ||
var existingEnv = process.env.NODE_ENV; | ||
process.env.NODE_ENV = ""; | ||
apn.Connection().options.address.should.equal("gateway.sandbox.push.apple.com"); | ||
process.env.NODE_ENV = existingEnv; | ||
}); | ||
@@ -19,2 +23,9 @@ | ||
it("should give precedence to production flag over NODE_ENV=production", function () { | ||
var existingEnv = process.env.NODE_ENV; | ||
process.env.NODE_ENV = "production"; | ||
apn.Connection({ production: false }).options.address.should.equal("gateway.sandbox.push.apple.com"); | ||
process.env.NODE_ENV = existingEnv; | ||
}); | ||
it("should use gateway.push.apple.com when production:true", function () { | ||
@@ -28,2 +39,108 @@ apn.Connection({production:true}).options.address.should.equal("gateway.push.apple.com"); | ||
}); | ||
describe('#initialize', function () { | ||
var pfx, cert, key, ca; | ||
before(function () { | ||
pfx = fs.readFileSync("test/support/initializeTest.pfx"); | ||
cert = fs.readFileSync("test/support/initializeTest.crt"); | ||
key = fs.readFileSync("test/support/initializeTest.key"); | ||
}); | ||
it("should eventually load a pfx file from disk", function () { | ||
return apn.Connection({ pfx: "test/support/initializeTest.pfx" }) | ||
.initialize().get(0).post("toString") | ||
.should.eventually.equal(pfx.toString()); | ||
}); | ||
it("should eventually provide pfx data from memory", function () { | ||
return apn.Connection({ pfx: pfx }).initialize().get(0).post("toString") | ||
.should.eventually.equal(pfx.toString()); | ||
}); | ||
it("should eventually provide pfx data explicitly passed in pfxData parameter", function () { | ||
return apn.Connection({ pfxData: pfx }).initialize().get(0).post("toString") | ||
.should.eventually.equal(pfx.toString()); | ||
}); | ||
it("should eventually load a certificate from disk", function () { | ||
return apn.Connection({ cert: "test/support/initializeTest.crt", key: null}) | ||
.initialize().get(1).post("toString") | ||
.should.eventually.equal(cert.toString()); | ||
}); | ||
it("should eventually provide a certificate from a Buffer", function () { | ||
return apn.Connection({ cert: cert, key: null}) | ||
.initialize().get(1).post("toString") | ||
.should.eventually.equal(cert.toString()); | ||
}); | ||
it("should eventually provide a certificate from a String", function () { | ||
return apn.Connection({ cert: cert.toString(), key: null}) | ||
.initialize().get(1) | ||
.should.eventually.equal(cert.toString()); | ||
}); | ||
it("should eventually provide certificate data explicitly passed in the certData parameter", function () { | ||
return apn.Connection({ certData: cert, key: null}) | ||
.initialize().get(1).post("toString") | ||
.should.eventually.equal(cert.toString()); | ||
}); | ||
it("should eventually load a key from disk", function () { | ||
return apn.Connection({ cert: null, key: "test/support/initializeTest.key"}) | ||
.initialize().get(2).post("toString") | ||
.should.eventually.equal(key.toString()); | ||
}); | ||
it("should eventually provide a key from a Buffer", function () { | ||
return apn.Connection({ cert: null, key: key}) | ||
.initialize().get(2).post("toString") | ||
.should.eventually.equal(key.toString()); | ||
}); | ||
it("should eventually provide a key from a String", function () { | ||
return apn.Connection({ cert: null, key: key.toString()}) | ||
.initialize().get(2) | ||
.should.eventually.equal(key.toString()); | ||
}) | ||
it("should eventually provide key data explicitly passed in the keyData parameter", function () { | ||
return apn.Connection({ cert: null, keyData: key}) | ||
.initialize().get(2).post("toString") | ||
.should.eventually.equal(key.toString()); | ||
}); | ||
it("should eventually load a single CA certificate from disk", function () { | ||
return apn.Connection({ cert: null, key: null, ca: "test/support/initializeTest.crt" }) | ||
.initialize().get(3).get(0).post("toString") | ||
.should.eventually.equal(cert.toString()); | ||
}); | ||
it("should eventually provide a single CA certificate from a Buffer", function () { | ||
return apn.Connection({ cert: null, key: null, ca: cert }) | ||
.initialize().get(3).get(0).post("toString") | ||
.should.eventually.equal(cert.toString()); | ||
}); | ||
it("should eventually provide a single CA certificate from a String", function () { | ||
return apn.Connection({ cert: null, key: null, ca: cert.toString() }) | ||
.initialize().get(3).get(0) | ||
.should.eventually.equal(cert.toString()); | ||
}); | ||
it("should eventually load an array of CA certificates", function (done) { | ||
apn.Connection({ cert: null, key: null, ca: ["test/support/initializeTest.crt", cert, cert.toString()] }) | ||
.initialize().get(3).spread(function(cert1, cert2, cert3) { | ||
var certString = cert.toString(); | ||
if (cert1.toString() == certString && | ||
cert2.toString() == certString && | ||
cert3.toString() == certString) { | ||
done(); | ||
} | ||
else { | ||
done(new Error("provided certificates did not match")); | ||
} | ||
}, done); | ||
}); | ||
}); | ||
}); |
@@ -5,23 +5,3 @@ var apn = require("../"); | ||
describe('constructor', function () { | ||
// Issue #50 | ||
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"); | ||
}); | ||
it("should use gateway.push.apple.com when NODE_ENV=production", function () { | ||
var existingEnv = process.env.NODE_ENV; | ||
process.env.NODE_ENV = "production"; | ||
apn.Connection().options.address.should.equal("gateway.push.apple.com"); | ||
process.env.NODE_ENV = existingEnv; | ||
}); | ||
it("should use gateway.push.apple.com when production:true", function () { | ||
apn.Connection({production:true}).options.address.should.equal("gateway.push.apple.com"); | ||
}); | ||
it("should use a custom address when passed", function () { | ||
apn.Connection({address: "testaddress"}).options.address.should.equal("testaddress"); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
114318
25
1759
3
26