From 442968c92a0f131c153dba40e607e081811e5eb3 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Fri, 7 Aug 2020 12:25:41 -0700 Subject: [PATCH] quic: check setSocket natRebinding argument, extend test PR-URL: https://github.com/nodejs/node/pull/34669 Reviewed-By: Anna Henningsen --- lib/internal/quic/core.js | 2 ++ test/parallel/test-quic-simple-client-migrate.js | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/internal/quic/core.js b/lib/internal/quic/core.js index 93849d0dcd8ecc..dfbc876a84670c 100644 --- a/lib/internal/quic/core.js +++ b/lib/internal/quic/core.js @@ -2445,6 +2445,8 @@ class QuicClientSession extends QuicSession { throw new ERR_INVALID_STATE('QuicSocket is already destroyed'); if (socket.closing) throw new ERR_INVALID_STATE('QuicSocket is closing'); + if (typeof natRebinding !== 'boolean') + throw new ERR_INVALID_ARG_TYPE('natRebinding', 'boolean', true); await socket[kMaybeBind](); diff --git a/test/parallel/test-quic-simple-client-migrate.js b/test/parallel/test-quic-simple-client-migrate.js index af15456c855fe6..a658bfa4bbbd2f 100644 --- a/test/parallel/test-quic-simple-client-migrate.js +++ b/test/parallel/test-quic-simple-client-migrate.js @@ -69,6 +69,17 @@ const server = createQuicSocket({ server: options }); const s1 = req.socket; const a1 = req.socket.endpoints[0].address; + await Promise.all([1, {}, 'test', false, null, undefined].map((i) => { + return assert.rejects(req.setSocket(i), { + code: 'ERR_INVALID_ARG_TYPE' + }); + })); + await Promise.all([1, {}, 'test', null].map((i) => { + return assert.rejects(req.setSocket(req.socket, i), { + code: 'ERR_INVALID_ARG_TYPE' + }); + })); + await req.setSocket(client2); // Verify that it is using a different network endpoint