1'use strict';
2
3const common = require('../common');
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6
7// Regression tests for https://github.com/nodejs/node/issues/40693
8
9const assert = require('assert');
10const fixtures = require('../common/fixtures');
11const tls = require('tls');
12const { AsyncLocalStorage } = require('async_hooks');
13
14const options = {
15  cert: fixtures.readKey('rsa_cert.crt'),
16  key: fixtures.readKey('rsa_private.pem'),
17  rejectUnauthorized: false,
18};
19
20tls
21  .createServer(options, (socket) => {
22    socket.write('Hello, world!');
23    socket.pipe(socket);
24  })
25  .listen(0, function() {
26    const asyncLocalStorage = new AsyncLocalStorage();
27    const store = { val: 'abcd' };
28    asyncLocalStorage.run(store, () => {
29      const client = tls.connect({ port: this.address().port, ...options });
30      client.on('data', () => {
31        assert.deepStrictEqual(asyncLocalStorage.getStore(), store);
32        client.end();
33        this.close();
34      });
35    });
36  });
37