node-mitm icon indicating copy to clipboard operation
node-mitm copied to clipboard

feat: add ability to reject connection with ECONNREFUSED

Open viglucci opened this issue 4 years ago • 1 comments

Addresses #72

For context -- I am looking to use this functionality in the tests for rsocket-js.

Usage example:

it("rejects if the connection errors", async () => {
  // arrange
  mitm.on("connect", function (socket) {
    socket.reject();
  });

  const expectedError = new Error();
  expectedError.address = "127.0.0.1";
  expectedError.code = "ECONNREFUSED";
  expectedError.errno = -4078;
  expectedError.port = 9090;
  expectedError.syscall = "connect";

  // act
  const transport = new TcpClientTransport({
    connectionOptions: {
      host: "localhost",
      port: 9090,
    },
  });

  // assert
  await expect(transport.connect()).rejects.toEqual(expectedError);
});

viglucci avatar Aug 02 '21 05:08 viglucci

This would be really great to test edge cases. This happens in real life and it is hard to test it.

vkruoso avatar Nov 30 '21 20:11 vkruoso