Skip to content

Commit 6e679c8

Browse files
committed
[test] Improve websocket tests to inspect outgoing and incoming HTTP headers to test origin mismatch bugs
1 parent 360e79a commit 6e679c8

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

test/web-socket-proxy-test.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,14 @@ vows.describe('node-http-proxy/websocket').addBatch({
6464
//
6565
// Setup the web socket against our proxy
6666
//
67-
var ws = new websocket.WebSocket('ws://localhost:8131/socket.io/websocket/', 'borf');
67+
var ws = new websocket.WebSocket('ws://localhost:8131/socket.io/websocket/', 'borf', {
68+
origin: 'localhost'
69+
});
70+
71+
ws.on('wsupgrade', function (req, res) {
72+
require('eyes').inspect(req);
73+
require('eyes').inspect(res.headers);
74+
});
6875

6976
ws.on('open', function () {
7077
ws.send(utils.encode('from client'));
@@ -91,7 +98,15 @@ vows.describe('node-http-proxy/websocket').addBatch({
9198
//
9299
// Setup the web socket against our proxy
93100
//
94-
var ws = new websocket.WebSocket('ws://localhost:8133/socket.io/websocket/', 'borf');
101+
var ws = new websocket.WebSocket('ws://localhost:8133/socket.io/websocket/', 'borf', {
102+
origin: 'localhost'
103+
});
104+
105+
ws.on('wsupgrade', function (req, res) {
106+
require('eyes').inspect(req);
107+
require('eyes').inspect(res.headers);
108+
});
109+
95110

96111
ws.on('message', function (msg) {
97112
msg = utils.decode(msg);

vendor/websocket.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -523,14 +523,20 @@ var WebSocket = function(url, proto, opts) {
523523
httpClient.on('upgrade', (function() {
524524
var data = undefined;
525525

526-
return function(req, s, head) {
526+
return function(res, s, head) {
527527
stream = s;
528528

529+
//
530+
// Emit the `wsupgrade` event to inspect the raw
531+
// arguments returned from the websocket request.
532+
//
533+
self.emit('wsupgrade', httpHeaders, res, s, head);
534+
529535
stream.on('data', function(d) {
530536
if (d.length <= 0) {
531537
return;
532538
}
533-
539+
534540
if (!data) {
535541
data = d;
536542
} else {
@@ -614,7 +620,6 @@ var WebSocket = function(url, proto, opts) {
614620
});
615621

616622
var httpReq = httpClient.request(httpPath, httpHeaders);
617-
618623
httpReq.write(challenge, 'binary');
619624
httpReq.end();
620625
})();

0 commit comments

Comments
 (0)