[test] Refined tests to begin checking Origin == Sec-Websocket-Origin

This commit is contained in:
indexzero 2011-05-17 20:25:45 -04:00
parent 6e679c8019
commit 9ab54ab47f

View File

@ -52,11 +52,12 @@ vows.describe('node-http-proxy/websocket').addBatch({
var that = this; var that = this;
runner.startTargetServer(8130, 'hello websocket', function (err, target) { runner.startTargetServer(8130, 'hello websocket', function (err, target) {
var socket = io.listen(target); var socket = io.listen(target),
headers = {};
socket.on('connection', function (client) { socket.on('connection', function (client) {
client.on('message', function (msg) { client.on('message', function (msg) {
that.callback(null, msg); that.callback(null, msg, headers);
}); });
}); });
@ -65,12 +66,12 @@ vows.describe('node-http-proxy/websocket').addBatch({
// Setup the web socket against our proxy // Setup the web socket against our proxy
// //
var ws = new websocket.WebSocket('ws://localhost:8131/socket.io/websocket/', 'borf', { var ws = new websocket.WebSocket('ws://localhost:8131/socket.io/websocket/', 'borf', {
origin: 'localhost' origin: 'http://localhost'
}); });
ws.on('wsupgrade', function (req, res) { ws.on('wsupgrade', function (req, res) {
require('eyes').inspect(req); headers.request = req;
require('eyes').inspect(res.headers); headers.response = res.headers;
}); });
ws.on('open', function () { ws.on('open', function () {
@ -79,8 +80,9 @@ vows.describe('node-http-proxy/websocket').addBatch({
}); });
}); });
}, },
"the target server should receive the message": function (err, msg) { "the target server should receive the message": function (err, msg, headers) {
assert.equal(msg, 'from client'); assert.equal(msg, 'from client');
require('eyes').inspect(headers);
} }
}, },
"when an outbound message is sent from the target server": { "when an outbound message is sent from the target server": {
@ -88,7 +90,8 @@ vows.describe('node-http-proxy/websocket').addBatch({
var that = this; var that = this;
runner.startTargetServer(8132, 'hello websocket', function (err, target) { runner.startTargetServer(8132, 'hello websocket', function (err, target) {
var socket = io.listen(target); var socket = io.listen(target),
headers = {};
socket.on('connection', function (client) { socket.on('connection', function (client) {
socket.broadcast('from server'); socket.broadcast('from server');
@ -99,26 +102,26 @@ vows.describe('node-http-proxy/websocket').addBatch({
// Setup the web socket against our proxy // Setup the web socket against our proxy
// //
var ws = new websocket.WebSocket('ws://localhost:8133/socket.io/websocket/', 'borf', { var ws = new websocket.WebSocket('ws://localhost:8133/socket.io/websocket/', 'borf', {
origin: 'localhost' origin: 'http://localhost'
}); });
ws.on('wsupgrade', function (req, res) { ws.on('wsupgrade', function (req, res) {
require('eyes').inspect(req); headers.request = req;
require('eyes').inspect(res.headers); headers.response = res.headers;
}); });
ws.on('message', function (msg) { ws.on('message', function (msg) {
msg = utils.decode(msg); msg = utils.decode(msg);
if (!/\d+/.test(msg)) { if (!/\d+/.test(msg)) {
that.callback(null, msg); that.callback(null, msg, headers);
} }
}); });
}); });
}); });
}, },
"the client should receive the message": function (err, msg) { "the client should receive the message": function (err, msg, headers) {
assert.equal(msg, 'from server'); assert.equal(msg, 'from server');
require('eyes').inspect(headers);
} }
} }
} }