I am writing test cases for a rest API written in NodeJS. I am using supertest and mocha for writing tests. The endpoints that do not check for session i.e. don't require authentication are working fine when I try to hit them using supertest in my test files.
But I am facing issue when I try to hit those endpoints that require the request to be authenticated (which I think means that there should be a valid sessionid set in the request cookies).
I followed this tutorial to make my request object authenticated. This works fine in that I get proper response when I try to hit the login endpoint.
But even now, when I use this authenticated request to hit those endpoints which require user to be logged in, I am getting 401 unauthorized
error. On checking server side, I found the request object still doesn't have any cookies attached to it, though the tutorial I followed says that cookies should be automatically set.
I have tried withCredentials
also, but still I get the same issue. Thanks in advance for your help.
Aucun commentaire:
Enregistrer un commentaire