nightwatchjs / nightwatch-plugin-apitesting

Run API tests in Nightwatch using supertest
https://nightwatchjs.org
MIT License
2 stars 8 forks source link

Seems to hide insecure certificate exceptions/helpful errors? #3

Open literallyMello opened 1 year ago

literallyMello commented 1 year ago

When testing internal APIs with insecure/untrusted certificates I was getting error

  ✖ NightwatchAssertError
   Cannot read properties of undefined (reading 'status')

when running a test similar to

await supertest
      .request("https://internal-insecurely-signed-app.url.int")
      .get("/_manage/health")
      .expect(200);

until I thought to try using the .disableTLSCerts() option (the API under test int his scenario does not use a securely-signed certificate)

await supertest
      .request("https://internal-insecurely-signed-app.url.int")
      .get("/_manage/health")
      .disableTLSCerts()
      .expect(200);

Unless I'm mistaken I recall SuperTest providing an error in these scenarios that would more easily let the user realize it didn't connect because of an insecure certificate. Is the plugin hiding the exception?

beatfactor commented 1 year ago

No, but what does the superset. disableTLSCerts() do?

reallymello commented 1 year ago

It stops supertest from checking the validity of the certificates so we you are using self-signed for local dev or hitting environments with otherwise non-legit certificates (like test environments). Without it supertest throws errors like Error: self signed certificate (see for example https://github.com/ladjs/supertest/issues/737)

beatfactor commented 1 year ago

Ok, so the issue is that those errors aren't reported correctly, like the assertion error you mentioned? Can you post a stack trace?

reallymello commented 1 year ago
  Running Example Test:

───────────────────────────────────────────────────────────────────────────────────────────────────

→ Running [beforeEach]:

→ Completed [beforeEach].

 → Running command: request ('https://redactedUrlHere')

  Error

   uncaughtException: Cannot read properties of undefined (reading 'request')

TypeError: Cannot read properties of undefined (reading 'request')

    at Test.<anonymous> (/Users/davidme/projects/nightwatch-framework-template-ts/node_modules/@nightwatch/apitesting/nightwatch/commands/supertest/request.js:33:71)

    at Test.assert (/Users/davidme/projects/nightwatch-framework-template-ts/node_modules/supertest/lib/test.js:172:8)

    at localAssert (/Users/davidme/projects/nightwatch-framework-template-ts/node_modules/supertest/lib/test.js:120:14)

    at fn (/Users/davidme/projects/nightwatch-framework-template-ts/node_modules/supertest/lib/test.js:125:7)

    at Test.callback (/Users/davidme/projects/nightwatch-framework-template-ts/node_modules/superagent/src/node/index.js:924:3)

    at ClientRequest.<anonymous> (/Users/davidme/projects/nightwatch-framework-template-ts/node_modules/superagent/src/node/index.js:836:10)

    at ClientRequest.emit (node:events:513:28)

    at ClientRequest.emit (node:domain:489:12)

    at TLSSocket.socketErrorListener (node:_http_client:481:9)

    at TLSSocket.emit (node:events:513:28)

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

  ️TEST FAILURE (5.891s):

   - 1 error during execution;

   - 0 tests failed;

   - 0/NA tests passed