NodeJS HTTPS API testing with mocha and super test - DEPTH ZERO SELF SIGNED CERT

0 votes

I need to use mocha and supertest to test an API that is provided over HTTPS (the certificate are not expired)

The following is a summary of the server:

...
var app = express();
var _options = {
    key: fs.readFileSync('my-key.pem');,
    cert: fs.readFileSync('my-cert.pem')
};

// Start HTTPS server
https.createServer(_options, app).listen(app.get('port'), app.get('ip'), function () {

 // ok or not logs

});

and this is the route to be tested

app.get('/hello',function (req, res) {
   res.json(200);
});

I'm trying to test with this code in test/test.js

    var supertest = require('supertest'),
        api = supertest('https://localhost:3000');

describe('Hello test', function () {

      it('hello', function (done) {

        api.get('/hello')
               .expect(200)
               .end(function (err, res) {
                                        if (err) {
                                                   done(err);
                                        } else {
                                                   done();
               }
         });
    });
});

but the test FAILs with the following error :

    enter Error: DEPTH_ZERO_SELF_SIGNED_CERT
  at SecurePair.<anonymous> (tls.js:1349:32)
  at SecurePair.EventEmitter.emit (events.js:92:17)
  at SecurePair.maybeInitFinished (tls.js:962:10)
  at CleartextStream.read [as _read] (tls.js:463:15)
  at CleartextStream.Readable.read (_stream_readable.js:320:10)
  at EncryptedStream.write [as _write] (tls.js:366:25)
  at doWrite (_stream_writable.js:219:10)
  at writeOrBuffer (_stream_writable.js:209:5)
  at EncryptedStream.Writable.write (_stream_writable.js:180:11)
  at write (_stream_readable.js:573:24)
  at flow (_stream_readable.js:582:7)
  at Socket.pipeOnReadable (_stream_readable.js:614:5)
  at Socket.EventEmitter.emit (events.js:92:17)
  at emitReadable_ (_stream_readable.js:408:10)
  at emitReadable (_stream_readable.js:404:5)
  at readableAddChunk (_stream_readable.js:165:9)
  at Socket.Readable.push (_stream_readable.js:127:10)
  at TCP.onread (net.js:526:21)

While using plain HTTP the test is PASSING

Jun 16, 2022 in Node-js by Vaani
• 7,070 points
1,058 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Node-js

0 votes
1 answer
0 votes
0 answers

How can i make my REST API Faster with nodejs and express?

Summarize the problem My problem: I have built ...READ MORE

Aug 19, 2022 in Node-js by Neha
• 9,020 points
798 views
0 votes
1 answer

How to host MEAN stack application with Angular and nodejs on windows IIS

It's fine that you're using Angular. Be ...READ MORE

answered May 27, 2022 in Node-js by Neha
• 9,020 points
1,338 views
0 votes
1 answer

Installing angularjs with NPM and NODEJS brings an error in ubuntu 16.04

Rename your angular folder to angular-test or ...READ MORE

answered May 30, 2022 in Node-js by Vaani
• 7,070 points
1,310 views
0 votes
1 answer

File Download on NodeJS with use opensubtitles API

The problem is the charset output (default ...READ MORE

answered Jun 7, 2022 in Node-js by Neha
• 9,020 points
992 views
0 votes
1 answer

Nodemailer with Gmail and NodeJS

I fixed it by going to the ...READ MORE

answered Jun 10, 2022 in Node-js by Neha
• 9,020 points
914 views
0 votes
1 answer

Presenting docket dtates inside html page by javascript

Use the Docker Engine Api:Docker Engine API ...READ MORE

answered Jun 20, 2018 in Docker by DareDev
• 6,890 points
729 views
0 votes
1 answer

Migrating proxy npm repo in nexus 3

I don't think you can achieve this ...READ MORE

answered Jun 22, 2018 in DevOps Tools by DareDev
• 6,890 points
1,518 views
+1 vote
1 answer

What is the difference between JavaScript and Java

This quote rightly explains that 2 totally ...READ MORE

answered Jun 29, 2018 in Java by Daisy
• 8,140 points
784 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP