I'm working in a Node.js project where we use passport for authentication. To bridge the authentication to socket.io/engine.io instead we use passport.socketio package. This works great in the browser as the available cookies are sent in the initial socket.io/engine.io handshake that is done via HTTP.
When we try write tests with mocha for the socket API how ever by first logging in via passport HTTP call with the module request we cannot find a way to pass the received session cookie along with the socket.io-client (that uses engine.io-client) initial connection. Hence we cannot find a way to write these tests in mocha.
Is there a way to set additional headers to be sent in the handshake or to share a cookie jar between the request and socket connection or is there another solution to this?
(there is an outdated "hack" solution but it is not working any more jfromaniello/passport.socketio#72)
xmlhttprequestand monkey-patches it, adding custom cookies. It works if only it is exactly the samexmlhttprequestas is used by the socket.io, and socket.io has changed dramatically since then, so it's not so trivial to make it work now. - Dmitry Frank