Skip to content

Commit 535c8dd

Browse files
mscdexevanlucas
authored andcommitted
test: add more http token/value checking tests
PR-URL: #6570 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
1 parent 32f7698 commit 535c8dd

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
'use strict';
2+
require('../common');
3+
const assert = require('assert');
4+
const inspect = require('util').inspect;
5+
const checkIsHttpToken = require('_http_common')._checkIsHttpToken;
6+
const checkInvalidHeaderChar = require('_http_common')._checkInvalidHeaderChar;
7+
8+
// Good header field names
9+
[
10+
'TCN',
11+
'ETag',
12+
'date',
13+
'alt-svc',
14+
'Content-Type',
15+
'0',
16+
'Set-Cookie2',
17+
'Set_Cookie',
18+
'foo`bar^',
19+
'foo|bar',
20+
'~foobar',
21+
'FooBar!',
22+
'#Foo',
23+
'$et-Cookie',
24+
'%%Test%%',
25+
'Test&123',
26+
'It\'s_fun',
27+
'2*3',
28+
'4+2',
29+
'3.14159265359'
30+
].forEach(function(str) {
31+
assert.strictEqual(checkIsHttpToken(str),
32+
true,
33+
'checkIsHttpToken(' +
34+
inspect(str) +
35+
') unexpectedly failed');
36+
});
37+
// Bad header field names
38+
[
39+
':',
40+
'@@',
41+
'中文呢', // unicode
42+
'((((())))',
43+
':alternate-protocol',
44+
'alternate-protocol:',
45+
'foo\nbar',
46+
'foo\rbar',
47+
'foo\r\nbar',
48+
'foo\x00bar',
49+
'\x7FMe!',
50+
'{Start',
51+
'(Start',
52+
'[Start',
53+
'End}',
54+
'End)',
55+
'End]',
56+
'"Quote"',
57+
'This,That'
58+
].forEach(function(str) {
59+
assert.strictEqual(checkIsHttpToken(str),
60+
false,
61+
'checkIsHttpToken(' +
62+
inspect(str) +
63+
') unexpectedly succeeded');
64+
});
65+
66+
67+
// Good header field values
68+
[
69+
'foo bar',
70+
'foo\tbar',
71+
'0123456789ABCdef',
72+
'!@#$%^&*()-_=+\\;\':"[]{}<>,./?|~`'
73+
].forEach(function(str) {
74+
assert.strictEqual(checkInvalidHeaderChar(str),
75+
false,
76+
'checkInvalidHeaderChar(' +
77+
inspect(str) +
78+
') unexpectedly failed');
79+
});
80+
81+
// Bad header field values
82+
[
83+
'foo\rbar',
84+
'foo\nbar',
85+
'foo\r\nbar',
86+
'中文呢', // unicode
87+
'\x7FMe!',
88+
'Testing 123\x00',
89+
'foo\vbar',
90+
'Ding!\x07'
91+
].forEach(function(str) {
92+
assert.strictEqual(checkInvalidHeaderChar(str),
93+
true,
94+
'checkInvalidHeaderChar(' +
95+
inspect(str) +
96+
') unexpectedly succeeded');
97+
});

0 commit comments

Comments
 (0)