moll / node-mitm

Intercept and mock outgoing Node.js network TCP connections and HTTP requests for testing. Intercepts and gives you a Net.Socket, Http.IncomingMessage and Http.ServerResponse to test and respond with. Super useful when testing code that hits remote servers.
Other
636 stars 48 forks source link

Simulate socket error/close #6

Closed abelnation closed 9 years ago

abelnation commented 9 years ago

Is there a way to simulate a socket error, or socket close using mitm?

Thanks

moll commented 9 years ago

Hey,

Hmm. I think you might be able to do that in a few ways. First you could close the socket given to the socket event on your Mitm instance with regular Socket functions (socket.end, socket.close etc). As for error, the connect event is given the client side socket. You could try either throwing from that handler or emitting error on that client side socket.

Let me know if these work. Cheers.

abelnation commented 9 years ago

I figured out this issue. I assumed the object returned by mitm() was the socket, but you have to set the socket from the onConnect callback param

moll commented 9 years ago

Yeah, for every intercepted connection Mitm gives you a new socket. ;-)

Feel free to ask further or close the issue once you get it all working. :)