postmanlabs / postman-app-support

Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs—faster.
https://www.postman.com
5.82k stars 839 forks source link

Cookies are not deleted programmatically via the pre-request/test script #10324

Open alxoldman opened 2 years ago

alxoldman commented 2 years ago

Is there an existing issue for this?

Describe the Issue

Cookies are not deleted programmatically via the pre-request/test script

Steps To Reproduce

  1. Import the collection that is attached to the ticket.
  2. On the "Manage cookies" module, whitelist acx-brillium-v2.auth.us-east-2.amazoncognito.com.
  3. On the "Manage cookies" screen, inspect cookies.

Expected result: since at the end of the test script we try to delete programmatically all cookies from acx-brillium-v2.auth.us-east-2.amazoncognito.com, and this domain is whitelisted, the Cookie Manager does not contain any cookie from this domain. Actual result: on the "Manage Cookies" screen, there are three cookies from acx-brillium-v2.auth.us-east-2.amazoncognito.com

If you add such string for cookie deletion to the pre-request script of the next request, nothing changes, the cookies are not removed anyway. Cookie_bug.postman_collection.zip

Screenshots or Videos

No response

Environment Information

- Operating System: Windows 10
- Platform Type: Native App
- Postman Version: Version 9.0.3

Additional Context?

The listing of the script:

var redirectLocation = pm.response.headers.get("Location");

const getToAmazon = {
    url: redirectLocation,
    method: "GET"
}
pm.sendRequest(getToAmazon, (error, response) => {
    if (error) {
        console.log(error);
    } else {
        pm.cookies.jar().clear("acx-brillium-v2.auth.us-east-2.amazoncognito.com");
    }
});
coditva commented 2 years ago

@alxoldman I was able to replicate this issue. Can you add "https://" to the cookies clear command and try if that fixes the issue?

pm.cookies.jar().clear("https://acx-brillium-v2.auth.us-east-2.amazoncognito.com");
alxoldman commented 2 years ago

Yep, it works for the attached collection. But it was only one request from the original huge collection, and I made sure that the full URL (with https://) was used there. And for the original collection, it still does not works.

alxoldman commented 2 years ago

Seems, something goes wrong with async actions. Because when I try to flush cookies inside in-line requests, everything works fine. But when the same code is, e.g., in Pre-request Script, the cookies are not flushed.

coditva commented 2 years ago

for the original collection, it still does not works.

@alxoldman Does this mean that adding https:// does not work for the entire collection? Or is it not possible to add https:// for each request in the collection?

Seems, something goes wrong with async actions. Because when I try to flush cookies inside in-line requests, everything works fine. But when the same code is, e.g., in Pre-request Script, the cookies are not flushed.

I'm not sure I understand. What do you mean by in-line requests? The "Manage Cookies" modal?