1
0
Fork 0
forked from svrjs/svrjs
This repository has been archived on 2024-11-10. You can view files and clone it, but cannot push or open issues or pull requests.
svrjs/node_modules/ocsp/test/cache-test.js

77 lines
1.7 KiB
JavaScript
Raw Normal View History

2023-07-29 20:33:28 +02:00
var ocsp = require('../');
var fixtures = require('./fixtures');
var assert = require('assert');
var https = require('https');
describe('OCSP Cache', function() {
var issuer = fixtures.certs.issuer;
var good = fixtures.certs.good;
var revoked = fixtures.certs.revoked;
var server;
var agent;
beforeEach(function(cb) {
server = ocsp.Server.create({
cert: issuer.cert,
key: issuer.key
});
server.addCert(43, 'good');
server.addCert(44, 'revoked', {
revocationTime: new Date(),
revocationReason: 'CACompromise'
});
server.listen(8000, function() {
cb();
});
agent = new ocsp.Agent();
cache = new ocsp.Cache();
});
afterEach(function(cb) {
server.close(cb);
agent = null;
});
it('should cache ocsp response', function(cb) {
var httpServer = https.createServer({
cert: good.cert + '\n' + good.issuer,
key: good.key
}, function(req, res) {
res.end('hello world');
});
httpServer.on('OCSPRequest', function(cert, issuer, cb) {
ocsp.getOCSPURI(cert, function(err, uri) {
if (err)
return cb(err);
var req = ocsp.request.generate(cert,
issuer || fixtures.certs.issuer.cert);
var options = {
url: uri,
ocsp: req.data
};
cache.request(req.id, options, cb);
});
});
httpServer.listen(8001, function() {
https.get({
agent: agent,
ca: issuer.cert,
rejectUnauthorized: !/^v0.12/.test(process.version),
servername: 'local.host',
port: 8001
}, function(res) {
cb();
});
});
});
});