You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.2 KiB

'use strict';
var tape = require('tape');
var got = require('../');
var server = require('./server.js');
var pem = require('pem');
var s, key, cert, caRootKey, caRootCert;
tape('root pem', function (t) {
pem.createCertificate({days:1, selfSigned:true}, function (err, keys) {
caRootKey = keys.serviceKey;
caRootCert = keys.certificate;
t.end();
});
});
tape('pem', function (t) {
pem.createCertificate({
serviceCertificate: caRootCert,
serviceKey: caRootKey,
serial: Date.now(),
days: 500,
country: '',
state: '',
locality: '',
organization: '',
organizationUnit: '',
commonName: 'sindresorhus.com'
}, function (err, keys) {
key = keys.clientKey;
cert = keys.certificate;
t.end();
});
});
tape('setup', function (t) {
s = server.createSSLServer(server.portSSL + 1, {
key: key,
cert: cert
});
s.on('/', function (req, res) {
res.end('ok');
});
s.listen(s.port, function () {
t.end();
});
});
tape('make request to https server', function (t) {
got(s.url, {
strictSSL: true,
ca: caRootCert,
headers: { host: 'sindresorhus.com' }
}, function (err, data) {
t.error(err);
t.equal(data, 'ok');
t.end();
});
});
tape('cleanup', function (t) {
s.close();
t.end();
});