• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4
5if (!common.hasCrypto)
6  common.skip('missing crypto');
7
8const https = require('https');
9const fixtures = require('../common/fixtures');
10
11const options = {
12  key: fixtures.readKey('agent1-key.pem'),
13  cert: fixtures.readKey('agent1-cert.pem'),
14  ca: fixtures.readKey('ca1-cert.pem')
15};
16
17
18const server = https.Server(options, (req, res) => {
19  res.writeHead(200);
20  res.end('hello world\n');
21});
22
23
24server.listen(0, function() {
25  https.get({
26    path: '/',
27    port: this.address().port,
28    rejectUnauthorized: true,
29    servername: 'agent1',
30    ca: options.ca
31  }, (res) => {
32    res.resume();
33    assert.strictEqual(res.statusCode, 200);
34    server.close();
35  }).on('error', (e) => {
36    console.log(e.message);
37    process.exit(1);
38  });
39});
40