From 2f9d9e5fe3b09d3fe54bbf04a61b1fe8289414c0 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Wed, 30 Aug 2017 15:52:26 -0700 Subject: test: http2 test coverage for assertValidPseudoHeader PR-URL: https://github.com/nodejs/node/pull/15105 Reviewed-By: Colin Ihrig Reviewed-By: Benjamin Gruenbaum Reviewed-By: Luigi Pinca Reviewed-By: Daniel Bevenius --- .../test-http2-util-assert-valid-pseudoheader.js | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test/parallel/test-http2-util-assert-valid-pseudoheader.js (limited to 'test/parallel/test-http2-util-assert-valid-pseudoheader.js') diff --git a/test/parallel/test-http2-util-assert-valid-pseudoheader.js b/test/parallel/test-http2-util-assert-valid-pseudoheader.js new file mode 100644 index 0000000000..27050fedd6 --- /dev/null +++ b/test/parallel/test-http2-util-assert-valid-pseudoheader.js @@ -0,0 +1,31 @@ +// Flags: --expose-internals +'use strict'; + +const common = require('../common'); + +// Tests the assertValidPseudoHeader function that is used within the +// mapToHeaders function. The assert function is not exported so we +// have to test it through mapToHeaders + +const { mapToHeaders } = require('internal/http2/util'); +const assert = require('assert'); + +function isNotError(val) { + assert(!(val instanceof Error)); +} + +function isError(val) { + common.expectsError({ + code: 'ERR_HTTP2_INVALID_PSEUDOHEADER', + type: Error, + 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' })); -- cgit v1.2.3