From 340b3be1df9e8ade94c4767c7ff6d7c6d3003ea6 Mon Sep 17 00:00:00 2001
From: Michael Albert <michaalbert.42@gmail.com>
Date: Wed, 9 Aug 2017 00:10:04 +0200
Subject: [PATCH] test: increase http2 coverage
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Added tests for `getPackedSettings` to check for not passing `settings`
and for `getUnpackedSettings` to check for a few cases when passing
`{ validate: true }`.

PR-URL: https://github.com/nodejs/node/pull/14701
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
---
 test/parallel/test-http2-getpackedsettings.js | 33 +++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/test/parallel/test-http2-getpackedsettings.js b/test/parallel/test-http2-getpackedsettings.js
index 341a55a92c4481..e5e49571800797 100644
--- a/test/parallel/test-http2-getpackedsettings.js
+++ b/test/parallel/test-http2-getpackedsettings.js
@@ -84,6 +84,12 @@ assert.doesNotThrow(() => http2.getPackedSettings({ enablePush: false }));
   assert.deepStrictEqual(packed, check);
 }
 
+// check for not passing settings
+{
+  const packed = http2.getPackedSettings();
+  assert.strictEqual(packed.length, 0);
+}
+
 {
   const packed = Buffer.from([
     0x00, 0x01, 0x00, 0x00, 0x00, 0x64, 0x00, 0x03, 0x00, 0x00,
@@ -120,6 +126,33 @@ assert.doesNotThrow(() => http2.getPackedSettings({ enablePush: false }));
   assert.strictEqual(settings.enablePush, true);
 }
 
+//check for what happens if passing {validate: true} and no errors happen
+{
+  const packed = Buffer.from([
+    0x00, 0x01, 0x00, 0x00, 0x00, 0x64, 0x00, 0x03, 0x00, 0x00,
+    0x00, 0xc8, 0x00, 0x05, 0x00, 0x00, 0x4e, 0x20, 0x00, 0x04,
+    0x00, 0x00, 0x00, 0x64, 0x00, 0x06, 0x00, 0x00, 0x00, 0x64,
+    0x00, 0x02, 0x00, 0x00, 0x00, 0x01]);
+
+  assert.doesNotThrow(() => {
+    http2.getUnpackedSettings(packed, { validate: true });
+  });
+}
+
+// check for maxFrameSize failing the max number
+{
+  const packed = Buffer.from([0x00, 0x05, 0x01, 0x00, 0x00, 0x00]);
+
+  assert.throws(() => {
+    http2.getUnpackedSettings(packed, { validate: true });
+  }, common.expectsError({
+    code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
+    type: RangeError,
+    message: 'Invalid value for setting "maxFrameSize": 16777216'
+  }));
+}
+
+// check for maxConcurrentStreams failing the max number
 {
   const packed = Buffer.from([0x00, 0x03, 0xFF, 0xFF, 0xFF, 0xFF]);