Extracting Cookies from a request

288 views
Skip to first unread message

James Wade

unread,
Sep 9, 2021, 10:51:58 AM9/9/21
to codename-taurus
Hi there,

I'm trying to extract the XSRF-TOKEN from the cookies and use it as a variable, is that possible with Taurus?

For example, on each request, I get a response that looks like this:

XSRF-TOKEN=eyJpdiI6Im94UURqMUphbUN6Nmo1WlIrblBDVGc9PSIsInZhbHVlIjoiVEJxbTJLVVRnZitmWUlXLzdlRGpCSnRjcTB6cDB0cXRWU3Nrd3hOeitqbWRuK0dyNFdTOEZhalh6T1owaGxiKy9LN2NBbkNiOFdnd3Nkb081VTlTOFV5bEZqTjFaSkdWV1JJMHVlRjBwNUE0M24yVE5wamdRU1hyYkZXdE8vaUMiLCJtYWMiOiI0NDAxNGNmZmI5NTZmZjdjOTg5YzBlZGZjOTZkYTdmZTVmMjZlMjk1ZGM1ZjBjYWMzM2NiMjZlMjhhY2RhYTg1In0=; expires=Thu, 09-Sep-2021 16:50:42 GMT; Max-Age=7200; path=/; domain=.example.com

Similar to how you can do extract-regexp, for subject of url or whatever, can you extract from cookies?

For example:

            -   url: '/agent/dashboard'
                extract-regexp:
                    xsrf_token:
                        default: NO_XSRF_TOKEN_FOUND
                        match-no: 1
                        regexp: 'XSRF-TOKEN: (.+?)'
                        template: $1$
                        subject: cookie

Is something like this possible?

Thanks.

grey....@gmail.com

unread,
Sep 11, 2021, 3:17:18 AM9/11/21
to codename-taurus
Hello.
It looks like something written based on our examples, it's impossible to guess it by intuition).
If you checked our doc, ability to do that with taurus is obvious. 
So your question is little bit vague. Could you explain it?

---
Taras

DT

unread,
Sep 12, 2021, 5:19:37 AM9/12/21
to codename-taurus
Where did you get this "cookie" subject from? According to Taurus documentation:

Possible subjects for regexp are:

  • body
  • headers
  • http-code
  • url
Cookies are basically HTTP Headers, from the server to the client it's Set-Cookie and from the client to the server it's Cookie so you need to change the "subject" to "headers"

I also don't think your regular expression is correct, most probably it should be something like XSRF-TOKEN=(.+?);

And last but not the least you can add a JMeter property instructing JMeter to store cookie values into JMeter Variables, something like:

modules:
  jmeter:
    properties:
       CookieManager.save.cookies : true

and once done you will be able to refer the extracted cookie value as ${COOKIE_XSRF-TOKEN} where required, see HTTP Cookie Manager Advanced Usage - A Guide article for more information. 
Reply all
Reply to author
Forward
0 new messages