artillery icon indicating copy to clipboard operation
artillery copied to clipboard

Dynamic extraHeaders

Open moeabdol opened this issue 6 years ago • 5 comments

Let me start by saying this is an awesome tool to load test your web app. I have a question with regards to load testing a socket.io backend. I pass information as JWT to the socket.io server in a custom header called x-webauth-user

config:
  target: "http://192.168.99.100:80"
  phases:
    - duration: 600
      arrivalRate: 5
  socketio:
    transportOptions:
      polling:
        extraHeaders:
          x-webauth-user: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJyaWRlcl9pZCI6MX0.LEzEhepLPL755w4oJhKUYx8YlioBPeo0awPQ0mBgFhg"

scenarios:
  - engine: "socketio"
    flow:
      - emit:
          namespace: "/riders"
          channel: "riderOnline"
          data: "{{ $randomString() }}"
      - think: 10

Is there a way to dynamically loop over x-webauth-user and provide a new token with each iteration. Thanks.

moeabdol avatar Aug 28 '18 11:08 moeabdol

I have a code change that might help here. I have setup my .yml file to do the following

config:
    target: "wss://location/ws"
    phases:
      - duration: 20
        arrivalRate: 1
    payload:
      path: "users.csv"
      fields:
        - "userId"
        - "token"
    ws:
       headers:
        Sec-WebSocket-Protocol: my-protocol
        Authorization: "{{ userId }}.{{ token }}"
scenarios:
  - engine: "ws"
    flow:
      - send: "{{ userId }}"
      - think: 200
      - send: "world"

Today this doesn't work because there is a race condition w/ running template over the config script in the runner.js file. I have a change for engine_util.js that basically makes it where it will just leave template variables alone if it can't find a sane replacement. This allows the race condition to resolve it self so this will work.

In renderVariables() When finding replacements move on without replacing for undefined values

  var startIndex = 0
  while (result.substr(startIndex, result.length).search(RX) > -1) {
    let templateStr = result.match(RX)[0];
    const varName = templateStr.replace(/{/g, '').replace(/}/g, '').trim();

    let varValue = L.get(vars, varName);

    if (typeof varValue === 'object') {
      varValue = JSON.stringify(varValue);
    }
    if (varValue !== undefined) {
      result = result.replace(templateStr, varValue);
    } else {
      startIndex += templateStr.length
    }
  }

tpavs avatar Sep 27 '18 20:09 tpavs

I am interested in the same feature. I am trying to use websockets to test the performance of my AWS IoT authorizer. I have one post http request to get the token and the other one to try to connect with websockets in my flow. Something like this:

config:
  target: "wss://someid-ats.iot.us-east-1.amazonaws.com"
  phases:
    - duration: 60
      arrivalRate: 5
    - duration: 120
      arrivalRate: 5
    - duration: 600
      arrivalRate: 50
  payload:
    path: "devices.csv"
    fields:
      - "oauthClient"
      - "oauthSecret"
      - "username"
      - "password"
scenarios:
  - name: "Sign in and conect"
    engine: "ws"
    flow:
      - post:
          url: "https://authorize.com"
          headers:
            content-type: "application/x-www-form-urlencoded"
          auth:
            user: "{{ oauthClient }}"
            pass: "{{ oauthSecret }}"
          body: "username={{ username }}&password={{ password }}"
          capture:
            - json: "$.token"
              as: "token"
            - json: "$.token_signature"
              as: "tokenSignature"
        - ws: 
            headers:
              Sec-WebSocket-Protocol: "mqtt"
              x-amz-customauthorizer-signature: "{{ tokenSignature }}"
              x-amz-customauthorizer-name: "MyAuthorizer"
              token: "{{ token }}"

jammymalina avatar Jul 16 '19 11:07 jammymalina

I am in the same spot. I need to be able to make a GET request and change a cookie value between subsequent socket.io connections. Even if I could have a static set of cookie values that I iterate through that would also work for the time being.

Arkh1 avatar Jul 25 '19 19:07 Arkh1

@Arkh1 did you end up finding a workaround to this issue?

ChrisKatsaras avatar Dec 15 '20 23:12 ChrisKatsaras

Same problem with dynamic query

yahyalrq avatar Jan 07 '24 02:01 yahyalrq