Last active
December 29, 2015 07:19
-
-
Save kapouer/7634923 to your computer and use it in GitHub Desktop.
GH-177 test cooking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('./common'); | |
var http = require('http'); | |
var server = http.createServer(); | |
server.listen(); | |
var engine = eio.attach(server, { | |
allowUpgrades: true, | |
transports: ['polling', 'websocket'], | |
pingInterval:4000, | |
pingTimeout: 8000 | |
}); | |
// disable websocket support | |
server.removeAllListeners('upgrade'); | |
var port = server.address().port; | |
engine.on('connection', function (conn) { | |
setTimeout(function() { | |
conn.send('success'); | |
}, 1000); | |
}); | |
var socket = new eioc.Socket('ws://localhost:%d'.s(port)); | |
socket.on('error', function(e) { | |
// fails before the fix | |
if (e.description) expect(e.description).to.not.be(400); | |
}); | |
socket.on('open', function () { | |
// make sure we get the message after the fix | |
socket.on('message', function (msg) { | |
expect(msg).to.be('success'); | |
done(); | |
}); | |
// squid, or nginx proxies remove Upgrade: websocket, Connection: Upgrade headers, | |
// transforming the ws request into http GET request. | |
// this emulates that bad behavior | |
var fakeProxyUrl = 'http://localhost:%d/engine.io/?EIO=2&transport=websocket&sid=%s' | |
.s(port, socket.id); | |
http.get(fakeProxyUrl); | |
}); |
Even if no race exists, be fair and listen messages before the fake GET.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This can be run in engine.io/test dir