I'm doing cookie session management with express with something like this:
req.session.authentication = auth;
And I verify the authenticated urls with something like
if(!req.session.authentication){res.send(401);}
Now I'm building tests for the URLs with mocha, superagent and should, however I can't seem to find a way to get/set the cookie with superagent. I even tried to request the login before the authenticated test but it is not working,
I have tried adding the request to the login in the before statement for the mocha BDD suite, however it is still telling me that the request is unauthorized, I have tested the authentication doing the requests from the browser, however it is not working from the suite any ideas why?
Super Agent helps you pick which cookies you want and which cookies you don't want. It doesn't store your data by default, informs you of any action taken, and warns you whenever it finds a website not respecting your preferences.
SuperAgent is light-weight progressive ajax API crafted for flexibility, readability, and a low learning curve after being frustrated with many of the existing request APIs. It also works with Node. js!
Use superagent.agent()
(instead of plain old superagent
) to make requests have persistent cookies. See 'Preserving cookies' in the superagent docs, or the code examples: agency.js, controller.test.js.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With