AnWeber / httpyac

Command Line Interface for *.http and *.rest files. Connect with http, gRPC, WebSocket and MQTT
https://httpyac.github.io/
MIT License
433 stars 38 forks source link

Websocket tests do not fail properly on 401/403 errors #816

Closed chris-lindstrom closed 3 weeks ago

chris-lindstrom commented 3 weeks ago

I have some websocket tests and I noticed that when I set the AAD token such that I get either 401 or 403 responses from the server (as opposed to 101 upgrade) - the tests don't run properly. When I run locally - the test will time out after 2 minutes. When I run in the docker image - it returns after 2 minutes but does not report any error ($? = 0)

I found code in the ws module (websocket.js) req.on('response') line 884: https://github.com/websockets/ws/blob/master/lib/websocket.js if I hacked up the code to abortHandshake on 401 - this worked more like I expected.

I can see that 401 responses go into unexpected-response - and httpyac has code registering this - but I got lost somewhere in the emit DispatchEvent. https://github.com/AnWeber/httpyac/blob/main/src/models/requestClient.ts#L80

I feel like I probably should be able to add a hook for this - but haven't had any luck figuring out where to put my hook so far.

AnWeber commented 3 weeks ago

@chris-lindstrom unexpected-response is only used in the meta-data case. These were events that sound interesting to me and might be helpful. However, I would currently expect to get an explicit error event. But unfortunately websocket only seems to execute the abortHandshake if I don't have a handler for unexpected-response. I remove the event listener