• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6
7const tls = require('tls');
8const net = require('net');
9const assert = require('assert');
10
11const bonkers = Buffer.alloc(1024, 42);
12
13
14const server = tls.createServer({})
15  .listen(0, function() {
16    const c = net.connect({ port: this.address().port }, function() {
17      c.write(bonkers);
18    });
19
20  }).on('tlsClientError', common.mustCall(function(e) {
21    assert.ok(e instanceof Error,
22              'Instance of Error should be passed to error handler');
23    // OpenSSL 1.0.x and 1.1.x use different error codes for junk inputs.
24    assert.ok(
25      /SSL routines:[^:]*:(unknown protocol|wrong version number)/.test(
26        e.message),
27      'Expecting SSL unknown protocol');
28
29    server.close();
30  }));
31