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.
 

83 lines
1.4 KiB

'use strict';
var test = require('tap').test;
var pem = require('pem');
var got = require('../');
var server = require('./server.js');
var s;
var key;
var cert;
var caRootKey;
var caRootCert;
test('root pem', function (t) {
pem.createCertificate({
days: 1,
selfSigned: true
}, function (err, keys) {
caRootKey = keys.serviceKey;
caRootCert = keys.certificate;
t.end();
});
});
test('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();
});
});
test('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();
});
});
test('make request to https server', function (t) {
got('https://google.com', {
strictSSL: true
}, function (err, data) {
t.error(err);
t.ok(data);
t.end();
});
});
test('make request to https server with ca', 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();
});
});
test('cleanup', function (t) {
s.close();
t.end();
});