0

I have a Node.js library that makes https.request (https://nodejs.org/api/https.html) calls to external sources.

In some cases, the user of the library may be behind a proxy. Due to configuration (or misconfiguration?) of the proxy, users behind the proxy may experience issues with SSL certificates. In this case, in order to make https requests in Node, you need to set the https.request option: rejectUnauthorized to be false. (on a related note, these proxies typically require npm --strict-ssl=false as well)

How can I setup a test that simulates being behind a proxy that rejects signed certificates so that I can ensure that my library will work properly for those behind proxies such as these?

I'm using mocha and/or chai as the testing library and nock to simulate external sources that are being called.

Jake Wilson
  • 88,616
  • 93
  • 252
  • 370

1 Answers1

0

I would wrap the request in a function in a module so that it can be mocked to have the behaviour that you want.

I believe this answer is a good example.

Community
  • 1
  • 1