11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciif (!common.hasCrypto) 41cb0ef41Sopenharmony_ci common.skip('missing crypto'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 71cb0ef41Sopenharmony_ciconst makeDuplexPair = require('../common/duplexpair'); 81cb0ef41Sopenharmony_ciconst assert = require('assert'); 91cb0ef41Sopenharmony_ciconst { TLSSocket, connect } = require('tls'); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst key = fixtures.readKey('agent1-key.pem'); 121cb0ef41Sopenharmony_ciconst cert = fixtures.readKey('agent1-cert.pem'); 131cb0ef41Sopenharmony_ciconst ca = fixtures.readKey('ca1-cert.pem'); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciconst { clientSide, serverSide } = makeDuplexPair(); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciconst clientTLS = connect({ 181cb0ef41Sopenharmony_ci socket: clientSide, 191cb0ef41Sopenharmony_ci ca, 201cb0ef41Sopenharmony_ci host: 'agent1' // Hostname from certificate 211cb0ef41Sopenharmony_ci}); 221cb0ef41Sopenharmony_ciconst serverTLS = new TLSSocket(serverSide, { 231cb0ef41Sopenharmony_ci isServer: true, 241cb0ef41Sopenharmony_ci key, 251cb0ef41Sopenharmony_ci cert, 261cb0ef41Sopenharmony_ci ca 271cb0ef41Sopenharmony_ci}); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ciassert.strictEqual(clientTLS.connecting, false); 301cb0ef41Sopenharmony_ciassert.strictEqual(serverTLS.connecting, false); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ciclientTLS.on('secureConnect', common.mustCall(() => { 331cb0ef41Sopenharmony_ci clientTLS.write('foobar', common.mustCall(() => { 341cb0ef41Sopenharmony_ci assert.strictEqual(serverTLS.read().toString(), 'foobar'); 351cb0ef41Sopenharmony_ci assert.strictEqual(clientTLS._handle.writeQueueSize, 0); 361cb0ef41Sopenharmony_ci })); 371cb0ef41Sopenharmony_ci assert.ok(clientTLS._handle.writeQueueSize > 0); 381cb0ef41Sopenharmony_ci})); 39