22
33// Test: ALPN mismatch causes connection failure.
44// The server offers 'quic-test' but the client requests 'nonexistent'.
5- // The handshake should fail.
5+ // The handshake should fail with a `no_application_protocol` alert.
6+ //
7+ // The QUIC transport error code for a CRYPTO_ERROR carrying a TLS alert is
8+ // 0x100 | <tls_alert>. For `no_application_protocol` (alert 120 / 0x78) this
9+ // is 0x178 == 376. ERR_QUIC_TRANSPORT_ERROR formats the wire code into its
10+ // message as a bigint, so we match `376n` to assert the specific alert was
11+ // sent rather than some other handshake failure.
612
713import { hasQuic , skip , mustCall } from '../common/index.mjs' ;
814import assert from 'node:assert' ;
915
10- const { rejects, strictEqual } = assert ;
16+ const { rejects, strictEqual, match } = assert ;
1117
1218if ( ! hasQuic ) {
1319 skip ( 'QUIC is not enabled' ) ;
1420}
1521
1622const { listen, connect } = await import ( '../common/quic.mjs' ) ;
1723
24+ const expected = {
25+ code : 'ERR_QUIC_TRANSPORT_ERROR' ,
26+ message : / \b 3 7 6 n \b / ,
27+ } ;
28+
1829const onerror = mustCall ( ( err ) => {
1930 strictEqual ( err . code , 'ERR_QUIC_TRANSPORT_ERROR' ) ;
31+ match ( err . message , / \b 3 7 6 n \b / ) ;
2032} , 2 ) ;
2133const transportParams = { maxIdleTimeout : 1 } ;
2234
2335const serverEndpoint = await listen ( mustCall ( async ( serverSession ) => {
24- await rejects ( serverSession . opened , {
25- code : 'ERR_QUIC_TRANSPORT_ERROR' ,
26- } ) ;
27- await rejects ( serverSession . closed , {
28- code : 'ERR_QUIC_TRANSPORT_ERROR' ,
29- } ) ;
36+ await rejects ( serverSession . opened , expected ) ;
37+ await rejects ( serverSession . closed , expected ) ;
3038} ) , {
3139 transportParams,
3240 onerror,
@@ -39,12 +47,8 @@ const clientSession = await connect(serverEndpoint.address, {
3947 onerror,
4048} ) ;
4149
42- await rejects ( clientSession . opened , {
43- code : 'ERR_QUIC_TRANSPORT_ERROR' ,
44- } ) ;
50+ await rejects ( clientSession . opened , expected ) ;
4551
4652// The handshake should fail — opened may reject or never resolve.
4753// The session should close with an error.
48- await rejects ( clientSession . closed , {
49- code : 'ERR_QUIC_TRANSPORT_ERROR' ,
50- } ) ;
54+ await rejects ( clientSession . closed , expected ) ;
0 commit comments