artilleryio / artillery

The complete load testing platform. Everything you need for production-grade load tests. Serverless & distributed. Load test with Playwright. Load test HTTP APIs, GraphQL, WebSocket, and more. Use any Node.js module.
https://www.artillery.io
Mozilla Public License 2.0
8.04k stars 511 forks source link

You must set an arbitrary default cookie value in order to use the cookieJar to set a cookie #1035

Closed Shazwazza closed 2 years ago

Shazwazza commented 3 years ago

With the latest 1.7.x version the cookie jar (which is a ToughCookie instance) will not work unless it is specifically enabled. This means that if you have any JS that assigns a cookie to the request it will not work unless a previous response had a cookie, or your config has an explicit cookie defined. This is different than the prev 1.6.x version.

It's due to this code here: https://github.com/artilleryio/artillery/blob/v1.6.x/core/lib/engine_http.js#L262

To work around this you need to set a default cookie value, even if it's empty so the cookieJar is enabled. You can do this at top level of your config like:

config:
  defaults:
    cookie:
      MY_COOKIE: ""

or at request levels, etc...

If you do this, then the cookieJar is enabled which is this code: https://github.com/artilleryio/artillery/blob/v1.6.x/core/lib/engine_http.js#L653

There's another work around, which is to forcefully enable it in the beginRequest method like:

if (!context._enableCookieJar) {
    context._enableCookieJar = true;
    requestParams.cookieJar = context._jar;
}

I think it may be clearer be able to explicitly enable this in config, something like

config:
  defaults:
    cookieJar: "always"

and perhaps you could have "auto" or even "never" (not sure why you'd want that, but maybe). Could be some other options like that but is a bit more clear that you just want to be able to dynamically set cookies in a request without having to declare an empty cookie.

Shazwazza commented 3 years ago

(I also mostly wanted to report this in case other people are searching work arounds for this)

hassy commented 3 years ago

Thank you for opening the issue @Shazwazza and for taking the time to investigate the cause! We can treat this as a regression - cookies should just work and be enabled by default.