我正在尝试使用chai的Mocha测试一个简单的nodejs https请求。
Test.js
let chai = require('chai');
let chaiHttp = require('chai-http');
let server = require('../../server');
const fs = require('fs');
const key = fs.readFileSync(__dirname + '/key.pem');
const cert = fs.readFileSync(__dirname + '/key-cert.pem');
describe('/GET test route', () => {
it('it should GET test route', (done) => {
chai.request(server)
.get('/service/test')
.key(key)
.cert(cert)
.end((err, res) => {
console.log('Testtttttttttt ', res);
res.should.have.status(200);
done();
});
});
});
这将引发以下错误:
{ Error: write EPROTO 140735569253248:error:1408F10B:SSL
routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:252:
at WriteWrap.afterWrite (net.js:836:14)
errno: 'EPROTO',
code: 'EPROTO',
syscall: 'write',
response: undefined }
我已经尝试过按照here进行以下设置:
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
但是它不起作用。有什么方法可以禁用严格的SSL测试吗?或与此有关的任何帮助将非常有帮助。