From 5c1b27fb574baa0d6e57e563e24045a4d7cea77e Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 20 Mar 2019 13:45:53 +0100 Subject: [PATCH] http2: validate settings input The settings input was not marked as optional in our documentation but we did not throw an error in those cases. The API does not seem to be useful without the correct input, so I went for throwing an error in such cases instead of updating the documentation. --- lib/internal/http2/core.js | 6 +++++- test/parallel/test-http2-getpackedsettings.js | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 0e7d8c544cc0db..117db86598ad0d 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -789,7 +789,11 @@ function pingCallback(cb) { // 6. enablePush must be a boolean // All settings are optional and may be left undefined function validateSettings(settings) { - if (settings === undefined) return; + if (settings === undefined) { + const err = new ERR_INVALID_ARG_TYPE('settings', 'object', settings); + Error.captureStackTrace(err, 'validateSettings'); + throw err; + } assertWithinRange('headerTableSize', settings.headerTableSize, 0, kMaxInt); diff --git a/test/parallel/test-http2-getpackedsettings.js b/test/parallel/test-http2-getpackedsettings.js index 77c8cf442f5f27..0df2457f76c67c 100644 --- a/test/parallel/test-http2-getpackedsettings.js +++ b/test/parallel/test-http2-getpackedsettings.js @@ -88,8 +88,10 @@ http2.getPackedSettings({ enablePush: false }); // Check for not passing settings. { - const packed = http2.getPackedSettings(); - assert.strictEqual(packed.length, 0); + assert.throws( + () => http2.getPackedSettings(), + { code: 'ERR_INVALID_ARG_TYPE' } + ); } {