Skip to content

Commit

Permalink
test: refactor test-http-response-splitting
Browse files Browse the repository at this point in the history
* move repeated code to function
* remove unneeded `common.mustCall()` usage with function arguments that
  are not callbacks
* add error message checking

PR-URL: #11429
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Сковорода Никита Андреевич <[email protected]>
  • Loading branch information
notarseniy authored and jasnell committed Mar 7, 2017
1 parent ba48075 commit f921637
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions test/parallel/test-http-response-splitting.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ const y = 'foo⠊Set-Cookie: foo=bar';

var count = 0;

function test(res, code, header) {
assert.throws(() => {
res.writeHead(code, header);
}, /^TypeError: The header content contains invalid characters$/);
}

const server = http.createServer((req, res) => {
switch (count++) {
case 0:
const loc = url.parse(req.url, true).query.lang;
assert.throws(common.mustCall(() => {
res.writeHead(302, {Location: `/foo?lang=${loc}`});
}));
test(res, 302, {Location: `/foo?lang=${loc}`});
break;
case 1:
assert.throws(common.mustCall(() => {
res.writeHead(200, {'foo': x});
}));
test(res, 200, {'foo': x});
break;
case 2:
assert.throws(common.mustCall(() => {
res.writeHead(200, {'foo': y});
}));
test(res, 200, {'foo': y});
break;
default:
common.fail('should not get to here.');
Expand Down

0 comments on commit f921637

Please sign in to comment.