Skip to content

Commit 6bedd4c

Browse files
committed
http2: add tests for customSettings
Test for the http2 setting's custom settings were added.
1 parent 2b53b16 commit 6bedd4c

File tree

2 files changed

+87
-4
lines changed

2 files changed

+87
-4
lines changed

test/parallel/test-http2-getpackedsettings.js

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ assert.deepStrictEqual(val, check);
2929
['maxHeaderListSize', 2 ** 32 - 1],
3030
['maxHeaderSize', 0],
3131
['maxHeaderSize', 2 ** 32 - 1],
32+
['customSettings', { '9999': 301 }],
3233
].forEach((i) => {
3334
// Valid options should not throw.
3435
http2.getPackedSettings({ [i[0]]: i[1] });
@@ -93,6 +94,7 @@ http2.getPackedSettings({ enablePush: false });
9394
0x00, 0x05, 0x00, 0x00, 0x4e, 0x20,
9495
0x00, 0x06, 0x00, 0x00, 0x00, 0x64,
9596
0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
97+
0x27, 0x0F, 0x00, 0x00, 0x01, 0x2d,
9698
]);
9799

98100
const packed = http2.getPackedSettings({
@@ -104,12 +106,90 @@ http2.getPackedSettings({ enablePush: false });
104106
maxHeaderSize: 100,
105107
enablePush: true,
106108
enableConnectProtocol: false,
107-
foo: 'ignored'
109+
foo: 'ignored',
110+
customSettings: { '9999': 301 }
108111
});
109-
assert.strictEqual(packed.length, 42);
112+
assert.strictEqual(packed.length, 48);
110113
assert.deepStrictEqual(packed, check);
111114
}
112115

116+
// Check if multiple custom settings can be set
117+
{
118+
const check = Buffer.from([
119+
0x00, 0x01, 0x00, 0x00, 0x00, 0x64,
120+
0x00, 0x02, 0x00, 0x00, 0x00, 0x01,
121+
0x00, 0x03, 0x00, 0x00, 0x00, 0xc8,
122+
0x00, 0x04, 0x00, 0x00, 0x00, 0x64,
123+
0x00, 0x05, 0x00, 0x00, 0x4e, 0x20,
124+
0x00, 0x06, 0x00, 0x00, 0x00, 0x64,
125+
0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
126+
0x03, 0xf3, 0x00, 0x00, 0x07, 0x9F,
127+
0x0a, 0x2e, 0x00, 0x00, 0x00, 0x58,
128+
]);
129+
130+
const packed = http2.getPackedSettings({
131+
headerTableSize: 100,
132+
initialWindowSize: 100,
133+
maxFrameSize: 20000,
134+
maxConcurrentStreams: 200,
135+
maxHeaderListSize: 100,
136+
maxHeaderSize: 100,
137+
enablePush: true,
138+
enableConnectProtocol: false,
139+
customSettings: { '2606': 88, '1011': 1951 }
140+
});
141+
assert.strictEqual(packed.length, 54);
142+
assert.deepStrictEqual(packed, check);
143+
}
144+
145+
{
146+
// Check if wrong custom settings cause an error
147+
148+
assert.throws(() => {
149+
http2.getPackedSettings({
150+
customSettings: { '-1': 659685 }
151+
});
152+
}, {
153+
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
154+
name: 'RangeError'
155+
});
156+
157+
assert.throws(() => {
158+
http2.getPackedSettings({
159+
customSettings: { '10': 34577577777 }
160+
});
161+
}, {
162+
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
163+
name: 'RangeError'
164+
});
165+
166+
assert.throws(() => {
167+
http2.getPackedSettings({
168+
customSettings: { 'notvalid': -777 }
169+
});
170+
}, {
171+
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
172+
name: 'RangeError'
173+
});
174+
175+
assert.throws(() => {
176+
http2.getPackedSettings({
177+
customSettings: { '11': 11, '12': 12, '13': 13, '14': 14, '15': 15, '16': 16,
178+
'17': 17, '18': 18, '19': 19, '20': 20, '21': 21 }
179+
});
180+
}, {
181+
code: 'ERR_HTTP2_TOO_MANY_CUSTOM_SETTINGS'
182+
});
183+
assert.throws(() => {
184+
http2.getPackedSettings({
185+
customSettings: { '11': 11, '12': 12, '13': 13, '14': 14, '15': 15, '16': 16,
186+
'17': 17, '18': 18, '19': 19, '20': 20, '21': 21, '22': 22 }
187+
});
188+
}, {
189+
code: 'ERR_HTTP2_TOO_MANY_CUSTOM_SETTINGS'
190+
});
191+
}
192+
113193
// Check for not passing settings.
114194
{
115195
const packed = http2.getPackedSettings();
@@ -124,7 +204,8 @@ http2.getPackedSettings({ enablePush: false });
124204
0x00, 0x04, 0x00, 0x00, 0x00, 0x64,
125205
0x00, 0x06, 0x00, 0x00, 0x00, 0x64,
126206
0x00, 0x02, 0x00, 0x00, 0x00, 0x01,
127-
0x00, 0x08, 0x00, 0x00, 0x00, 0x00]);
207+
0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
208+
0x27, 0x0F, 0x00, 0x00, 0x01, 0x2d]);
128209

129210
[1, true, '', [], {}, NaN].forEach((input) => {
130211
assert.throws(() => {
@@ -157,6 +238,7 @@ http2.getPackedSettings({ enablePush: false });
157238
assert.strictEqual(settings.maxHeaderSize, 100);
158239
assert.strictEqual(settings.enablePush, true);
159240
assert.strictEqual(settings.enableConnectProtocol, false);
241+
assert.deepStrictEqual(settings.customSettings, { '9999': 301 });
160242
}
161243

162244
{

test/parallel/test-http2-update-settings.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ testUpdateSettingsWith({
1919
'maxHeaderListSize': 1,
2020
'maxFrameSize': 16385,
2121
'enablePush': false,
22-
'enableConnectProtocol': true
22+
'enableConnectProtocol': true,
23+
'customSettings': { '9999': 301 }
2324
}
2425
});
2526
testUpdateSettingsWith({

0 commit comments

Comments
 (0)