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
7.9k stars 502 forks source link

Cookies not getting replayed from function #652

Open saranjaga opened 5 years ago

saranjaga commented 5 years ago

Rather than having login inside the flow I've invoked from the custom java script but the cookies does not replay as required. If i set them in the user context variable and use it in the subsequent methods in the flow, at times they are not setting as required and my post log in services throws back with 401.

When i mention the log in the flow as part of the scenario, there are no problems at all and all the services works perfectly fine as expected but couldnt understand the behaviour when the log in extracted in to a function. Is there a way to replay the cookies in the flow in this scenario?

@hassy, any insights on this will be really helpful.

hassy commented 5 years ago

how are you setting the cookie in your custom JS code?

saranjaga commented 5 years ago

In JS inside function login

context.vars.sessionid = get the cookie from log in response headers

In yml

Cookie: SESSIONID: "{{sessionid}};Domain=.*****.com; Path=/; Secure; HttpOnly"

This is how we update the cookie for the post log in services

sureshkrishnaselvam commented 5 years ago

@hassy We have are executing login from custom js and tried calling from function as well as from before request. But we are getting 401 error response for few api calls. Could you please provide some solution for this.

Login from before request:

scenarios:

Login from function:

scenarios:

hassy commented 5 years ago

@sureshkrishnaselvam can you try setting just the value of the cookie, i.e.:

name: 'XXXXXX'
flow:
  - function: "getLoginData"
  - get:
    name: "xxxxxxxxx"
    beforeRequest: "recordStartTime"
    url: "/svc/profiles/{{pfId}}/loyalty/(RewardsInfo)"
    cookie:
      JSESSIONID: "{{jsessionId}}"
    afterResponse: "reportLatency"
sureshkrishnaselvam commented 5 years ago

@hassy thanks for the solution but that way also not working.

hassy commented 5 years ago

Can you provide more information to try to isolate where the issue might be? Can you confirm that the jsessionId variable is being set properly, by logging it for example? Does it look like it's being set to an expected value? Do you see 401s for all requests or only some of them? If only some of them, do you have access to the application's logs to see what the inbound request headers look like?

saranjaga commented 5 years ago

@hassy, yes we have logged in and made sure that the cookie value is set correctly. I logged the whole request in before request method to confirm the same. Only partial requests in the initial stage succeed and remaining all requests ends up in failure. Am trying to check the request headers in the application and i'll let you know on the same.

If I mention the same log in service in the flow, I just do not have any problems at all.

Clement-TS commented 5 years ago

duplicate of #539 ?