Sha256: 9794b47e0ea10b91d7fad5e159c5e36f35a02f44de8453d83a6e2ee67fc6d8fa

Contents?: true

Size: 1.51 KB

Versions: 5

Compression:

Stored size: 1.51 KB

Contents

'use strict';
var common = require('../common');
var assert = require('assert');

if (!common.hasCrypto) {
  common.skip('missing crypto');
  return;
}
var tls = require('tls');

var stream = require('stream');
var fs = require('fs');
var net = require('net');

var connected = {
  client: 0,
  server: 0
};

var server = tls.createServer({
  key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
  cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
}, function(c) {
  console.log('new client');
  connected.server++;
  c.end('ohai');
}).listen(0, function() {
  var raw = net.connect(this.address().port);

  var pending = false;
  raw.on('readable', function() {
    if (pending)
      p._read();
  });

  var p = new stream.Duplex({
    read: function read() {
      pending = false;

      var chunk = raw.read();
      if (chunk) {
        console.log('read', chunk);
        this.push(chunk);
      } else {
        pending = true;
      }
    },
    write: function write(data, enc, cb) {
      console.log('write', data, enc);
      raw.write(data, enc, cb);
    }
  });

  var socket = tls.connect({
    socket: p,
    rejectUnauthorized: false
  }, function() {
    console.log('client secure');

    connected.client++;

    socket.end('hello');
    socket.resume();
    socket.destroy();
  });

  socket.once('close', function() {
    console.log('client close');
    server.close();
  });
});

process.once('exit', function() {
  assert.equal(connected.client, 1);
  assert.equal(connected.server, 1);
});

Version data entries

5 entries across 4 versions & 1 rubygems

Version Path
node-compiler-0.9.1 vendor/node/test/parallel/test-tls-js-stream.js
node-compiler-0.9.0 vendor/node-v7.2.1/test/parallel/test-tls-js-stream.js
node-compiler-0.8.0 vendor/node-v7.2.0/test/parallel/test-tls-js-stream.js
node-compiler-0.7.0 vendor/node-v6.9.1/test/parallel/test-tls-js-stream.js
node-compiler-0.7.0 vendor/node-v7.1.0/test/parallel/test-tls-js-stream.js