diff options
author | James M Snell <jasnell@gmail.com> | 2018-11-03 10:27:18 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2018-11-21 08:57:56 -0800 |
commit | e94d16daf23bf471ac438860216bfa4c92c86525 (patch) | |
tree | a163aca49ab6c25fd3b4fcbfaad91f4734d4dcbd /test | |
parent | 9379ab3786c0c6a9985f7b32b1c9fe36421b5eaf (diff) | |
download | android-node-v8-e94d16daf23bf471ac438860216bfa4c92c86525.tar.gz android-node-v8-e94d16daf23bf471ac438860216bfa4c92c86525.tar.bz2 android-node-v8-e94d16daf23bf471ac438860216bfa4c92c86525.zip |
http2: throw from mapToHeaders
PR-URL: https://github.com/nodejs/node/pull/24063
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Note: Landed with one collaborator approval after PR
was open for 18 days
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-http2-util-assert-valid-pseudoheader.js | 30 | ||||
-rw-r--r-- | test/parallel/test-http2-util-headers-list.js | 34 |
2 files changed, 29 insertions, 35 deletions
diff --git a/test/parallel/test-http2-util-assert-valid-pseudoheader.js b/test/parallel/test-http2-util-assert-valid-pseudoheader.js index badd7442ad..b0d7ac0e58 100644 --- a/test/parallel/test-http2-util-assert-valid-pseudoheader.js +++ b/test/parallel/test-http2-util-assert-valid-pseudoheader.js @@ -8,24 +8,16 @@ const common = require('../common'); // have to test it through mapToHeaders const { mapToHeaders } = require('internal/http2/util'); -const assert = require('assert'); -function isNotError(val) { - assert(!(val instanceof Error)); -} +// These should not throw +mapToHeaders({ ':status': 'a' }); +mapToHeaders({ ':path': 'a' }); +mapToHeaders({ ':authority': 'a' }); +mapToHeaders({ ':scheme': 'a' }); +mapToHeaders({ ':method': 'a' }); -function isError(val) { - common.expectsError({ - code: 'ERR_HTTP2_INVALID_PSEUDOHEADER', - type: TypeError, - message: '":foo" is an invalid pseudoheader or is used incorrectly' - })(val); -} - -isNotError(mapToHeaders({ ':status': 'a' })); -isNotError(mapToHeaders({ ':path': 'a' })); -isNotError(mapToHeaders({ ':authority': 'a' })); -isNotError(mapToHeaders({ ':scheme': 'a' })); -isNotError(mapToHeaders({ ':method': 'a' })); - -isError(mapToHeaders({ ':foo': 'a' })); +common.expectsError(() => mapToHeaders({ ':foo': 'a' }), { + code: 'ERR_HTTP2_INVALID_PSEUDOHEADER', + type: TypeError, + message: '":foo" is an invalid pseudoheader or is used incorrectly' +}); diff --git a/test/parallel/test-http2-util-headers-list.js b/test/parallel/test-http2-util-headers-list.js index 2402e01cbf..2814613df2 100644 --- a/test/parallel/test-http2-util-headers-list.js +++ b/test/parallel/test-http2-util-headers-list.js @@ -175,11 +175,11 @@ const { ':statuS': 204, }; - common.expectsError({ + common.expectsError(() => mapToHeaders(headers), { code: 'ERR_HTTP2_HEADER_SINGLE_VALUE', type: TypeError, message: 'Header field ":status" must only have a single value' - })(mapToHeaders(headers)); + }); } // The following are not allowed to have multiple values @@ -224,10 +224,10 @@ const { HTTP2_HEADER_X_CONTENT_TYPE_OPTIONS ].forEach((name) => { const msg = `Header field "${name}" must only have a single value`; - common.expectsError({ + common.expectsError(() => mapToHeaders({ [name]: [1, 2, 3] }), { code: 'ERR_HTTP2_HEADER_SINGLE_VALUE', message: msg - })(mapToHeaders({ [name]: [1, 2, 3] })); + }); }); [ @@ -281,30 +281,32 @@ const { 'Proxy-Connection', 'Keep-Alive' ].forEach((name) => { - common.expectsError({ + common.expectsError(() => mapToHeaders({ [name]: 'abc' }), { code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS', name: 'TypeError [ERR_HTTP2_INVALID_CONNECTION_HEADERS]', message: 'HTTP/1 Connection specific headers are forbidden: ' + `"${name.toLowerCase()}"` - })(mapToHeaders({ [name]: 'abc' })); + }); }); -common.expectsError({ +common.expectsError(() => mapToHeaders({ [HTTP2_HEADER_TE]: ['abc'] }), { code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS', name: 'TypeError [ERR_HTTP2_INVALID_CONNECTION_HEADERS]', message: 'HTTP/1 Connection specific headers are forbidden: ' + `"${HTTP2_HEADER_TE}"` -})(mapToHeaders({ [HTTP2_HEADER_TE]: ['abc'] })); +}); -common.expectsError({ - code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS', - name: 'TypeError [ERR_HTTP2_INVALID_CONNECTION_HEADERS]', - message: 'HTTP/1 Connection specific headers are forbidden: ' + - `"${HTTP2_HEADER_TE}"` -})(mapToHeaders({ [HTTP2_HEADER_TE]: ['abc', 'trailers'] })); +common.expectsError( + () => mapToHeaders({ [HTTP2_HEADER_TE]: ['abc', 'trailers'] }), { + code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS', + name: 'TypeError [ERR_HTTP2_INVALID_CONNECTION_HEADERS]', + message: 'HTTP/1 Connection specific headers are forbidden: ' + + `"${HTTP2_HEADER_TE}"` + }); -assert(!(mapToHeaders({ te: 'trailers' }) instanceof Error)); -assert(!(mapToHeaders({ te: ['trailers'] }) instanceof Error)); +// These should not throw +mapToHeaders({ te: 'trailers' }); +mapToHeaders({ te: ['trailers'] }); { |