mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[tests] make the tests run with the last refactor
This commit is contained in:
parent
275a5192fa
commit
5bb83b967e
@ -1,4 +1,4 @@
|
||||
var caronte = require('../lib/caronte/passes/web'),
|
||||
var caronte = require('../lib/caronte/passes/web-incoming'),
|
||||
expect = require('expect.js');
|
||||
|
||||
describe('lib/caronte/passes/web.js', function() {
|
||||
|
||||
@ -1,87 +1,145 @@
|
||||
var caronte = require('../lib/caronte/passes/ws'),
|
||||
var caronte = require('../lib/caronte/passes/ws-incoming'),
|
||||
expect = require('expect.js');
|
||||
|
||||
describe('lib/caronte/passes/ws.js', function () {
|
||||
describe('lib/caronte/passes/ws-incoming.js', function () {
|
||||
describe('#checkMethodAndHeader', function () {
|
||||
it('should drop non-GET connections', function () {
|
||||
var endCalled = false,
|
||||
var destroyCalled = false,
|
||||
stubRequest = {
|
||||
method: 'DELETE',
|
||||
headers: {},
|
||||
end: function () {
|
||||
// Simulate Stream.end() method when call
|
||||
endCalled = true;
|
||||
}
|
||||
headers: {}
|
||||
},
|
||||
returnValue = caronte.checkMethodAndHeader(stubRequest, {}, {});
|
||||
stubSocket = {
|
||||
destroy: function () {
|
||||
// Simulate Socket.destroy() method when call
|
||||
destroyCalled = true;
|
||||
}
|
||||
}
|
||||
returnValue = caronte.checkMethodAndHeader(stubRequest, stubSocket);
|
||||
expect(returnValue).to.be(true);
|
||||
expect(endCalled).to.be(true);
|
||||
expect(destroyCalled).to.be(true);
|
||||
})
|
||||
|
||||
it('should drop connections when no upgrade header', function () {
|
||||
var endCalled = false,
|
||||
var destroyCalled = false,
|
||||
stubRequest = {
|
||||
method: 'GET',
|
||||
headers: {},
|
||||
end: function () {
|
||||
// Simulate Stream.end() method when call
|
||||
endCalled = true;
|
||||
}
|
||||
headers: {}
|
||||
},
|
||||
returnValue = caronte.checkMethodAndHeader(stubRequest, {}, {});
|
||||
stubSocket = {
|
||||
destroy: function () {
|
||||
// Simulate Socket.destroy() method when call
|
||||
destroyCalled = true;
|
||||
}
|
||||
}
|
||||
returnValue = caronte.checkMethodAndHeader(stubRequest, stubSocket);
|
||||
expect(returnValue).to.be(true);
|
||||
expect(endCalled).to.be(true);
|
||||
expect(destroyCalled).to.be(true);
|
||||
})
|
||||
|
||||
it('should drop connections when upgrade header is different of `websocket`', function () {
|
||||
var endCalled = false,
|
||||
var destroyCalled = false,
|
||||
stubRequest = {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
upgrade: 'anotherprotocol'
|
||||
},
|
||||
end: function () {
|
||||
// Simulate Stream.end() method when call
|
||||
endCalled = true;
|
||||
}
|
||||
},
|
||||
returnValue = caronte.checkMethodAndHeader(stubRequest, {}, {});
|
||||
stubSocket = {
|
||||
destroy: function () {
|
||||
// Simulate Socket.destroy() method when call
|
||||
destroyCalled = true;
|
||||
}
|
||||
}
|
||||
returnValue = caronte.checkMethodAndHeader(stubRequest, stubSocket);
|
||||
expect(returnValue).to.be(true);
|
||||
expect(endCalled).to.be(true);
|
||||
expect(destroyCalled).to.be(true);
|
||||
})
|
||||
|
||||
it('should return nothing when all is ok', function () {
|
||||
var endCalled = false,
|
||||
var destroyCalled = false,
|
||||
stubRequest = {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
upgrade: 'websocket'
|
||||
},
|
||||
end: function () {
|
||||
// Simulate Stream.end() method when call
|
||||
endCalled = true;
|
||||
}
|
||||
},
|
||||
returnValue = caronte.checkMethodAndHeader(stubRequest, {}, {});
|
||||
stubSocket = {
|
||||
destroy: function () {
|
||||
// Simulate Socket.destroy() method when call
|
||||
destroyCalled = true;
|
||||
}
|
||||
}
|
||||
returnValue = caronte.checkMethodAndHeader(stubRequest, stubSocket);
|
||||
expect(returnValue).to.be(undefined);
|
||||
expect(endCalled).to.be(false);
|
||||
expect(destroyCalled).to.be(false);
|
||||
})
|
||||
});
|
||||
|
||||
describe('#XHeaders', function () {
|
||||
// var stubRequest = {
|
||||
// connection: {
|
||||
// remoteAddress: '192.168.1.2',
|
||||
// remotePort: '8080'
|
||||
// },
|
||||
// headers: {}
|
||||
// }
|
||||
describe('#setupSocket', function () {
|
||||
it('Set the correct config to the socket', function () {
|
||||
var stubSocket = {
|
||||
setTimeout: function (num) {
|
||||
// Simulate Socket.setTimeout()
|
||||
socketConfig.timeout = num;
|
||||
},
|
||||
setNoDelay: function (bol) {
|
||||
// Simulate Socket.setNoDelay()
|
||||
socketConfig.nodelay = bol;
|
||||
},
|
||||
setKeepAlive: function (bol) {
|
||||
// Simulate Socket.setKeepAlive()
|
||||
socketConfig.keepalive = bol;
|
||||
}
|
||||
},
|
||||
socketConfig = {
|
||||
timeout: null,
|
||||
nodelay: false,
|
||||
keepalive: false
|
||||
},
|
||||
returnValue = caronte.setupSocket({}, stubSocket);
|
||||
expect(returnValue).to.be(undefined);
|
||||
expect(socketConfig.timeout).to.eql(0);
|
||||
expect(socketConfig.nodelay).to.eql(true);
|
||||
expect(socketConfig.keepalive).to.eql(true);
|
||||
});
|
||||
});
|
||||
|
||||
// it('set the correct x-forwarded-* headers', function () {
|
||||
// caronte.XHeaders(stubRequest, {}, { xfwd: true });
|
||||
// expect(stubRequest.headers['x-forwarded-for']).to.be('192.168.1.2');
|
||||
// expect(stubRequest.headers['x-forwarded-port']).to.be('8080');
|
||||
// expect(stubRequest.headers['x-forwarded-proto']).to.be('http');
|
||||
// });
|
||||
describe('#XHeaders', function () {
|
||||
it('return if no forward request', function () {
|
||||
var returnValue = caronte.XHeaders({}, {}, {});
|
||||
expect(returnValue).to.be(undefined);
|
||||
});
|
||||
|
||||
it('set the correct x-forwarded-* headers from req.connection', function () {
|
||||
var stubRequest = {
|
||||
connection: {
|
||||
remoteAddress: '192.168.1.2',
|
||||
remotePort: '8080'
|
||||
},
|
||||
headers: {}
|
||||
}
|
||||
caronte.XHeaders(stubRequest, {}, { xfwd: true });
|
||||
expect(stubRequest.headers['x-forwarded-for']).to.be('192.168.1.2');
|
||||
expect(stubRequest.headers['x-forwarded-port']).to.be('8080');
|
||||
expect(stubRequest.headers['x-forwarded-proto']).to.be('ws');
|
||||
});
|
||||
|
||||
it('set the correct x-forwarded-* headers from req.socket', function () {
|
||||
var stubRequest = {
|
||||
socket: {
|
||||
remoteAddress: '192.168.1.3',
|
||||
remotePort: '8181'
|
||||
},
|
||||
connection: {
|
||||
pair: true
|
||||
},
|
||||
headers: {}
|
||||
};
|
||||
caronte.XHeaders(stubRequest, {}, { xfwd: true });
|
||||
expect(stubRequest.headers['x-forwarded-for']).to.be('192.168.1.3');
|
||||
expect(stubRequest.headers['x-forwarded-port']).to.be('8181');
|
||||
expect(stubRequest.headers['x-forwarded-proto']).to.be('wss');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user