Skip to content

Commit 340b3be

Browse files
michaalbertaddaleax
authored andcommitted
test: increase http2 coverage
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: #14701 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent b5556e4 commit 340b3be

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/parallel/test-http2-getpackedsettings.js

+33
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ assert.doesNotThrow(() => http2.getPackedSettings({ enablePush: false }));
8484
assert.deepStrictEqual(packed, check);
8585
}
8686

87+
// check for not passing settings
88+
{
89+
const packed = http2.getPackedSettings();
90+
assert.strictEqual(packed.length, 0);
91+
}
92+
8793
{
8894
const packed = Buffer.from([
8995
0x00, 0x01, 0x00, 0x00, 0x00, 0x64, 0x00, 0x03, 0x00, 0x00,
@@ -120,6 +126,33 @@ assert.doesNotThrow(() => http2.getPackedSettings({ enablePush: false }));
120126
assert.strictEqual(settings.enablePush, true);
121127
}
122128

129+
//check for what happens if passing {validate: true} and no errors happen
130+
{
131+
const packed = Buffer.from([
132+
0x00, 0x01, 0x00, 0x00, 0x00, 0x64, 0x00, 0x03, 0x00, 0x00,
133+
0x00, 0xc8, 0x00, 0x05, 0x00, 0x00, 0x4e, 0x20, 0x00, 0x04,
134+
0x00, 0x00, 0x00, 0x64, 0x00, 0x06, 0x00, 0x00, 0x00, 0x64,
135+
0x00, 0x02, 0x00, 0x00, 0x00, 0x01]);
136+
137+
assert.doesNotThrow(() => {
138+
http2.getUnpackedSettings(packed, { validate: true });
139+
});
140+
}
141+
142+
// check for maxFrameSize failing the max number
143+
{
144+
const packed = Buffer.from([0x00, 0x05, 0x01, 0x00, 0x00, 0x00]);
145+
146+
assert.throws(() => {
147+
http2.getUnpackedSettings(packed, { validate: true });
148+
}, common.expectsError({
149+
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
150+
type: RangeError,
151+
message: 'Invalid value for setting "maxFrameSize": 16777216'
152+
}));
153+
}
154+
155+
// check for maxConcurrentStreams failing the max number
123156
{
124157
const packed = Buffer.from([0x00, 0x03, 0xFF, 0xFF, 0xFF, 0xFF]);
125158

0 commit comments

Comments
 (0)