|
| 1 | +// Flags: --no-warnings |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +const common = require('../common'); |
| 5 | + |
| 6 | +if (!common.hasQuic) |
| 7 | + common.skip('missing quic'); |
| 8 | + |
| 9 | +const { createQuicSocket, BlockList } = require('net'); |
| 10 | +const assert = require('assert'); |
| 11 | + |
| 12 | +const { key, cert, ca } = require('../common/quic'); |
| 13 | +const { once } = require('events'); |
| 14 | + |
| 15 | +const idleTimeout = common.platformTimeout(1); |
| 16 | +const options = { key, cert, ca, alpn: 'zzz', idleTimeout }; |
| 17 | + |
| 18 | +const client = createQuicSocket({ client: options }); |
| 19 | +const server = createQuicSocket({ server: options }); |
| 20 | + |
| 21 | +assert(client.blockList instanceof BlockList); |
| 22 | +assert(server.blockList instanceof BlockList); |
| 23 | + |
| 24 | +client.blockList.addAddress('10.0.0.1'); |
| 25 | + |
| 26 | +assert(client.blockList.check('10.0.0.1')); |
| 27 | + |
| 28 | +// Connection fails because the IP address is blocked |
| 29 | +assert.rejects(client.connect({ address: '10.0.0.1' }), { |
| 30 | + code: 'ERR_OPERATION_FAILED' |
| 31 | +}).then(common.mustCall()); |
| 32 | + |
| 33 | +server.blockList.addAddress('127.0.0.1'); |
| 34 | + |
| 35 | +(async () => { |
| 36 | + server.on('session', common.mustNotCall()); |
| 37 | + |
| 38 | + await server.listen(); |
| 39 | + |
| 40 | + const session = await client.connect({ |
| 41 | + address: common.localhostIPv4, |
| 42 | + port: server.endpoints[0].address.port, |
| 43 | + idleTimeout, |
| 44 | + }); |
| 45 | + |
| 46 | + session.on('secure', common.mustNotCall()); |
| 47 | + |
| 48 | + await once(session, 'close'); |
| 49 | + |
| 50 | + await Promise.all([server.close(), client.close()]); |
| 51 | + |
| 52 | +})().then(common.mustCall()); |
0 commit comments