|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const { test, describe } = require('node:test') |
| 4 | +const { throws, strictEqual } = require('node:assert') |
| 5 | + |
| 6 | +const { |
| 7 | + validateCookieValue |
| 8 | +} = require('../../lib/web/cookies/util') |
| 9 | + |
| 10 | +describe('validateCookieValue', () => { |
| 11 | + test('should throw for CTLs', () => { |
| 12 | + throws(() => validateCookieValue('\x00'), new Error('Invalid cookie value')) |
| 13 | + throws(() => validateCookieValue('\x01'), new Error('Invalid cookie value')) |
| 14 | + throws(() => validateCookieValue('\x02'), new Error('Invalid cookie value')) |
| 15 | + throws(() => validateCookieValue('\x03'), new Error('Invalid cookie value')) |
| 16 | + throws(() => validateCookieValue('\x04'), new Error('Invalid cookie value')) |
| 17 | + throws(() => validateCookieValue('\x05'), new Error('Invalid cookie value')) |
| 18 | + throws(() => validateCookieValue('\x06'), new Error('Invalid cookie value')) |
| 19 | + throws(() => validateCookieValue('\x07'), new Error('Invalid cookie value')) |
| 20 | + throws(() => validateCookieValue('\x08'), new Error('Invalid cookie value')) |
| 21 | + throws(() => validateCookieValue('\x09'), new Error('Invalid cookie value')) |
| 22 | + throws(() => validateCookieValue('\x0A'), new Error('Invalid cookie value')) |
| 23 | + throws(() => validateCookieValue('\x0B'), new Error('Invalid cookie value')) |
| 24 | + throws(() => validateCookieValue('\x0C'), new Error('Invalid cookie value')) |
| 25 | + throws(() => validateCookieValue('\x0D'), new Error('Invalid cookie value')) |
| 26 | + throws(() => validateCookieValue('\x0E'), new Error('Invalid cookie value')) |
| 27 | + throws(() => validateCookieValue('\x0F'), new Error('Invalid cookie value')) |
| 28 | + throws(() => validateCookieValue('\x10'), new Error('Invalid cookie value')) |
| 29 | + throws(() => validateCookieValue('\x11'), new Error('Invalid cookie value')) |
| 30 | + throws(() => validateCookieValue('\x12'), new Error('Invalid cookie value')) |
| 31 | + throws(() => validateCookieValue('\x13'), new Error('Invalid cookie value')) |
| 32 | + throws(() => validateCookieValue('\x14'), new Error('Invalid cookie value')) |
| 33 | + throws(() => validateCookieValue('\x15'), new Error('Invalid cookie value')) |
| 34 | + throws(() => validateCookieValue('\x16'), new Error('Invalid cookie value')) |
| 35 | + throws(() => validateCookieValue('\x17'), new Error('Invalid cookie value')) |
| 36 | + throws(() => validateCookieValue('\x18'), new Error('Invalid cookie value')) |
| 37 | + throws(() => validateCookieValue('\x19'), new Error('Invalid cookie value')) |
| 38 | + throws(() => validateCookieValue('\x1A'), new Error('Invalid cookie value')) |
| 39 | + throws(() => validateCookieValue('\x1B'), new Error('Invalid cookie value')) |
| 40 | + throws(() => validateCookieValue('\x1C'), new Error('Invalid cookie value')) |
| 41 | + throws(() => validateCookieValue('\x1D'), new Error('Invalid cookie value')) |
| 42 | + throws(() => validateCookieValue('\x1E'), new Error('Invalid cookie value')) |
| 43 | + throws(() => validateCookieValue('\x1F'), new Error('Invalid cookie value')) |
| 44 | + throws(() => validateCookieValue('\x7F'), new Error('Invalid cookie value')) |
| 45 | + }) |
| 46 | + |
| 47 | + test('should throw for ; character', () => { |
| 48 | + throws(() => validateCookieValue(';'), new Error('Invalid cookie value')) |
| 49 | + }) |
| 50 | + |
| 51 | + test('should throw for " character', () => { |
| 52 | + throws(() => validateCookieValue('"'), new Error('Invalid cookie value')) |
| 53 | + }) |
| 54 | + |
| 55 | + test('should throw for " character', () => { |
| 56 | + throws(() => validateCookieValue(','), new Error('Invalid cookie value')) |
| 57 | + }) |
| 58 | + |
| 59 | + test('should throw for \\ character', () => { |
| 60 | + throws(() => validateCookieValue('\\'), new Error('Invalid cookie value')) |
| 61 | + }) |
| 62 | + |
| 63 | + test('should pass for a printable character', t => { |
| 64 | + strictEqual(validateCookieValue('A'), undefined) |
| 65 | + strictEqual(validateCookieValue('Z'), undefined) |
| 66 | + strictEqual(validateCookieValue('a'), undefined) |
| 67 | + strictEqual(validateCookieValue('z'), undefined) |
| 68 | + strictEqual(validateCookieValue('!'), undefined) |
| 69 | + strictEqual(validateCookieValue('='), undefined) |
| 70 | + }) |
| 71 | + |
| 72 | + test('should handle strings wrapped in DQUOTE', t => { |
| 73 | + strictEqual(validateCookieValue('""'), undefined) |
| 74 | + strictEqual(validateCookieValue('"helloworld"'), undefined) |
| 75 | + throws(() => validateCookieValue('"'), new Error('Invalid cookie value')) |
| 76 | + throws(() => validateCookieValue('"""'), new Error('Invalid cookie value')) |
| 77 | + }) |
| 78 | +}) |
0 commit comments