Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rexagod committed Jun 14, 2020
1 parent f3ba48d commit 8dedf1f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
23 changes: 17 additions & 6 deletions test/parallel/test-http2-invalidheaderfield.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ const { throws, strictEqual } = require('assert');
const server = http2.createServer(common.mustCall((req, res) => {
throws(() => {
res.setHeader(':path', '/');
}, TypeError);
}, {
code: 'ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED'
});
throws(() => {
res.setHeader('t est', 123);
}, TypeError);
}, {
code: 'ERR_INVALID_HTTP_TOKEN'
});
res.setHeader('TEST', 123);
res.setHeader('test_', 123);
res.setHeader(' test', 123);
Expand All @@ -30,20 +34,27 @@ server.listen(0, common.mustCall(() => {
session1.close();
server.close();
}));

const session2 = http2.connect(`http://localhost:${server.address().port}`);
session2.on('error', common.mustCall((e) => {
strictEqual(e.code, 'ERR_INVALID_HTTP_TOKEN');
}));
try {
throws(() => {
session2.request({ 't est': 123 });
} catch (e) { } // eslint-disable-line no-unused-vars
}, {
code: 'ERR_INVALID_HTTP_TOKEN'
});

const session3 = http2.connect(`http://localhost:${server.address().port}`);
session3.on('error', common.mustCall((e) => {
strictEqual(e.code, 'ERR_INVALID_HTTP_TOKEN');
}));
try {
throws(() => {
session3.request({ ' test': 123 });
} catch (e) { } // eslint-disable-line no-unused-vars
}, {
code: 'ERR_INVALID_HTTP_TOKEN'
});

const session4 = http2.connect(`http://localhost:${server.address().port}`);
try {
session4.request({ ':test': 123 });
Expand Down
20 changes: 13 additions & 7 deletions test/parallel/test-http2-invalidheaderfields-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ const server1 = http2.createServer();
server1.listen(0, common.mustCall(() => {
const session = http2.connect(`http://localhost:${server1.address().port}`);
// Check for req headers
session.request({ 'no underscore': 123 });
assert.throws(() => {
session.request({ 'no underscore': 123 });
}, {
code: 'ERR_INVALID_HTTP_TOKEN'
});
session.on('error', common.mustCall((e) => {
assert.strictEqual(e.code, 'ERR_INVALID_HTTP_TOKEN');
server1.close();
Expand All @@ -18,15 +22,18 @@ server1.listen(0, common.mustCall(() => {

const server2 = http2.createServer(common.mustCall((req, res) => {
// check for setHeader
res.setHeader('x y z', 123);
assert.throws(() => {
res.setHeader('x y z', 123);
}, {
code: 'ERR_INVALID_HTTP_TOKEN'
});
res.end();
}));

server2.listen(0, common.mustCall(() => {
const session = http2.connect(`http://localhost:${server2.address().port}`);
const req = session.request();
req.on('error', common.mustCall((e) => {
assert.strictEqual(e.code, 'ERR_HTTP2_STREAM_ERROR');
req.on('end', common.mustCall(() => {
session.close();
server2.close();
}));
Expand All @@ -39,16 +46,15 @@ const server3 = http2.createServer(common.mustCall((req, res) => {
'an invalid header': 123
});
}), {
code: 'ERR_HTTP2_INVALID_STREAM'
code: 'ERR_INVALID_HTTP_TOKEN'
});
res.end();
}));

server3.listen(0, common.mustCall(() => {
const session = http2.connect(`http://localhost:${server3.address().port}`);
const req = session.request();
req.on('error', common.mustCall((e) => {
assert.strictEqual(e.code, 'ERR_HTTP2_STREAM_ERROR');
req.on('end', common.mustCall(() => {
server3.close();
session.close();
}));
Expand Down

0 comments on commit 8dedf1f

Please sign in to comment.