aboutsummaryrefslogtreecommitdiff
path: root/test/parallel/test-http2-util-headers-list.js
diff options
context:
space:
mode:
authorAnatoli Papirovski <apapirovski@mac.com>2017-10-28 14:04:16 -0400
committerAnatoli Papirovski <apapirovski@mac.com>2017-10-29 13:05:54 -0400
commit980ebd2d35d9e001bcf24aee8a1f061ed2c7c70f (patch)
treef901ce92ded0b27765502178ae171dc2d1f539af /test/parallel/test-http2-util-headers-list.js
parentca82e3088dfe204ab36baa492a3e399d46827453 (diff)
downloadandroid-node-v8-980ebd2d35d9e001bcf24aee8a1f061ed2c7c70f.tar.gz
android-node-v8-980ebd2d35d9e001bcf24aee8a1f061ed2c7c70f.tar.bz2
android-node-v8-980ebd2d35d9e001bcf24aee8a1f061ed2c7c70f.zip
http2: simplify mapToHeaders, stricter validation
No longer check whether key is a symbol as Object.keys does not return symbols. No longer convert key to string as it is always a string. Validate that only one value is passed for each pseudo-header. Extend illegal connection header message to include the name of the problematic header. Extend tests to cover this behaviour. PR-URL: https://github.com/nodejs/node/pull/16575 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-http2-util-headers-list.js')
-rw-r--r--test/parallel/test-http2-util-headers-list.js27
1 files changed, 21 insertions, 6 deletions
diff --git a/test/parallel/test-http2-util-headers-list.js b/test/parallel/test-http2-util-headers-list.js
index f5e2025385..0bbe1972d0 100644
--- a/test/parallel/test-http2-util-headers-list.js
+++ b/test/parallel/test-http2-util-headers-list.js
@@ -158,7 +158,7 @@ const {
// Arrays containing a single set-cookie value are handled correctly
// (https://github.com/nodejs/node/issues/16452)
const headers = {
- 'set-cookie': 'foo=bar'
+ 'set-cookie': ['foo=bar']
};
assert.deepStrictEqual(
mapToHeaders(headers),
@@ -166,6 +166,20 @@ const {
);
}
+{
+ // pseudo-headers are only allowed a single value
+ const headers = {
+ ':status': 200,
+ ':statuS': 204,
+ };
+
+ common.expectsError({
+ code: 'ERR_HTTP2_HEADER_SINGLE_VALUE',
+ type: Error,
+ message: 'Header field ":status" must have only a single value'
+ })(mapToHeaders(headers));
+}
+
// The following are not allowed to have multiple values
[
HTTP2_HEADER_STATUS,
@@ -248,8 +262,6 @@ const {
assert(!(mapToHeaders({ [name]: [1, 2, 3] }) instanceof Error), name);
});
-const regex =
- /^HTTP\/1 Connection specific headers are forbidden$/;
[
HTTP2_HEADER_CONNECTION,
HTTP2_HEADER_UPGRADE,
@@ -269,18 +281,21 @@ const regex =
].forEach((name) => {
common.expectsError({
code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS',
- message: regex
+ message: 'HTTP/1 Connection specific headers are forbidden: ' +
+ `"${name.toLowerCase()}"`
})(mapToHeaders({ [name]: 'abc' }));
});
common.expectsError({
code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS',
- message: regex
+ message: 'HTTP/1 Connection specific headers are forbidden: ' +
+ `"${HTTP2_HEADER_TE}"`
})(mapToHeaders({ [HTTP2_HEADER_TE]: ['abc'] }));
common.expectsError({
code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS',
- message: regex
+ message: 'HTTP/1 Connection specific headers are forbidden: ' +
+ `"${HTTP2_HEADER_TE}"`
})(mapToHeaders({ [HTTP2_HEADER_TE]: ['abc', 'trailers'] }));
assert(!(mapToHeaders({ te: 'trailers' }) instanceof Error));