1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6const assert = require('assert'); 7const http2 = require('http2'); 8const net = require('net'); 9 10const server = http2.createServer(); 11server.on('stream', common.mustCall((stream) => { 12 stream.respond(); 13 stream.end('ok'); 14})); 15 16server.listen(0, common.mustCall(() => { 17 const client = http2.connect(`http://localhost:${server.address().port}`); 18 const socket = client.socket; 19 const req = client.request(); 20 req.resume(); 21 req.on('close', common.mustCall(() => { 22 client.close(); 23 server.close(); 24 25 // Tests to make sure accessing the socket proxy fails with an 26 // informative error. 27 setImmediate(common.mustCall(() => { 28 assert.throws(() => { 29 socket.example; // eslint-disable-line no-unused-expressions 30 }, { 31 code: 'ERR_HTTP2_SOCKET_UNBOUND' 32 }); 33 assert.throws(() => { 34 socket.example = 1; 35 }, { 36 code: 'ERR_HTTP2_SOCKET_UNBOUND' 37 }); 38 assert.throws(() => { 39 // eslint-disable-next-line no-unused-expressions 40 socket instanceof net.Socket; 41 }, { 42 code: 'ERR_HTTP2_SOCKET_UNBOUND' 43 }); 44 })); 45 })); 46})); 47