4

I'm testing my NodeJS application with supertest. My application is asking for a certificate, with the CN of the certificate my user gets authorized against the application.

While testing my first route, I got an error complaining about my self signed certificate.

I wonder if there is a way to set a valid or invalid certificate while testing my routes?

user1772306
  • 449
  • 1
  • 7
  • 20

1 Answers1

13

On Node.js, TLS and HTTPS will validate certificates before accepting them. Therefore, to use self-signed certificates with Node, you will need to set the rejectUnauthorized option when performing requests to false, or use:

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

Here's an old pull request that pertains to this problem.

hexacyanide
  • 88,222
  • 31
  • 159
  • 162
  • If doing this for lot of tests, I recommend adding `NODE_TLS_REJECT_UNAUTHORIZED=0` in the makefile, so it will be set for all tests. Something like `NODE_ENV=test NODE_TLS_REJECT_UNAUTHORIZED=0 ./node_modules/.bin/mocha --recursive --timeout 5000 --reporter spec "./**/modules/*/test/**/*.js"` – Diosney Jan 12 '16 at 14:55