Skip to content

Commit 9ab54ab

Browse files
committed
[test] Refined tests to begin checking Origin == Sec-Websocket-Origin
1 parent 6e679c8 commit 9ab54ab

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

test/web-socket-proxy-test.js

+16-13
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ vows.describe('node-http-proxy/websocket').addBatch({
5252
var that = this;
5353

5454
runner.startTargetServer(8130, 'hello websocket', function (err, target) {
55-
var socket = io.listen(target);
55+
var socket = io.listen(target),
56+
headers = {};
5657

5758
socket.on('connection', function (client) {
5859
client.on('message', function (msg) {
59-
that.callback(null, msg);
60+
that.callback(null, msg, headers);
6061
});
6162
});
6263

@@ -65,12 +66,12 @@ vows.describe('node-http-proxy/websocket').addBatch({
6566
// Setup the web socket against our proxy
6667
//
6768
var ws = new websocket.WebSocket('ws://localhost:8131/socket.io/websocket/', 'borf', {
68-
origin: 'localhost'
69+
origin: 'http://localhost'
6970
});
7071

7172
ws.on('wsupgrade', function (req, res) {
72-
require('eyes').inspect(req);
73-
require('eyes').inspect(res.headers);
73+
headers.request = req;
74+
headers.response = res.headers;
7475
});
7576

7677
ws.on('open', function () {
@@ -79,16 +80,18 @@ vows.describe('node-http-proxy/websocket').addBatch({
7980
});
8081
});
8182
},
82-
"the target server should receive the message": function (err, msg) {
83+
"the target server should receive the message": function (err, msg, headers) {
8384
assert.equal(msg, 'from client');
85+
require('eyes').inspect(headers);
8486
}
8587
},
8688
"when an outbound message is sent from the target server": {
8789
topic: function () {
8890
var that = this;
8991

9092
runner.startTargetServer(8132, 'hello websocket', function (err, target) {
91-
var socket = io.listen(target);
93+
var socket = io.listen(target),
94+
headers = {};
9295

9396
socket.on('connection', function (client) {
9497
socket.broadcast('from server');
@@ -99,26 +102,26 @@ vows.describe('node-http-proxy/websocket').addBatch({
99102
// Setup the web socket against our proxy
100103
//
101104
var ws = new websocket.WebSocket('ws://localhost:8133/socket.io/websocket/', 'borf', {
102-
origin: 'localhost'
105+
origin: 'http://localhost'
103106
});
104107

105108
ws.on('wsupgrade', function (req, res) {
106-
require('eyes').inspect(req);
107-
require('eyes').inspect(res.headers);
109+
headers.request = req;
110+
headers.response = res.headers;
108111
});
109112

110-
111113
ws.on('message', function (msg) {
112114
msg = utils.decode(msg);
113115
if (!/\d+/.test(msg)) {
114-
that.callback(null, msg);
116+
that.callback(null, msg, headers);
115117
}
116118
});
117119
});
118120
});
119121
},
120-
"the client should receive the message": function (err, msg) {
122+
"the client should receive the message": function (err, msg, headers) {
121123
assert.equal(msg, 'from server');
124+
require('eyes').inspect(headers);
122125
}
123126
}
124127
}

0 commit comments

Comments
 (0)