summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-invalidheaderfield2.js
diff options
context:
space:
mode:
authorBrian White <mscdex@mscdex.net>2016-05-07 17:21:22 -0400
committerBrian White <mscdex@mscdex.net>2016-06-14 15:13:00 -0400
commitc8fa79f35128388496b42e41adcec486797f6122 (patch)
tree27423a6d879087a9ada22e19107304301fc07867 /test/parallel/test-http-invalidheaderfield2.js
parent39fdf0773d7066d33f562de8bb7220708f4ab619 (diff)
downloadnode-new-c8fa79f35128388496b42e41adcec486797f6122.tar.gz
test: add more http token/value checking tests
PR-URL: https://github.com/nodejs/node/pull/6570 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Diffstat (limited to 'test/parallel/test-http-invalidheaderfield2.js')
-rw-r--r--test/parallel/test-http-invalidheaderfield2.js97
1 files changed, 97 insertions, 0 deletions
diff --git a/test/parallel/test-http-invalidheaderfield2.js b/test/parallel/test-http-invalidheaderfield2.js
new file mode 100644
index 0000000000..727c600d5d
--- /dev/null
+++ b/test/parallel/test-http-invalidheaderfield2.js
@@ -0,0 +1,97 @@
+'use strict';
+require('../common');
+const assert = require('assert');
+const inspect = require('util').inspect;
+const checkIsHttpToken = require('_http_common')._checkIsHttpToken;
+const checkInvalidHeaderChar = require('_http_common')._checkInvalidHeaderChar;
+
+// Good header field names
+[
+ 'TCN',
+ 'ETag',
+ 'date',
+ 'alt-svc',
+ 'Content-Type',
+ '0',
+ 'Set-Cookie2',
+ 'Set_Cookie',
+ 'foo`bar^',
+ 'foo|bar',
+ '~foobar',
+ 'FooBar!',
+ '#Foo',
+ '$et-Cookie',
+ '%%Test%%',
+ 'Test&123',
+ 'It\'s_fun',
+ '2*3',
+ '4+2',
+ '3.14159265359'
+].forEach(function(str) {
+ assert.strictEqual(checkIsHttpToken(str),
+ true,
+ 'checkIsHttpToken(' +
+ inspect(str) +
+ ') unexpectedly failed');
+});
+// Bad header field names
+[
+ ':',
+ '@@',
+ '中文呢', // unicode
+ '((((())))',
+ ':alternate-protocol',
+ 'alternate-protocol:',
+ 'foo\nbar',
+ 'foo\rbar',
+ 'foo\r\nbar',
+ 'foo\x00bar',
+ '\x7FMe!',
+ '{Start',
+ '(Start',
+ '[Start',
+ 'End}',
+ 'End)',
+ 'End]',
+ '"Quote"',
+ 'This,That'
+].forEach(function(str) {
+ assert.strictEqual(checkIsHttpToken(str),
+ false,
+ 'checkIsHttpToken(' +
+ inspect(str) +
+ ') unexpectedly succeeded');
+});
+
+
+// Good header field values
+[
+ 'foo bar',
+ 'foo\tbar',
+ '0123456789ABCdef',
+ '!@#$%^&*()-_=+\\;\':"[]{}<>,./?|~`'
+].forEach(function(str) {
+ assert.strictEqual(checkInvalidHeaderChar(str),
+ false,
+ 'checkInvalidHeaderChar(' +
+ inspect(str) +
+ ') unexpectedly failed');
+});
+
+// Bad header field values
+[
+ 'foo\rbar',
+ 'foo\nbar',
+ 'foo\r\nbar',
+ '中文呢', // unicode
+ '\x7FMe!',
+ 'Testing 123\x00',
+ 'foo\vbar',
+ 'Ding!\x07'
+].forEach(function(str) {
+ assert.strictEqual(checkInvalidHeaderChar(str),
+ true,
+ 'checkInvalidHeaderChar(' +
+ inspect(str) +
+ ') unexpectedly succeeded');
+});