Can we test/assert for ECONNRESET?

My question: A service we are testing should not accept requests with TLS 1.0 or 1.1 and it behaves correctly denying those connections.

When send a request via postman and force it to use TLS 1.0 (or TLS1.1), what’s returned by postman is
image

Console shows: Error: read ECONNRESET
is there an way to detect & test for this as the expected? so the test would pass.

2 Likes

Hey @spn2016,

You’ll have to do a workaround here. Postman will not execute tests if it can’t get a network response from the URL.

One workaround is to actually send the request in a pm.sendRequest() call in a pre-request script. Then you can check for an ECONNRESET error and set a variable with the result. This is essentially moving the test execution to the pre-request script. We still want the assertion in the Tests section of the request, which is why we’re setting a variable with the result. We can assert on that result in the Tests section.

Example below.

pre-request script:

// Store the original URL.
const subjectURL = pm.request.url.toString();

// Set the URL to one that will execute successfully.
pm.request.url = 'https://postman-echo.com/delay/0';

// Set up a variable that we'll test in the Tests section.
const variableName = `does${pm.info.requestId}Fail`;
pm.variables.set(variableName, false);

// Set request options.
const options = {
  method: pm.request.method,
  url: subjectURL
};

// Send the request using pm.sendRequest().
pm.sendRequest(options, (err, _res) => {
  // if the request fails, update our variable to true (success).
  if (err && err.errno == 'ECONNREFUSED') {
    pm.variables.set(variableName, true);
  }
});

test script:

pm.test('does request fail on TLS 1.0', () => {
  // fetch the variable set in the pre-rquest script.
  const variableName = `does${pm.info.requestId}Fail`;
  const subject = pm.variables.get(variableName);

  // assert that the request failed with ECONNRESET.
  pm.expect(subject).to.be.true;
});

Hope that helps!
2 Likes