11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciif (!common.hasCrypto)
61cb0ef41Sopenharmony_ci  common.skip('missing crypto');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst https = require('https');
91cb0ef41Sopenharmony_ciconst assert = require('assert');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ci{
121cb0ef41Sopenharmony_ci  const server = https.createServer({
131cb0ef41Sopenharmony_ci    cert: fixtures.readKey('agent1-cert.pem'),
141cb0ef41Sopenharmony_ci    key: fixtures.readKey('agent1-key.pem'),
151cb0ef41Sopenharmony_ci  }, common.mustCall((req, res) => {
161cb0ef41Sopenharmony_ci    server.close();
171cb0ef41Sopenharmony_ci    res.end();
181cb0ef41Sopenharmony_ci  }));
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci  server.listen(0, '127.0.0.1', common.mustCall(() => {
211cb0ef41Sopenharmony_ci    const port = server.address().port;
221cb0ef41Sopenharmony_ci    const req = https.get({
231cb0ef41Sopenharmony_ci      host: 'localhost',
241cb0ef41Sopenharmony_ci      pathname: '/',
251cb0ef41Sopenharmony_ci      port,
261cb0ef41Sopenharmony_ci      family: 4,
271cb0ef41Sopenharmony_ci      localPort: common.PORT,
281cb0ef41Sopenharmony_ci      rejectUnauthorized: false,
291cb0ef41Sopenharmony_ci    }, common.mustCall(() => {
301cb0ef41Sopenharmony_ci      assert.strictEqual(req.socket.localPort, common.PORT);
311cb0ef41Sopenharmony_ci      assert.strictEqual(req.socket.remotePort, port);
321cb0ef41Sopenharmony_ci    }));
331cb0ef41Sopenharmony_ci  }));
341cb0ef41Sopenharmony_ci}
35