I am writing unit test for middleware that relies on persistent sessions in a connection. (namely connect-mongo).
I would like to create a fake session, but cannot figure out how to do this.
I have a connect.sid cookie in my browser that I believe correlates with _id in my session collection in some encrypted form.
Here is what I tried:
I added cookieParser and session storage to the server in the middleware, and then used the following request to send it to the server (I copied the key from the chrome dev toolbar):
var jar = request.jar(),
cookie = request.cookie('connect.sid=<REALLYLONGKEY>');
jar.add(cookie);
request({url : 'http://localhost:8585/',jar : jar},this.callback);
which set the cookie correctly on the server side, and I checked that the sessions are working.
However, the magic conversion from cookie to session did not happen, as I had hoped - what is the right way to do this?
source
share