diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..2a71602 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +# Changelog + +## 1.0.1 (2014-08-11) + +[CHANGED] Incorrect arguments to `authenticate` will raise an error + +## 1.0.0 (2014-07-14) + +First stable release. diff --git a/lib/pusher.js b/lib/pusher.js index a5ad4de..67b9dee 100644 --- a/lib/pusher.js +++ b/lib/pusher.js @@ -79,6 +79,12 @@ Pusher.forCluster = function(cluster, options) { * @returns {String} authentication signature */ Pusher.prototype.authenticate = function(socketId, channel, data) { + if (typeof socketId !== "string" || socketId === "") { + throw new Error("Invalid socket id: '" + socketId + "'"); + } + if (typeof channel !== "string" || channel === "") { + throw new Error("Invalid channel name: '" + channel + "'"); + } return auth.getSocketSignature(this.config.token, channel, socketId, data); }; diff --git a/package.json b/package.json index e37dad3..25ecc15 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "pusher", "description": "Node.js client to interact with the Pusher REST API", - "version": "1.0.0", + "version": "1.0.1", "author": "Pusher ", "contributors": [ { diff --git a/tests/integration/pusher/authenticate.js b/tests/integration/pusher/authenticate.js index 2679773..cd106e5 100644 --- a/tests/integration/pusher/authenticate.js +++ b/tests/integration/pusher/authenticate.js @@ -66,5 +66,41 @@ describe("Pusher", function() { channel_data: "{\"foo\":\"bar\"}" }); }); + + it("should raise an exception if socket id is not a string", function() { + expect(function() { + pusher.authenticate(undefined, "test") + }).to.throwException(/^Invalid socket id: 'undefined'$/); + expect(function() { + pusher.authenticate(null, "test") + }).to.throwException(/^Invalid socket id: 'null'$/); + expect(function() { + pusher.authenticate(111, "test") + }).to.throwException(/^Invalid socket id: '111'$/); + }); + + it("should raise an exception if socket id is an empty string", function() { + expect(function() { + pusher.authenticate("", "test") + }).to.throwException(/^Invalid socket id: ''$/); + }); + + it("should raise an exception if channel name is not a string", function() { + expect(function() { + pusher.authenticate("111.222", undefined) + }).to.throwException(/^Invalid channel name: 'undefined'$/); + expect(function() { + pusher.authenticate("111.222", null) + }).to.throwException(/^Invalid channel name: 'null'$/); + expect(function() { + pusher.authenticate("111.222", 111) + }).to.throwException(/^Invalid channel name: '111'$/); + }); + + it("should raise an exception if channel name is an empty string", function() { + expect(function() { + pusher.authenticate("111.222", "") + }).to.throwException(/^Invalid channel name: ''$/); + }); }); });