diff --git a/lib/internal/tls/wrap.js b/lib/internal/tls/wrap.js index 4f1351f3e3e907..50adacb58b0cd9 100644 --- a/lib/internal/tls/wrap.js +++ b/lib/internal/tls/wrap.js @@ -1531,8 +1531,9 @@ Server.prototype.getTicketKeys = function getTicketKeys() { Server.prototype.setTicketKeys = function setTicketKeys(keys) { validateBuffer(keys); - assert(keys.byteLength === 48, - 'Session ticket keys must be a 48-byte buffer'); + if (keys.byteLength !== 48) { + throw new ERR_INVALID_ARG_VALUE('keys', keys.byteLength, 'must be exactly 48 bytes'); + } this._sharedCreds.context.setTicketKeys(keys); }; diff --git a/test/parallel/test-tls-ticket-invalid-arg.js b/test/parallel/test-tls-ticket-invalid-arg.js index 55143cdca31e77..2943d2690e29fe 100644 --- a/test/parallel/test-tls-ticket-invalid-arg.js +++ b/test/parallel/test-tls-ticket-invalid-arg.js @@ -13,12 +13,22 @@ const server = new tls.Server(); .forEach((arg) => assert.throws( () => server.setTicketKeys(arg), - { code: 'ERR_INVALID_ARG_TYPE' } + { + name: 'TypeError', + code: 'ERR_INVALID_ARG_TYPE', + message: 'The "buffer" argument must be an instance of Buffer, TypedArray, or DataView.' + + common.invalidArgTypeHelper(arg), + } )); [new Uint8Array(1), Buffer.from([1]), new DataView(new ArrayBuffer(2))].forEach( (arg) => - assert.throws(() => { - server.setTicketKeys(arg); - }, /Session ticket keys must be a 48-byte buffer/) + assert.throws( + () => server.setTicketKeys(arg), + { + name: 'TypeError', + code: 'ERR_INVALID_ARG_VALUE', + message: `The argument 'keys' must be exactly 48 bytes. Received ${arg.byteLength}`, + } + ) );