|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +const assert = require('assert'); |
| 5 | +const crypto = require('crypto'); |
| 6 | +const dgram = require('dgram'); |
| 7 | +const dns = require('dns'); |
| 8 | +const fs = require('fs'); |
| 9 | +const net = require('net'); |
| 10 | +const tls = require('tls'); |
| 11 | +const zlib = require('zlib'); |
| 12 | +const ChildProcess = require('child_process').ChildProcess; |
| 13 | +const StreamWrap = require('_stream_wrap').StreamWrap; |
| 14 | +const async_wrap = process.binding('async_wrap'); |
| 15 | +const pkeys = Object.keys(async_wrap.Providers); |
| 16 | + |
| 17 | +let keyList = pkeys.slice(); |
| 18 | +// Drop NONE |
| 19 | +keyList.splice(0, 1); |
| 20 | + |
| 21 | + |
| 22 | +function init(id) { |
| 23 | + keyList = keyList.filter(e => e != pkeys[id]); |
| 24 | +} |
| 25 | + |
| 26 | +function noop() { } |
| 27 | + |
| 28 | +async_wrap.setupHooks(init, noop, noop); |
| 29 | + |
| 30 | +async_wrap.enable(); |
| 31 | + |
| 32 | + |
| 33 | +setTimeout(function() { }); |
| 34 | + |
| 35 | +fs.stat(__filename, noop); |
| 36 | +fs.watchFile(__filename, noop); |
| 37 | +fs.unwatchFile(__filename); |
| 38 | +fs.watch(__filename).close(); |
| 39 | + |
| 40 | +dns.lookup('localhost', noop); |
| 41 | +dns.lookupService('::', 0, noop); |
| 42 | +dns.resolve('localhost', noop); |
| 43 | + |
| 44 | +new StreamWrap(new net.Socket()); |
| 45 | + |
| 46 | +new (process.binding('tty_wrap').TTY)(); |
| 47 | + |
| 48 | +crypto.randomBytes(1, noop); |
| 49 | + |
| 50 | +try { |
| 51 | + fs.unlinkSync(common.PIPE); |
| 52 | +} catch(e) { } |
| 53 | + |
| 54 | +net.createServer(function(c) { |
| 55 | + c.end(); |
| 56 | + this.close(); |
| 57 | +}).listen(common.PIPE, function() { |
| 58 | + net.connect(common.PIPE, noop); |
| 59 | +}); |
| 60 | + |
| 61 | +net.createServer(function(c) { |
| 62 | + c.end(); |
| 63 | + this.close(checkTLS); |
| 64 | +}).listen(common.PORT, function() { |
| 65 | + net.connect(common.PORT, noop); |
| 66 | +}); |
| 67 | + |
| 68 | +dgram.createSocket('udp4').bind(common.PORT, function() { |
| 69 | + this.send(new Buffer(2), 0, 2, common.PORT, '::', () => { |
| 70 | + this.close(); |
| 71 | + }); |
| 72 | +}); |
| 73 | + |
| 74 | +process.on('SIGINT', () => process.exit()); |
| 75 | + |
| 76 | +// Run from closed net server above. |
| 77 | +function checkTLS() { |
| 78 | + let options = { |
| 79 | + key: fs.readFileSync(common.fixturesDir + '/keys/ec-key.pem'), |
| 80 | + cert: fs.readFileSync(common.fixturesDir + '/keys/ec-cert.pem') |
| 81 | + }; |
| 82 | + let server = tls.createServer(options, noop).listen(common.PORT, function() { |
| 83 | + tls.connect(common.PORT, { rejectUnauthorized: false }, function() { |
| 84 | + this.destroy(); |
| 85 | + server.close(); |
| 86 | + }); |
| 87 | + }); |
| 88 | +} |
| 89 | + |
| 90 | +zlib.createGzip(); |
| 91 | + |
| 92 | +new ChildProcess(); |
| 93 | + |
| 94 | +process.on('exit', function() { |
| 95 | + if (keyList.length !== 0) { |
| 96 | + process._rawDebug('Not all keys have been used:'); |
| 97 | + process._rawDebug(keyList); |
| 98 | + assert.equal(keyList.length, 0); |
| 99 | + } |
| 100 | +}); |
0 commit comments