supertest icon indicating copy to clipboard operation
supertest copied to clipboard

[fix] SuperTest agents not sending cookies for Localhost domain cookies, you must set them to 127.0.0.1

Open yevon opened this issue 11 months ago • 2 comments

I'm unable to have the agent to automatically send my cookies to my requests after a successful login. What I don't undersand is that if try to set the cookies manually reading them from the agent itself it just works, but if i just remove the .set("Cookie") it stops working immediately. In my node express application, the very first thing I do is to setup cookieParser. It seems similar to the provided example on agents and cookies. The cookies are set as insecure already. Does the httpOnly flag of the cookies affect to this?

const app: Express = express();
app.use(cookieParser());
const response: Response = await myAgent.post("/post")
   .field("description", "This is a test post.")
   .field("price", "100")
   .set(
     "Cookie",
     myAgent.jar.getCookies({
         domain: "localhost",
         path: "/",
         secure: false,
         script: false,
       })
       .at(0)!
       .toString()
   )
   .redirects(5);

yevon avatar Nov 10 '24 10:11 yevon