Skip to content

Commit

Permalink
Merge branch 'r1.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
pl committed Aug 11, 2014
2 parents c51ea3c + 1e0ae35 commit 28b7337
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 6 additions & 0 deletions lib/pusher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"contributors": [
{
Expand Down
36 changes: 36 additions & 0 deletions tests/integration/pusher/authenticate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: ''$/);
});
});
});

0 comments on commit 28b7337

Please sign in to comment.