|
| 1 | +// Flags: --permission --allow-fs-read=* --experimental-quic --no-warnings |
| 2 | +import { hasQuic, skip, mustNotCall } from '../common/index.mjs'; |
| 3 | +import assert from 'node:assert'; |
| 4 | +import { createPrivateKey } from 'node:crypto'; |
| 5 | +import * as fixtures from '../common/fixtures.mjs'; |
| 6 | + |
| 7 | +if (!hasQuic) { |
| 8 | + skip('QUIC is not enabled'); |
| 9 | +} |
| 10 | + |
| 11 | +const { connect, listen, QuicEndpoint } = await import('node:quic'); |
| 12 | + |
| 13 | +// Verify that the permission system correctly reports no net access. |
| 14 | +assert.ok(!process.permission.has('net')); |
| 15 | + |
| 16 | +const key = createPrivateKey(fixtures.readKey('agent1-key.pem')); |
| 17 | +const cert = fixtures.readKey('agent1-cert.pem'); |
| 18 | + |
| 19 | +// Test: connect() should reject with ERR_ACCESS_DENIED |
| 20 | +{ |
| 21 | + await assert.rejects( |
| 22 | + connect('127.0.0.1:12345', { alpn: 'h3' }), |
| 23 | + { |
| 24 | + code: 'ERR_ACCESS_DENIED', |
| 25 | + permission: 'Net', |
| 26 | + }, |
| 27 | + ); |
| 28 | +} |
| 29 | + |
| 30 | +// Test: listen() should throw ERR_ACCESS_DENIED |
| 31 | +{ |
| 32 | + await assert.rejects( |
| 33 | + listen(mustNotCall('onsession should not be called'), { |
| 34 | + alpn: ['h3'], |
| 35 | + sni: { '*': { keys: [key], certs: [cert] } }, |
| 36 | + }), |
| 37 | + { |
| 38 | + code: 'ERR_ACCESS_DENIED', |
| 39 | + permission: 'Net', |
| 40 | + }, |
| 41 | + ); |
| 42 | +} |
| 43 | + |
| 44 | +// Test: Creating a QuicEndpoint without connect/listen is allowed |
| 45 | +// since no network I/O occurs at construction time. |
| 46 | +{ |
| 47 | + const endpoint = new QuicEndpoint(); |
| 48 | + // The endpoint exists but has not performed any network operations. |
| 49 | + await endpoint.close(); |
| 50 | +} |
0 commit comments