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_ci 141cb0ef41Sopenharmony_ciconst server = tls.createServer({}) 151cb0ef41Sopenharmony_ci .listen(0, function() { 161cb0ef41Sopenharmony_ci const c = net.connect({ port: this.address().port }, function() { 171cb0ef41Sopenharmony_ci c.write(bonkers); 181cb0ef41Sopenharmony_ci }); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci }).on('tlsClientError', 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 server.close(); 291cb0ef41Sopenharmony_ci })); 30