Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: http2 options errors for respondWithFD
Refs: #14985
  • Loading branch information
ssbrewster committed Sep 10, 2017
commit 9c52b73c1701c2fb9f9e9c82a656e526bb2b1be9
71 changes: 71 additions & 0 deletions test/parallel/test-http2-options-errors-respondfd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Flags: --expose-http2
'use strict';

const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const http2 = require('http2');

// Test that ERR_INVALID_OPT_VALUE TypeErrors are thrown when passing invalid
// options to ServerHttp2Stream.respondWithFD method

const optionsToTest = {
offset: 'number',
length: 'number',
statCheck: 'function',
getTrailers: 'function'
};

const types = {
function: () => {},
number: 1,
object: {},
array: [],
null: null,
symbol: Symbol('test')
};

const server = http2.createServer();

const {
HTTP2_HEADER_CONTENT_TYPE
} = http2.constants;

server.on('stream', common.mustCall(onStream));

function onStream(stream, headers, flags) {
Object.keys(optionsToTest).forEach((option) => {
Object.keys(types).forEach((type) => {
if (type === optionsToTest[option]) {
return;
}

common.expectsError(() => stream.respondWithFD(0, {
[HTTP2_HEADER_CONTENT_TYPE]: 'text/plain'
}, {
[option]: types[type]
}), {
type: TypeError,
code: 'ERR_INVALID_OPT_VALUE',
message: `The value "${String(types[type])}" is invalid ` +
`for option "${option}"`
});

});
});
stream.end('hello world');
}

server.listen(0, common.mustCall(() => {
const port = server.address().port;
const client = http2.connect(`http://localhost:${port}`);
const req = client.request();

req.resume();

req.on('end', common.mustCall(() => {
client.destroy();
server.close();
}));
req.end();
}));