Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookie jar feature #112

Open
josepmarixg opened this issue Jan 19, 2022 · 2 comments
Open

Cookie jar feature #112

josepmarixg opened this issue Jan 19, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@josepmarixg
Copy link

Is your feature request related to a problem? Please describe.
If you want to reuse the cookies from a previous request (or across multiple ones), you need to extract the cookies manually from the "set-cookie" from the first request (and from any request that might add a new cookie), and send it along with every subsequent request.

Describe the solution you'd like
It would be nice to be able to do something like:

const cookieJar = require('pactum').cookieJar();

await pactum.spec().get('/...').withCookieJar(cookieJar).expect(...);
await pactum.spec().post('/...').withCookieJar(cookieJar).expect(...);
await pactum.spec().post('/...').withCookieJar(cookieJar).expect(...);

cookieJar should also have some utility methods to getCookie/setCookie.

Maybe it also could be done automatically with a new setting pactum.request.setUseCookieJar(true); that will make all requests made in the same test to use the same cookie jar. Not sure if it's even possible, but it would be nice :) You could override it for a specific request sending a new cookie jar, for instance.

Thanks! I hope it's not too much asking 🙏

@ASaiAnudeep ASaiAnudeep added the enhancement New feature or request label Jan 20, 2022
@chrisrichard chrisrichard mentioned this issue Apr 4, 2022
@tnypxl
Copy link

tnypxl commented Apr 12, 2022

Should probably close this issue?

@chrisrichard
Copy link

For user-facing APIs it's typical to keep authentication tokens hidden inside the application and issue an "opaque" cookie to represent the session to the user agent upon successful sign-in. In this case it's really nice to have a built-in way to store the cookie(s) and automatically send the right ones on subsequent requests, as a cookie-supporting HTTP user agent would do.

Would be willing to work on a PR for this if you can provide a bit of guidance on how to integrate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

4 participants