Artillery: need example for socket.io with JWT

Created on 19 Jan 2017  路  10Comments  路  Source: artilleryio/artillery

Hi

I am trying to use artillery to test my socket.io server under
artillery 1.5.0-22 and socket.io 1.4.5

I auth the user with JWT while connecting. Connecting with socket.io client looks like

io.connect('https://mywebsite', {
'query': 'token=' + the JWT,
'transports': ['websocket']
});

and the url looks like
wss://mywebsite/socket.io/?token=the JWT&transport=websocket

I tried to write similar script as the socket.io example, but I have no idea where should I insert the token.
Also, it seems when running this test none of the request actually hit the server.(I will have log if someone is trying to connect without a token or incorrect signature) If this approach is possible with artillery please kindly provide me a short example.

Thanks very much~

 config:
  target: "https://mywebsite/"
  phases:
    -
      duration: 10
      arrivalRate: 1

scenarios:
  -
    engine: "socketio"
    flow:
      -
        emit:
          channel: "room:join"
          data:
            id: "6ec82266-de6f-11e6-bf01-fe55135034f3"
socketio enhancement good-first-pr

Most helpful comment

PR submitted :)

All 10 comments

@lethe0690 This isn't possible at the moment.

We just merged a PR which allows for transports to be configurable:

https://github.com/shoreditch-ops/artillery-core/pull/143

To allow for query to be customised we'll need to either introduce an explicit connect command to the Socket.io engine or another way to specify the query for a virtual user.

@hassy Any chance we can make query configurable in the same manner as transport?

@n3ps that's the plan, though there's no ETA on that (PRs always welcome though!)

PR submitted :)

Link to the PR https://github.com/shoreditch-ops/artillery-core/pull/170

Modified example from the first post with a query param:

 config:
  target: "https://mywebsite/"
  phases:
    -
      duration: 10
      arrivalRate: 1
  socketio:
    query:
      token: "the JWT"

scenarios:
  -
    engine: "socketio"
    flow:
      -
        emit:
          channel: "room:join"
          data:
            id: "6ec82266-de6f-11e6-bf01-fe55135034f3"

Hi Guys,

Do you have some example when JWT is used with Authentication header as Bearer [token]?

I'm sending a POST request to http://localhost:8081/auth
body: {"username":"xxx", "password": "xxx"}
response:
{"token": "xxx..."}

and now I would like to use the token for a second POST request:
http://localhost:8081/transaction
headers:
Authorization: Bearer [token]
Content-Type: application/json

many thanks :)

If you're using the HTTP engine (though the OP is using sockets) then this sounds like an excellent candidate for the capture functionality. An example could like the the following:

post:
  url: /auth
  body:  '{"username":"xxx", "password": "xxx"}'
  capture:
    json: '$.token'
    as: token
get:
  url: /transaction
  headers:
    Authorization: Bearer {{ token }}
    Content-Type: application/json

thank you very much, really appreciate it :)

Hi Guys,

The following is my full config that I came up with after your comment:

config:
  target: 'http://localhost:8081'
  phases:
    - duration: 100
      arrivalRate: 10
  defaults:
    headers:
      Content-Type: application/json

scenarios:
  - flow:
    - get:
        url: /health
        headers:
          Content-Type: application/json
    - post:
        url: /auth
        body:  '{"username":"asdf", "password": "asdf"}'
        headers:
          Content-Type: application/json
        capture:
          json: '$.token'
          as: token
    - post:
        url: /transaction
        body:  '{"...."}'
        headers:
          Authorization: Bearer {{ token }}
          Content-Type: application/json

but now it starts 10x get, 10x first post and 10x second post. Is there a way how to iterate the scenario one by one in sequence? (not 10 x first + 10 x second + 10 x third, but 10 x (first + second + third))

Thank you

@kukoman would you mind taking general questions to our Gitter chatroom please? This isn't really the right place for it.

As to your question, Artillery is already doing exactly what you're saying you want it to do. Each virtual user will run the requests in the scenario one after another, but since you will have many virtual users running concurrently, you will see concurrent requests to /health for example.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kennethlynne picture kennethlynne  路  5Comments

mrchief picture mrchief  路  3Comments

NivLipetz picture NivLipetz  路  5Comments

endrureza picture endrureza  路  5Comments

ericmacfarland picture ericmacfarland  路  6Comments