![](/img/trans.png)
[英]NodeJS HTTPS API testing with mocha and super test -“DEPTH_ZERO_SELF_SIGNED_CERT”
[英]NodeJS HTTPS API testing with mocha and super test -“CERT_HAS_EXPIRED”
我需要使用mocha
和super test
來測試通過HTTPS
服務的API
這是服務器的要點:
...
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
});
這是要測試的路線
app.get('/hello',function (req, res) {
res.json(200);
});
我正在嘗試在test/test.js
使用此代碼進行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();
}
});
});
});
但是測試FAILs
並出現以下錯誤:
Error: CERT_HAS_EXPIRED
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)
盡管使用普通HTTP
該測試PASSING
您是否已按面值提取了錯誤消息? 您用於測試的證書是否已過期? 機器上的時鍾是否關閉? 還要注意,TLS證書與主機名關聯,並且如果您想做任何有用的事情,則主機名通常不是“ localhost”。 假設這不是證書過期的明顯錯誤,請在連接到服務器時嘗試使用正確的主機名。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.