question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

need example for socket.io with JWT

See original GitHub issue

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"

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
n3pscommented, Feb 27, 2017

PR submitted 😃

2reactions
kukomancommented, Jul 26, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Authenticating socket io connections using JWT - Stack Overflow
This module makes the authentication much easier in both client and server side. Just check out their examples. client const {token} = ...
Read more >
socketio-jwt - npm
Intro. Authenticate socket.io incoming connections with JWTs. This is useful if you are building a single page application and you are not ...
Read more >
Thream/socketio-jwt: Authenticate socket.io incoming ... - GitHub
Authenticate socket.io incoming connections with JWTs. Compatible with socket.io >= 3.0.0 . This repository was originally forked from auth0-socketio-jwt ...
Read more >
Middlewares - Socket.IO
A middleware function is a function that gets executed for every incoming connection.
Read more >
Usage of Passport JWT Strategy for Authentication in Socket.IO
JWT is an open standard that is based on signed JSON objects. In case of a successful login, the backend or an authorization...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found