forked from nodejs/undici
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate-cookie-name.js
130 lines (107 loc) · 5.54 KB
/
validate-cookie-name.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
'use strict'
const { test, describe } = require('node:test')
const { throws, strictEqual } = require('node:assert')
const {
validateCookieName
} = require('../../lib/web/cookies/util')
describe('validateCookieName', () => {
test('should throw for CTLs', () => {
throws(() => validateCookieName('\x00'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x01'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x02'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x03'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x04'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x05'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x06'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x07'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x08'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x09'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x0A'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x0B'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x0C'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x0D'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x0E'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x0F'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x10'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x11'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x12'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x13'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x14'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x15'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x16'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x17'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x18'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x19'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x1A'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x1B'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x1C'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x1D'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x1E'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x1F'), new Error('Invalid cookie name'))
throws(() => validateCookieName('\x7F'), new Error('Invalid cookie name'))
})
test('should throw for " " character', () => {
throws(() => validateCookieName(' '), new Error('Invalid cookie name'))
})
test('should throw for Horizontal Tab character', () => {
throws(() => validateCookieName('\t'), new Error('Invalid cookie name'))
})
test('should throw for ; character', () => {
throws(() => validateCookieName(';'), new Error('Invalid cookie name'))
})
test('should throw for " character', () => {
throws(() => validateCookieName('"'), new Error('Invalid cookie name'))
})
test('should throw for , character', () => {
throws(() => validateCookieName(','), new Error('Invalid cookie name'))
})
test('should throw for \\ character', () => {
throws(() => validateCookieName('\\'), new Error('Invalid cookie name'))
})
test('should throw for ( character', () => {
throws(() => validateCookieName('('), new Error('Invalid cookie name'))
})
test('should throw for ) character', () => {
throws(() => validateCookieName(')'), new Error('Invalid cookie name'))
})
test('should throw for < character', () => {
throws(() => validateCookieName('<'), new Error('Invalid cookie name'))
})
test('should throw for > character', () => {
throws(() => validateCookieName('>'), new Error('Invalid cookie name'))
})
test('should throw for @ character', () => {
throws(() => validateCookieName('@'), new Error('Invalid cookie name'))
})
test('should throw for : character', () => {
throws(() => validateCookieName(':'), new Error('Invalid cookie name'))
})
test('should throw for / character', () => {
throws(() => validateCookieName('/'), new Error('Invalid cookie name'))
})
test('should throw for [ character', () => {
throws(() => validateCookieName('['), new Error('Invalid cookie name'))
})
test('should throw for ] character', () => {
throws(() => validateCookieName(']'), new Error('Invalid cookie name'))
})
test('should throw for ? character', () => {
throws(() => validateCookieName('?'), new Error('Invalid cookie name'))
})
test('should throw for = character', () => {
throws(() => validateCookieName('='), new Error('Invalid cookie name'))
})
test('should throw for { character', () => {
throws(() => validateCookieName('{'), new Error('Invalid cookie name'))
})
test('should throw for } character', () => {
throws(() => validateCookieName('}'), new Error('Invalid cookie name'))
})
test('should pass for a printable character', t => {
strictEqual(validateCookieName('A'), undefined)
strictEqual(validateCookieName('Z'), undefined)
strictEqual(validateCookieName('a'), undefined)
strictEqual(validateCookieName('z'), undefined)
strictEqual(validateCookieName('!'), undefined)
})
})