11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciif (!common.hasCrypto)
51cb0ef41Sopenharmony_ci  common.skip('missing crypto');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst tls = require('tls');
81cb0ef41Sopenharmony_ciconst net = require('net');
91cb0ef41Sopenharmony_ciconst assert = require('assert');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst bonkers = Buffer.alloc(1024, 42);
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciconst server = net.createServer(function(c) {
141cb0ef41Sopenharmony_ci  setTimeout(function() {
151cb0ef41Sopenharmony_ci    const s = new tls.TLSSocket(c, {
161cb0ef41Sopenharmony_ci      isServer: true,
171cb0ef41Sopenharmony_ci      server: server
181cb0ef41Sopenharmony_ci    });
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci    s.on('error', common.mustCall(function(e) {
211cb0ef41Sopenharmony_ci      assert.ok(e instanceof Error,
221cb0ef41Sopenharmony_ci                'Instance of Error should be passed to error handler');
231cb0ef41Sopenharmony_ci      assert.ok(
241cb0ef41Sopenharmony_ci        /SSL routines:[^:]*:wrong version number/.test(
251cb0ef41Sopenharmony_ci          e.message),
261cb0ef41Sopenharmony_ci        'Expecting SSL unknown protocol');
271cb0ef41Sopenharmony_ci    }));
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci    s.on('close', function() {
301cb0ef41Sopenharmony_ci      server.close();
311cb0ef41Sopenharmony_ci      s.destroy();
321cb0ef41Sopenharmony_ci    });
331cb0ef41Sopenharmony_ci  }, common.platformTimeout(200));
341cb0ef41Sopenharmony_ci}).listen(0, function() {
351cb0ef41Sopenharmony_ci  const c = net.connect({ port: this.address().port }, function() {
361cb0ef41Sopenharmony_ci    c.write(bonkers);
371cb0ef41Sopenharmony_ci  });
381cb0ef41Sopenharmony_ci});
39