supertest icon indicating copy to clipboard operation
supertest copied to clipboard

Self signed certificate issue

Open FedeFressiel opened this issue 3 years ago • 1 comments

Hello everyone and thank you for reading. I'm testing an API (Internal) that calls another API (external), and processes the results. When I test methods that don't use the external, everything is fine. When I call it via postman, the problematic method it works perfectly. But, when I call it via SuperTest I get

Error: self signed certificate
        at TLSSocket.onConnectSecure (_tls_wrap.js:1514:34)
        at TLSSocket.emit (events.js:400:28)
        at TLSSocket._finishInit (_tls_wrap.js:936:8)
        at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:708:12) {
      code: 'DEPTH_ZERO_SELF_SIGNED_CERT',

I've tried setting process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; and

"jest": {
    "testEnvironment": "node"
  }

without success.

Any ideas? I don't know what to do next.

Thank you all again.

FedeFressiel avatar Aug 25 '21 15:08 FedeFressiel

Hi, old issue, but for me it works using trustLocalhost for request("https://localhost"), e.g.:

describe("GET /", function(){
    it("gets index", function(){
        return req
        .get('/')
        .trustLocalhost(true)
        .expect('Content-Type', /html/)
        .expect(200);
    });
});

node: v16.7.0 supertest: v6.3.1 mocha: v10.1.0

andre5s avatar Dec 02 '22 15:12 andre5s