Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/LearnBoost/socket.io into a…
Browse files Browse the repository at this point in the history
…uth-fix
  • Loading branch information
gavinuhma committed Nov 22, 2011
2 parents 4c17f7f + 5ee6b43 commit 61e7e89
Show file tree
Hide file tree
Showing 16 changed files with 440 additions and 315 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
@@ -0,0 +1,7 @@
language: node_js
node_js:
- 0.4
- 0.6

notifications:
irc: "irc.freenode.org#socket.io"
14 changes: 11 additions & 3 deletions lib/manager.js
Expand Up @@ -10,6 +10,7 @@

var fs = require('fs')
, url = require('url')
, tty = require('tty')
, util = require('./util')
, store = require('./store')
, client = require('socket.io-client')
Expand Down Expand Up @@ -69,7 +70,7 @@ function Manager (server, options) {
, authorization: false
, blacklist: ['disconnect']
, 'log level': 3
, 'log colors': true
, 'log colors': tty.isatty(process.stdout.fd)
, 'close timeout': 25
, 'heartbeat timeout': 15
, 'heartbeat interval': 20
Expand Down Expand Up @@ -468,7 +469,8 @@ Manager.prototype.onClientMessage = function (id, packet) {

Manager.prototype.onClientDisconnect = function (id, reason) {
for (var name in this.namespaces) {
this.namespaces[name].handleDisconnect(id, reason, typeof this.roomClients[id][name] !== 'undefined');
this.namespaces[name].handleDisconnect(id, reason, typeof this.roomClients[id] !== 'undefined' &&
typeof this.roomClients[id][name] !== 'undefined');
}

this.onDisconnect(id);
Expand Down Expand Up @@ -623,7 +625,12 @@ Manager.prototype.handleClient = function (data, req) {

var transport = new transports[data.transport](this, data, req)
, handshaken = this.handshaken[data.id];


if (transport.disconnected) {
// failed during transport setup
req.connection.end();
return;
}
if (handshaken) {
if (transport.open) {
if (this.closed[data.id] && this.closed[data.id].length) {
Expand Down Expand Up @@ -810,6 +817,7 @@ Manager.prototype.verifyOrigin = function (request) {
if (origin) {
try {
var parts = url.parse(origin);
parts.port = parts.port || 80;
var ok =
~origins.indexOf(parts.hostname + ':' + parts.port) ||
~origins.indexOf(parts.hostname + ':*') ||
Expand Down
5 changes: 4 additions & 1 deletion lib/transports/websocket/hybi-07-12.js
Expand Up @@ -159,6 +159,7 @@ WebSocket.prototype.verifyOrigin = function (origin) {
if (origin) {
try {
var parts = url.parse(origin);
parts.port = parts.port || 80;
var ok =
~origins.indexOf(parts.hostname + ':' + parts.port) ||
~origins.indexOf(parts.hostname + ':*') ||
Expand Down Expand Up @@ -505,7 +506,9 @@ Parser.prototype.expect = function(what, length, handler) {
*/

Parser.prototype.processPacket = function (data) {
if ((data[0] & 0x70) != 0) this.error('reserved fields must be empty');
if ((data[0] & 0x70) != 0) {
this.error('reserved fields must be empty');
}
this.state.lastFragment = (data[0] & 0x80) == 0x80;
this.state.masked = (data[1] & 0x80) == 0x80;
var opcode = data[0] & 0xf;
Expand Down
6 changes: 5 additions & 1 deletion lib/transports/websocket/hybi-16.js
Expand Up @@ -159,6 +159,7 @@ WebSocket.prototype.verifyOrigin = function (origin) {
if (origin) {
try {
var parts = url.parse(origin);
parts.port = parts.port || 80;
var ok =
~origins.indexOf(parts.hostname + ':' + parts.port) ||
~origins.indexOf(parts.hostname + ':*') ||
Expand Down Expand Up @@ -505,7 +506,10 @@ Parser.prototype.expect = function(what, length, handler) {
*/

Parser.prototype.processPacket = function (data) {
if ((data[0] & 0x70) != 0) this.error('reserved fields must be empty');
if ((data[0] & 0x70) != 0) {
this.error('reserved fields must be empty');
return;
}
this.state.lastFragment = (data[0] & 0x80) == 0x80;
this.state.masked = (data[1] & 0x80) == 0x80;
var opcode = data[0] & 0xf;
Expand Down
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -30,4 +30,7 @@
}
, "main": "index"
, "engines": { "node": ">= 0.4.0" }
, "scripts": {
"test": "make test"
}
}
2 changes: 1 addition & 1 deletion test/common.js
Expand Up @@ -227,7 +227,7 @@ function WSClient (port, sid, transport) {
this.transportName = transport || 'websocket';
WebSocket.call(
this
, 'ws://localhost:' + port + '/socket.io/'
, 'ws://localhost:' + port + '/socket.io/'
+ io.protocol + '/' + this.transportName + '/' + sid
);
};
Expand Down
8 changes: 4 additions & 4 deletions test/hybi-common.js
Expand Up @@ -43,16 +43,16 @@ mask = function(buf, maskString) {
if (typeof buf == 'string') buf = new Buffer(buf);
var mask = getBufferFromHexString(maskString || '34 83 a8 68');
for (var i = 0; i < buf.length; ++i) {
buf[i] ^= mask[i % 4];
buf[i] ^= mask[i % 4];
}
return buf;
}

/**
* Returns a hex string representing the length of a message
*/
getHybiLengthAsHexString = function(len, masked) {

getHybiLengthAsHexString = function(len, masked) {
if (len < 126) {
var buf = new Buffer(1);
buf[0] = (masked ? 0x80 : 0) | len;
Expand Down Expand Up @@ -94,6 +94,6 @@ pack = function(length, number) {
* Left pads the string 's' to a total length of 'n' with char 'c'.
*/

padl = function(s, n, c) {
padl = function(s, n, c) {
return new Array(1 + n - s.length).join(c) + s;
}
17 changes: 17 additions & 0 deletions test/manager.test.js
Expand Up @@ -277,6 +277,23 @@ module.exports = {
});
},

'test that a referer with implicit port 80 is accepted for foo.bar.com:80 origin': function (done) {
var port = ++ports
, io = sio.listen(port)
, cl = client(port);

io.configure(function () {
io.set('origins', 'foo.bar.com:80');
});

cl.get('/socket.io/{protocol}', { headers: { referer: 'http://foo.bar.com/something' } }, function (res, data) {
res.statusCode.should.eql(200);
cl.end();
io.server.close();
done();
});
},

'test that erroneous referer is denied for addr:* origin': function (done) {
var port = ++ports
, io = sio.listen(port)
Expand Down
2 changes: 1 addition & 1 deletion test/static.test.js
Expand Up @@ -94,7 +94,7 @@ module.exports = {

'test that the client is build with the enabled transports': function (done) {
var port = ++ports
, io = sio.listen(port)
, io = sio.listen(port)
, cl = client(port);

io.set('transports', ['websocket']);
Expand Down
2 changes: 1 addition & 1 deletion test/stores.memory.test.js
Expand Up @@ -45,7 +45,7 @@ module.exports = {

client.set('b', 'c', function (err) {
should.strictEqual(err, null);

client.set('c', 'd', function (err) {
should.strictEqual(err, null);

Expand Down
2 changes: 1 addition & 1 deletion test/stores.redis.test.js
Expand Up @@ -95,7 +95,7 @@ module.exports = {

client.set('b', 'c', function (err) {
should.strictEqual(err, null);

client.set('c', 'd', function (err) {
should.strictEqual(err, null);

Expand Down
2 changes: 1 addition & 1 deletion test/transports.flashsocket.test.js
Expand Up @@ -30,7 +30,7 @@ function FlashSocket (port, sid) {

WebSocket.call(
this
, 'ws://localhost:' + port + '/socket.io/'
, 'ws://localhost:' + port + '/socket.io/'
+ sio.protocol + '/flashsocket/' + sid
);
};
Expand Down

0 comments on commit 61e7e89

Please sign in to comment.