diff --git a/test/cookie/cookies.js b/test/cookie/cookies.js index 9e2d3cf5fff..7ccd593bd28 100644 --- a/test/cookie/cookies.js +++ b/test/cookie/cookies.js @@ -23,7 +23,6 @@ 'use strict' const { test } = require('node:test') -const assert = require('node:assert') const { deleteCookie, getCookies, @@ -34,31 +33,31 @@ const { // https://raw.githubusercontent.com/denoland/deno_std/b4239898d6c6b4cdbfd659a4ea1838cf4e656336/http/cookie_test.ts -test('Cookie parser', () => { +test('Cookie parser', (t) => { let headers = new Headers() - assert.deepEqual(getCookies(headers), {}) + t.assert.deepEqual(getCookies(headers), {}) headers = new Headers() headers.set('Cookie', 'foo=bar') - assert.deepEqual(getCookies(headers), { foo: 'bar' }) + t.assert.deepEqual(getCookies(headers), { foo: 'bar' }) headers = new Headers() headers.set('Cookie', 'full=of ; tasty=chocolate') - assert.deepEqual(getCookies(headers), { full: 'of ', tasty: 'chocolate' }) + t.assert.deepEqual(getCookies(headers), { full: 'of ', tasty: 'chocolate' }) headers = new Headers() headers.set('Cookie', 'igot=99; problems=but...') - assert.deepEqual(getCookies(headers), { igot: '99', problems: 'but...' }) + t.assert.deepEqual(getCookies(headers), { igot: '99', problems: 'but...' }) headers = new Headers() headers.set('Cookie', 'PREF=al=en-GB&f1=123; wide=1; SID=123') - assert.deepEqual(getCookies(headers), { + t.assert.deepEqual(getCookies(headers), { PREF: 'al=en-GB&f1=123', wide: '1', SID: '123' }) }) -test('Cookie Name Validation', () => { +test('Cookie Name Validation', (t) => { const tokens = [ '"id"', 'id\t', @@ -72,7 +71,7 @@ test('Cookie Name Validation', () => { ] const headers = new Headers() tokens.forEach((name) => { - assert.throws( + t.assert.throws( () => { setCookie(headers, { name, @@ -87,7 +86,7 @@ test('Cookie Name Validation', () => { }) }) -test('Cookie Value Validation', () => { +test('Cookie Value Validation', (t) => { const tokens = [ '1f\tWa', '\t', @@ -103,7 +102,7 @@ test('Cookie Value Validation', () => { const headers = new Headers() tokens.forEach((value) => { - assert.throws( + t.assert.throws( () => { setCookie( headers, @@ -121,7 +120,7 @@ test('Cookie Value Validation', () => { ) }) - assert.throws( + t.assert.throws( () => { setCookie(headers, { name: 'location', @@ -133,10 +132,10 @@ test('Cookie Value Validation', () => { ) }) -test('Cookie Path Validation', () => { +test('Cookie Path Validation', (t) => { const path = '/;domain=sub.domain.com' const headers = new Headers() - assert.throws( + t.assert.throws( () => { setCookie(headers, { name: 'Space', @@ -152,11 +151,11 @@ test('Cookie Path Validation', () => { ) }) -test('Cookie Domain Validation', () => { +test('Cookie Domain Validation', (t) => { const tokens = ['-domain.com', 'domain.org.', 'domain.org-'] const headers = new Headers() tokens.forEach((domain) => { - assert.throws( + t.assert.throws( () => { setCookie(headers, { name: 'Space', @@ -173,10 +172,10 @@ test('Cookie Domain Validation', () => { }) }) -test('Cookie Delete', () => { +test('Cookie Delete', (t) => { let headers = new Headers() deleteCookie(headers, 'deno') - assert.equal( + t.assert.strictEqual( headers.get('Set-Cookie'), 'deno=; Expires=Thu, 01 Jan 1970 00:00:00 GMT' ) @@ -188,24 +187,24 @@ test('Cookie Delete', () => { path: '/' }) deleteCookie(headers, 'Space', { domain: '', path: '' }) - assert.equal( + t.assert.strictEqual( headers.get('Set-Cookie'), 'Space=Cat; Domain=deno.land; Path=/, Space=; Expires=Thu, 01 Jan 1970 00:00:00 GMT' ) }) -test('Cookie Set', () => { +test('Cookie Set', (t) => { let headers = new Headers() setCookie(headers, { name: 'Space', value: 'Cat' }) - assert.equal(headers.get('Set-Cookie'), 'Space=Cat') + t.assert.strictEqual(headers.get('Set-Cookie'), 'Space=Cat') headers = new Headers() setCookie(headers, { name: 'Space', value: 'Cat', secure: true }) - assert.equal(headers.get('Set-Cookie'), 'Space=Cat; Secure') + t.assert.strictEqual(headers.get('Set-Cookie'), 'Space=Cat; Secure') headers = new Headers() setCookie(headers, { name: 'Space', value: 'Cat', httpOnly: true }) - assert.equal(headers.get('Set-Cookie'), 'Space=Cat; HttpOnly') + t.assert.strictEqual(headers.get('Set-Cookie'), 'Space=Cat; HttpOnly') headers = new Headers() setCookie(headers, { @@ -214,7 +213,7 @@ test('Cookie Set', () => { httpOnly: true, secure: true }) - assert.equal(headers.get('Set-Cookie'), 'Space=Cat; Secure; HttpOnly') + t.assert.strictEqual(headers.get('Set-Cookie'), 'Space=Cat; Secure; HttpOnly') headers = new Headers() setCookie(headers, { @@ -224,7 +223,7 @@ test('Cookie Set', () => { secure: true, maxAge: 2 }) - assert.equal( + t.assert.strictEqual( headers.get('Set-Cookie'), 'Space=Cat; Secure; HttpOnly; Max-Age=2' ) @@ -237,7 +236,7 @@ test('Cookie Set', () => { secure: true, maxAge: 0 }) - assert.equal( + t.assert.strictEqual( headers.get('Set-Cookie'), 'Space=Cat; Secure; HttpOnly; Max-Age=0' ) @@ -255,7 +254,7 @@ test('Cookie Set', () => { } catch { error = true } - assert.ok(error) + t.assert.ok(error) headers = new Headers() setCookie(headers, { @@ -266,7 +265,7 @@ test('Cookie Set', () => { maxAge: 2, domain: 'deno.land' }) - assert.equal( + t.assert.strictEqual( headers.get('Set-Cookie'), 'Space=Cat; Secure; HttpOnly; Max-Age=2; Domain=deno.land' ) @@ -281,7 +280,7 @@ test('Cookie Set', () => { domain: 'deno.land', sameSite: 'Strict' }) - assert.equal( + t.assert.strictEqual( headers.get('Set-Cookie'), 'Space=Cat; Secure; HttpOnly; Max-Age=2; Domain=deno.land; ' + 'SameSite=Strict' @@ -297,7 +296,7 @@ test('Cookie Set', () => { domain: 'deno.land', sameSite: 'Lax' }) - assert.equal( + t.assert.strictEqual( headers.get('Set-Cookie'), 'Space=Cat; Secure; HttpOnly; Max-Age=2; Domain=deno.land; SameSite=Lax' ) @@ -312,7 +311,7 @@ test('Cookie Set', () => { domain: 'deno.land', path: '/' }) - assert.equal( + t.assert.strictEqual( headers.get('Set-Cookie'), 'Space=Cat; Secure; HttpOnly; Max-Age=2; Domain=deno.land; Path=/' ) @@ -328,7 +327,7 @@ test('Cookie Set', () => { path: '/', unparsed: ['unparsed=keyvalue', 'batman=Bruce'] }) - assert.equal( + t.assert.strictEqual( headers.get('Set-Cookie'), 'Space=Cat; Secure; HttpOnly; Max-Age=2; Domain=deno.land; Path=/; ' + 'unparsed=keyvalue; batman=Bruce' @@ -345,7 +344,7 @@ test('Cookie Set', () => { path: '/', expires: new Date(Date.UTC(1983, 0, 7, 15, 32)) }) - assert.equal( + t.assert.strictEqual( headers.get('Set-Cookie'), 'Space=Cat; Secure; HttpOnly; Max-Age=2; Domain=deno.land; Path=/; ' + 'Expires=Fri, 07 Jan 1983 15:32:00 GMT' @@ -357,14 +356,14 @@ test('Cookie Set', () => { value: 'Cat', expires: Date.UTC(1983, 0, 7, 15, 32) }) - assert.equal( + t.assert.strictEqual( headers.get('Set-Cookie'), 'Space=Cat; Expires=Fri, 07 Jan 1983 15:32:00 GMT' ) headers = new Headers() setCookie(headers, { name: '__Secure-Kitty', value: 'Meow' }) - assert.equal(headers.get('Set-Cookie'), '__Secure-Kitty=Meow; Secure') + t.assert.strictEqual(headers.get('Set-Cookie'), '__Secure-Kitty=Meow; Secure') headers = new Headers() setCookie(headers, { @@ -372,7 +371,7 @@ test('Cookie Set', () => { value: 'Meow', domain: 'deno.land' }) - assert.equal( + t.assert.strictEqual( headers.get('Set-Cookie'), '__Host-Kitty=Meow; Secure; Path=/' ) @@ -380,39 +379,39 @@ test('Cookie Set', () => { headers = new Headers() setCookie(headers, { name: 'cookie-1', value: 'value-1', secure: true }) setCookie(headers, { name: 'cookie-2', value: 'value-2', maxAge: 3600 }) - assert.equal( + t.assert.strictEqual( headers.get('Set-Cookie'), 'cookie-1=value-1; Secure, cookie-2=value-2; Max-Age=3600' ) headers = new Headers() setCookie(headers, { name: '', value: '' }) - assert.equal(headers.get('Set-Cookie'), null) + t.assert.strictEqual(headers.get('Set-Cookie'), null) }) -test('Set-Cookie parser', () => { +test('Set-Cookie parser', (t) => { let headers = new Headers({ 'set-cookie': 'Space=Cat' }) - assert.deepEqual(getSetCookies(headers), [{ + t.assert.deepEqual(getSetCookies(headers), [{ name: 'Space', value: 'Cat' }]) headers = new Headers({ 'set-cookie': 'Space=Cat; Secure' }) - assert.deepEqual(getSetCookies(headers), [{ + t.assert.deepEqual(getSetCookies(headers), [{ name: 'Space', value: 'Cat', secure: true }]) headers = new Headers({ 'set-cookie': 'Space=Cat; HttpOnly' }) - assert.deepEqual(getSetCookies(headers), [{ + t.assert.deepEqual(getSetCookies(headers), [{ name: 'Space', value: 'Cat', httpOnly: true }]) headers = new Headers({ 'set-cookie': 'Space=Cat; Secure; HttpOnly' }) - assert.deepEqual(getSetCookies(headers), [{ + t.assert.deepEqual(getSetCookies(headers), [{ name: 'Space', value: 'Cat', secure: true, @@ -422,7 +421,7 @@ test('Set-Cookie parser', () => { headers = new Headers({ 'set-cookie': 'Space=Cat; Secure; HttpOnly; Max-Age=2' }) - assert.deepEqual(getSetCookies(headers), [{ + t.assert.deepEqual(getSetCookies(headers), [{ name: 'Space', value: 'Cat', secure: true, @@ -433,7 +432,7 @@ test('Set-Cookie parser', () => { headers = new Headers({ 'set-cookie': 'Space=Cat; Secure; HttpOnly; Max-Age=0' }) - assert.deepEqual(getSetCookies(headers), [{ + t.assert.deepEqual(getSetCookies(headers), [{ name: 'Space', value: 'Cat', secure: true, @@ -444,7 +443,7 @@ test('Set-Cookie parser', () => { headers = new Headers({ 'set-cookie': 'Space=Cat; Secure; HttpOnly; Max-Age=-1' }) - assert.deepEqual(getSetCookies(headers), [{ + t.assert.deepEqual(getSetCookies(headers), [{ name: 'Space', value: 'Cat', secure: true, @@ -454,7 +453,7 @@ test('Set-Cookie parser', () => { headers = new Headers({ 'set-cookie': 'Space=Cat; Secure; HttpOnly; Max-Age=2; Domain=deno.land' }) - assert.deepEqual(getSetCookies(headers), [{ + t.assert.deepEqual(getSetCookies(headers), [{ name: 'Space', value: 'Cat', secure: true, @@ -467,7 +466,7 @@ test('Set-Cookie parser', () => { 'set-cookie': 'Space=Cat; Secure; HttpOnly; Max-Age=2; Domain=deno.land; SameSite=Strict' }) - assert.deepEqual(getSetCookies(headers), [{ + t.assert.deepEqual(getSetCookies(headers), [{ name: 'Space', value: 'Cat', secure: true, @@ -481,7 +480,7 @@ test('Set-Cookie parser', () => { 'set-cookie': 'Space=Cat; Secure; HttpOnly; Max-Age=2; Domain=deno.land; SameSite=Lax' }) - assert.deepEqual(getSetCookies(headers), [{ + t.assert.deepEqual(getSetCookies(headers), [{ name: 'Space', value: 'Cat', secure: true, @@ -495,7 +494,7 @@ test('Set-Cookie parser', () => { 'set-cookie': 'Space=Cat; Secure; HttpOnly; Max-Age=2; Domain=deno.land; Path=/' }) - assert.deepEqual(getSetCookies(headers), [{ + t.assert.deepEqual(getSetCookies(headers), [{ name: 'Space', value: 'Cat', secure: true, @@ -509,7 +508,7 @@ test('Set-Cookie parser', () => { 'set-cookie': 'Space=Cat; Secure; HttpOnly; Max-Age=2; Domain=deno.land; Path=/; unparsed=keyvalue; batman=Bruce' }) - assert.deepEqual(getSetCookies(headers), [{ + t.assert.deepEqual(getSetCookies(headers), [{ name: 'Space', value: 'Cat', secure: true, @@ -525,7 +524,7 @@ test('Set-Cookie parser', () => { 'Space=Cat; Secure; HttpOnly; Max-Age=2; Domain=deno.land; Path=/; ' + 'Expires=Fri, 07 Jan 1983 15:32:00 GMT' }) - assert.deepEqual(getSetCookies(headers), [{ + t.assert.deepEqual(getSetCookies(headers), [{ name: 'Space', value: 'Cat', secure: true, @@ -537,14 +536,14 @@ test('Set-Cookie parser', () => { }]) headers = new Headers({ 'set-cookie': '__Secure-Kitty=Meow; Secure' }) - assert.deepEqual(getSetCookies(headers), [{ + t.assert.deepEqual(getSetCookies(headers), [{ name: '__Secure-Kitty', value: 'Meow', secure: true }]) headers = new Headers({ 'set-cookie': '__Secure-Kitty=Meow' }) - assert.deepEqual(getSetCookies(headers), [{ + t.assert.deepEqual(getSetCookies(headers), [{ name: '__Secure-Kitty', value: 'Meow' }]) @@ -552,7 +551,7 @@ test('Set-Cookie parser', () => { headers = new Headers({ 'set-cookie': '__Host-Kitty=Meow; Secure; Path=/' }) - assert.deepEqual(getSetCookies(headers), [{ + t.assert.deepEqual(getSetCookies(headers), [{ name: '__Host-Kitty', value: 'Meow', secure: true, @@ -560,7 +559,7 @@ test('Set-Cookie parser', () => { }]) headers = new Headers({ 'set-cookie': '__Host-Kitty=Meow; Path=/' }) - assert.deepEqual(getSetCookies(headers), [{ + t.assert.deepEqual(getSetCookies(headers), [{ name: '__Host-Kitty', value: 'Meow', path: '/' @@ -569,7 +568,7 @@ test('Set-Cookie parser', () => { headers = new Headers({ 'set-cookie': '__Host-Kitty=Meow; Secure; Domain=deno.land; Path=/' }) - assert.deepEqual(getSetCookies(headers), [{ + t.assert.deepEqual(getSetCookies(headers), [{ name: '__Host-Kitty', value: 'Meow', secure: true, @@ -580,7 +579,7 @@ test('Set-Cookie parser', () => { headers = new Headers({ 'set-cookie': '__Host-Kitty=Meow; Secure; Path=/not-root' }) - assert.deepEqual(getSetCookies(headers), [{ + t.assert.deepEqual(getSetCookies(headers), [{ name: '__Host-Kitty', value: 'Meow', secure: true, @@ -591,21 +590,21 @@ test('Set-Cookie parser', () => { ['set-cookie', 'cookie-1=value-1; Secure'], ['set-cookie', 'cookie-2=value-2; Max-Age=3600'] ]) - assert.deepEqual(getSetCookies(headers), [ + t.assert.deepEqual(getSetCookies(headers), [ { name: 'cookie-1', value: 'value-1', secure: true }, { name: 'cookie-2', value: 'value-2', maxAge: 3600 } ]) headers = new Headers() - assert.deepEqual(getSetCookies(headers), []) + t.assert.deepEqual(getSetCookies(headers), []) }) -test('Cookie setCookie throws if headers is not of type Headers', () => { +test('Cookie setCookie throws if headers is not of type Headers', (t) => { class Headers { [Symbol.toStringTag] = 'CustomHeaders' } const headers = new Headers() - assert.throws( + t.assert.throws( () => { setCookie(headers, { name: 'key', @@ -619,7 +618,7 @@ test('Cookie setCookie throws if headers is not of type Headers', () => { ) }) -test('Cookie setCookie does not throw if headers is an instance of undici owns Headers class', () => { +test('Cookie setCookie does not throw if headers is an instance of undici owns Headers class', (t) => { const headers = new Headers() setCookie(headers, { name: 'key', @@ -630,7 +629,7 @@ test('Cookie setCookie does not throw if headers is an instance of undici owns H }) }) -test('Cookie setCookie does not throw if headers is an instance of the global Headers class', { skip: !globalThis.Headers }, () => { +test('Cookie setCookie does not throw if headers is an instance of the global Headers class', { skip: !globalThis.Headers }, (t) => { const headers = new globalThis.Headers() setCookie(headers, { name: 'key', @@ -641,12 +640,12 @@ test('Cookie setCookie does not throw if headers is an instance of the global He }) }) -test('Cookie getCookies throws if headers is not of type Headers', () => { +test('Cookie getCookies throws if headers is not of type Headers', (t) => { class Headers { [Symbol.toStringTag] = 'CustomHeaders' } const headers = new Headers() - assert.throws( + t.assert.throws( () => { getCookies(headers) }, @@ -654,22 +653,22 @@ test('Cookie getCookies throws if headers is not of type Headers', () => { ) }) -test('Cookie getCookies does not throw if headers is an instance of undici owns Headers class', () => { +test('Cookie getCookies does not throw if headers is an instance of undici owns Headers class', (t) => { const headers = new Headers() getCookies(headers) }) -test('Cookie getCookie does not throw if headers is an instance of the global Headers class', { skip: !globalThis.Headers }, () => { +test('Cookie getCookie does not throw if headers is an instance of the global Headers class', { skip: !globalThis.Headers }, (t) => { const headers = new globalThis.Headers() getCookies(headers) }) -test('Cookie getSetCookies throws if headers is not of type Headers', () => { +test('Cookie getSetCookies throws if headers is not of type Headers', (t) => { class Headers { [Symbol.toStringTag] = 'CustomHeaders' } const headers = new Headers({ 'set-cookie': 'Space=Cat' }) - assert.throws( + t.assert.throws( () => { getSetCookies(headers) }, @@ -677,22 +676,22 @@ test('Cookie getSetCookies throws if headers is not of type Headers', () => { ) }) -test('Cookie getSetCookies does not throw if headers is an instance of undici owns Headers class', () => { +test('Cookie getSetCookies does not throw if headers is an instance of undici owns Headers class', (t) => { const headers = new Headers({ 'set-cookie': 'Space=Cat' }) getSetCookies(headers) }) -test('Cookie setCookie does not throw if headers is an instance of the global Headers class', { skip: !globalThis.Headers }, () => { +test('Cookie setCookie does not throw if headers is an instance of the global Headers class', { skip: !globalThis.Headers }, (t) => { const headers = new globalThis.Headers({ 'set-cookie': 'Space=Cat' }) getSetCookies(headers) }) -test('Cookie deleteCookie throws if headers is not of type Headers', () => { +test('Cookie deleteCookie throws if headers is not of type Headers', (t) => { class Headers { [Symbol.toStringTag] = 'CustomHeaders' } const headers = new Headers() - assert.throws( + t.assert.throws( () => { deleteCookie(headers, 'deno') }, @@ -700,12 +699,12 @@ test('Cookie deleteCookie throws if headers is not of type Headers', () => { ) }) -test('Cookie deleteCookie does not throw if headers is an instance of undici owns Headers class', () => { +test('Cookie deleteCookie does not throw if headers is an instance of undici owns Headers class', (t) => { const headers = new Headers() deleteCookie(headers, 'deno') }) -test('Cookie getCookie does not throw if headers is an instance of the global Headers class', { skip: !globalThis.Headers }, () => { +test('Cookie getCookie does not throw if headers is an instance of the global Headers class', { skip: !globalThis.Headers }, (t) => { const headers = new globalThis.Headers() deleteCookie(headers, 'deno') }) diff --git a/test/cookie/global-headers.js b/test/cookie/global-headers.js index ad9d8a14771..2f122320e22 100644 --- a/test/cookie/global-headers.js +++ b/test/cookie/global-headers.js @@ -1,7 +1,6 @@ 'use strict' const { describe, test } = require('node:test') -const assert = require('node:assert') const { deleteCookie, getCookies, @@ -9,24 +8,24 @@ const { setCookie } = require('../..') -describe('Using global Headers', async () => { - test('deleteCookies', { skip: !globalThis.Headers }, () => { +describe('Using global Headers', () => { + test('deleteCookies', { skip: !globalThis.Headers }, (t) => { const headers = new globalThis.Headers() - assert.equal(headers.get('set-cookie'), null) + t.assert.strictEqual(headers.get('set-cookie'), null) deleteCookie(headers, 'undici') - assert.equal(headers.get('set-cookie'), 'undici=; Expires=Thu, 01 Jan 1970 00:00:00 GMT') + t.assert.strictEqual(headers.get('set-cookie'), 'undici=; Expires=Thu, 01 Jan 1970 00:00:00 GMT') }) - test('getCookies', { skip: !globalThis.Headers }, () => { + test('getCookies', { skip: !globalThis.Headers }, (t) => { const headers = new globalThis.Headers({ cookie: 'get=cookies; and=attributes' }) - assert.deepEqual(getCookies(headers), { get: 'cookies', and: 'attributes' }) + t.assert.deepEqual(getCookies(headers), { get: 'cookies', and: 'attributes' }) }) - test('getSetCookies', { skip: !globalThis.Headers }, () => { + test('getSetCookies', { skip: !globalThis.Headers }, (t) => { const headers = new globalThis.Headers({ 'set-cookie': 'undici=getSetCookies; Secure' }) @@ -34,9 +33,9 @@ describe('Using global Headers', async () => { const supportsCookies = headers.getSetCookie() if (!supportsCookies) { - assert.deepEqual(getSetCookies(headers), []) + t.assert.deepEqual(getSetCookies(headers), []) } else { - assert.deepEqual(getSetCookies(headers), [ + t.assert.deepEqual(getSetCookies(headers), [ { name: 'undici', value: 'getSetCookies', @@ -46,23 +45,23 @@ describe('Using global Headers', async () => { } }) - test('setCookie', { skip: !globalThis.Headers }, () => { + test('setCookie', { skip: !globalThis.Headers }, (t) => { const headers = new globalThis.Headers() setCookie(headers, { name: 'undici', value: 'setCookie' }) - assert.equal(headers.get('Set-Cookie'), 'undici=setCookie') + t.assert.strictEqual(headers.get('Set-Cookie'), 'undici=setCookie') }) -}) -describe('Headers check is not too lax', { skip: !globalThis.Headers }, () => { - class Headers { } - Object.defineProperty(globalThis.Headers.prototype, Symbol.toStringTag, { - value: 'Headers', - configurable: true - }) + test('Headers check is not too lax', { skip: !globalThis.Headers }, (t) => { + class Headers { } + Object.defineProperty(globalThis.Headers.prototype, Symbol.toStringTag, { + value: 'Headers', + configurable: true + }) - assert.throws(() => getCookies(new Headers()), { code: 'ERR_INVALID_THIS' }) - assert.throws(() => getSetCookies(new Headers()), { code: 'ERR_INVALID_THIS' }) - assert.throws(() => setCookie(new Headers(), { name: 'a', value: 'b' }), { code: 'ERR_INVALID_THIS' }) - assert.throws(() => deleteCookie(new Headers(), 'name'), { code: 'ERR_INVALID_THIS' }) + t.assert.throws(() => getCookies(new Headers()), { code: 'ERR_INVALID_THIS' }) + t.assert.throws(() => getSetCookies(new Headers()), { code: 'ERR_INVALID_THIS' }) + t.assert.throws(() => setCookie(new Headers(), { name: 'a', value: 'b' }), { code: 'ERR_INVALID_THIS' }) + t.assert.throws(() => deleteCookie(new Headers(), 'name'), { code: 'ERR_INVALID_THIS' }) + }) }) diff --git a/test/cookie/is-ctl-excluding-htab.js b/test/cookie/is-ctl-excluding-htab.js index a9523326553..0110e4629a4 100644 --- a/test/cookie/is-ctl-excluding-htab.js +++ b/test/cookie/is-ctl-excluding-htab.js @@ -1,85 +1,84 @@ 'use strict' const { test, describe } = require('node:test') -const { strictEqual } = require('node:assert') const { isCTLExcludingHtab } = require('../../lib/web/cookies/util') describe('isCTLExcludingHtab', () => { - test('should return false for 0x00 - 0x08 characters', () => { - strictEqual(isCTLExcludingHtab('\x00'), true) - strictEqual(isCTLExcludingHtab('\x01'), true) - strictEqual(isCTLExcludingHtab('\x02'), true) - strictEqual(isCTLExcludingHtab('\x03'), true) - strictEqual(isCTLExcludingHtab('\x04'), true) - strictEqual(isCTLExcludingHtab('\x05'), true) - strictEqual(isCTLExcludingHtab('\x06'), true) - strictEqual(isCTLExcludingHtab('\x07'), true) - strictEqual(isCTLExcludingHtab('\x08'), true) + test('should return false for 0x00 - 0x08 characters', (t) => { + t.assert.strictEqual(isCTLExcludingHtab('\x00'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x01'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x02'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x03'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x04'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x05'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x06'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x07'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x08'), true) }) - test('should return false for 0x09 HTAB character', () => { - strictEqual(isCTLExcludingHtab('\x09'), false) + test('should return false for 0x09 HTAB character', (t) => { + t.assert.strictEqual(isCTLExcludingHtab('\x09'), false) }) - test('should return false for 0x0A - 0x1F characters', () => { - strictEqual(isCTLExcludingHtab('\x0A'), true) - strictEqual(isCTLExcludingHtab('\x0B'), true) - strictEqual(isCTLExcludingHtab('\x0C'), true) - strictEqual(isCTLExcludingHtab('\x0D'), true) - strictEqual(isCTLExcludingHtab('\x0E'), true) - strictEqual(isCTLExcludingHtab('\x0F'), true) - strictEqual(isCTLExcludingHtab('\x10'), true) - strictEqual(isCTLExcludingHtab('\x11'), true) - strictEqual(isCTLExcludingHtab('\x12'), true) - strictEqual(isCTLExcludingHtab('\x13'), true) - strictEqual(isCTLExcludingHtab('\x14'), true) - strictEqual(isCTLExcludingHtab('\x15'), true) - strictEqual(isCTLExcludingHtab('\x16'), true) - strictEqual(isCTLExcludingHtab('\x17'), true) - strictEqual(isCTLExcludingHtab('\x18'), true) - strictEqual(isCTLExcludingHtab('\x19'), true) - strictEqual(isCTLExcludingHtab('\x1A'), true) - strictEqual(isCTLExcludingHtab('\x1B'), true) - strictEqual(isCTLExcludingHtab('\x1C'), true) - strictEqual(isCTLExcludingHtab('\x1D'), true) - strictEqual(isCTLExcludingHtab('\x1E'), true) - strictEqual(isCTLExcludingHtab('\x1F'), true) + test('should return false for 0x0A - 0x1F characters', (t) => { + t.assert.strictEqual(isCTLExcludingHtab('\x0A'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x0B'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x0C'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x0D'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x0E'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x0F'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x10'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x11'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x12'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x13'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x14'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x15'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x16'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x17'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x18'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x19'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x1A'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x1B'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x1C'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x1D'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x1E'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x1F'), true) }) test('should return false for a 0x7F character', t => { - strictEqual(isCTLExcludingHtab('\x7F'), true) + t.assert.strictEqual(isCTLExcludingHtab('\x7F'), true) }) test('should return false for a 0x20 / space character', t => { - strictEqual(isCTLExcludingHtab(' '), false) + t.assert.strictEqual(isCTLExcludingHtab(' '), false) }) test('should return false for a printable character', t => { - strictEqual(isCTLExcludingHtab('A'), false) - strictEqual(isCTLExcludingHtab('Z'), false) - strictEqual(isCTLExcludingHtab('a'), false) - strictEqual(isCTLExcludingHtab('z'), false) - strictEqual(isCTLExcludingHtab('!'), false) + t.assert.strictEqual(isCTLExcludingHtab('A'), false) + t.assert.strictEqual(isCTLExcludingHtab('Z'), false) + t.assert.strictEqual(isCTLExcludingHtab('a'), false) + t.assert.strictEqual(isCTLExcludingHtab('z'), false) + t.assert.strictEqual(isCTLExcludingHtab('!'), false) }) - test('should return false for an empty string', () => { - strictEqual(isCTLExcludingHtab(''), false) + test('should return false for an empty string', (t) => { + t.assert.strictEqual(isCTLExcludingHtab(''), false) }) - test('all printable characters (0x20 - 0x7E)', () => { + test('all printable characters (0x20 - 0x7E)', (t) => { for (let i = 0x20; i < 0x7F; i++) { - strictEqual(isCTLExcludingHtab(String.fromCharCode(i)), false) + t.assert.strictEqual(isCTLExcludingHtab(String.fromCharCode(i)), false) } }) - test('valid case', () => { - strictEqual(isCTLExcludingHtab('Space=Cat; Secure; HttpOnly; Max-Age=2'), false) + test('valid case', (t) => { + t.assert.strictEqual(isCTLExcludingHtab('Space=Cat; Secure; HttpOnly; Max-Age=2'), false) }) - test('invalid case', () => { - strictEqual(isCTLExcludingHtab('Space=Cat; Secure; HttpOnly; Max-Age=2\x7F'), true) + test('invalid case', (t) => { + t.assert.strictEqual(isCTLExcludingHtab('Space=Cat; Secure; HttpOnly; Max-Age=2\x7F'), true) }) }) diff --git a/test/cookie/npm-cookie.js b/test/cookie/npm-cookie.js index 28e86c1d279..d6bc4e34a30 100644 --- a/test/cookie/npm-cookie.js +++ b/test/cookie/npm-cookie.js @@ -25,84 +25,83 @@ // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. const { describe, it } = require('node:test') -const assert = require('node:assert') const { parseCookie } = require('../..') -describe('parseCookie(str)', function () { - it('should parse cookie string to object', function () { - assert.deepStrictEqual(parseCookie('foo=bar'), { name: 'foo', value: 'bar' }) - assert.deepStrictEqual(parseCookie('foo=123'), { name: 'foo', value: '123' }) +describe('parseCookie(str)', () => { + it('should parse cookie string to object', (t) => { + t.assert.deepStrictEqual(parseCookie('foo=bar'), { name: 'foo', value: 'bar' }) + t.assert.deepStrictEqual(parseCookie('foo=123'), { name: 'foo', value: '123' }) }) - it('should ignore OWS', function () { - assert.deepStrictEqual(parseCookie('FOO = bar; baz = raz'), { + it('should ignore OWS', (t) => { + t.assert.deepStrictEqual(parseCookie('FOO = bar; baz = raz'), { name: 'FOO', value: 'bar', unparsed: ['baz=raz'] }) }) - it('should parse cookie with empty value', function () { - assert.deepStrictEqual(parseCookie('foo=; bar='), { name: 'foo', value: '', unparsed: ['bar='] }) + it('should parse cookie with empty value', (t) => { + t.assert.deepStrictEqual(parseCookie('foo=; bar='), { name: 'foo', value: '', unparsed: ['bar='] }) }) - it('should parse cookie with minimum length', function () { - assert.deepStrictEqual(parseCookie('f='), { name: 'f', value: '' }) - assert.deepStrictEqual(parseCookie('f=;b='), { name: 'f', value: '', unparsed: ['b='] }) + it('should parse cookie with minimum length', (t) => { + t.assert.deepStrictEqual(parseCookie('f='), { name: 'f', value: '' }) + t.assert.deepStrictEqual(parseCookie('f=;b='), { name: 'f', value: '', unparsed: ['b='] }) }) - it('should URL-decode values', function () { - assert.deepStrictEqual(parseCookie('foo="bar=123456789&name=Magic+Mouse"'), { + it('should URL-decode values', (t) => { + t.assert.deepStrictEqual(parseCookie('foo="bar=123456789&name=Magic+Mouse"'), { name: 'foo', value: '"bar=123456789&name=Magic+Mouse"' }) - assert.deepStrictEqual(parseCookie('email=%20%22%2c%3b%2f'), { name: 'email', value: ' ",;/' }) + t.assert.deepStrictEqual(parseCookie('email=%20%22%2c%3b%2f'), { name: 'email', value: ' ",;/' }) }) - it('should trim whitespace around key and value', function () { - assert.deepStrictEqual(parseCookie(' foo = "bar" '), { name: 'foo', value: '"bar"' }) - assert.deepStrictEqual(parseCookie(' foo = bar ; fizz = buzz '), { + it('should trim whitespace around key and value', (t) => { + t.assert.deepStrictEqual(parseCookie(' foo = "bar" '), { name: 'foo', value: '"bar"' }) + t.assert.deepStrictEqual(parseCookie(' foo = bar ; fizz = buzz '), { name: 'foo', value: 'bar', unparsed: ['fizz=buzz'] }) - assert.deepStrictEqual(parseCookie(' foo = " a b c " '), { name: 'foo', value: '" a b c "' }) - assert.deepStrictEqual(parseCookie(' = bar '), { name: '', value: 'bar' }) - assert.deepStrictEqual(parseCookie(' foo = '), { name: 'foo', value: '' }) - assert.deepStrictEqual(parseCookie(' = '), { name: '', value: '' }) - assert.deepStrictEqual(parseCookie('\tfoo\t=\tbar\t'), { name: 'foo', value: 'bar' }) + t.assert.deepStrictEqual(parseCookie(' foo = " a b c " '), { name: 'foo', value: '" a b c "' }) + t.assert.deepStrictEqual(parseCookie(' = bar '), { name: '', value: 'bar' }) + t.assert.deepStrictEqual(parseCookie(' foo = '), { name: 'foo', value: '' }) + t.assert.deepStrictEqual(parseCookie(' = '), { name: '', value: '' }) + t.assert.deepStrictEqual(parseCookie('\tfoo\t=\tbar\t'), { name: 'foo', value: 'bar' }) }) - it('should return original value on escape error', function () { - assert.deepStrictEqual(parseCookie('foo=%1;bar=bar'), { name: 'foo', value: '%1', unparsed: ['bar=bar'] }) + it('should return original value on escape error', (t) => { + t.assert.deepStrictEqual(parseCookie('foo=%1;bar=bar'), { name: 'foo', value: '%1', unparsed: ['bar=bar'] }) }) - it('should ignore cookies without value', function () { - assert.deepStrictEqual(parseCookie('foo=bar;fizz ; buzz'), { name: 'foo', value: 'bar', unparsed: ['fizz=', 'buzz='] }) - assert.deepStrictEqual(parseCookie(' fizz; foo= bar'), { name: '', value: 'fizz', unparsed: ['foo=bar'] }) + it('should ignore cookies without value', (t) => { + t.assert.deepStrictEqual(parseCookie('foo=bar;fizz ; buzz'), { name: 'foo', value: 'bar', unparsed: ['fizz=', 'buzz='] }) + t.assert.deepStrictEqual(parseCookie(' fizz; foo= bar'), { name: '', value: 'fizz', unparsed: ['foo=bar'] }) }) - it('should ignore duplicate cookies', function () { - assert.deepStrictEqual(parseCookie('foo=%1;bar=bar;foo=boo'), { + it('should ignore duplicate cookies', (t) => { + t.assert.deepStrictEqual(parseCookie('foo=%1;bar=bar;foo=boo'), { name: 'foo', value: '%1', unparsed: ['bar=bar', 'foo=boo'] }) - assert.deepStrictEqual(parseCookie('foo=false;bar=bar;foo=true'), { + t.assert.deepStrictEqual(parseCookie('foo=false;bar=bar;foo=true'), { name: 'foo', value: 'false', unparsed: ['bar=bar', 'foo=true'] }) - assert.deepStrictEqual(parseCookie('foo=;bar=bar;foo=boo'), { + t.assert.deepStrictEqual(parseCookie('foo=;bar=bar;foo=boo'), { name: 'foo', value: '', unparsed: ['bar=bar', 'foo=boo'] }) }) - it('should parse native properties', function () { - assert.deepStrictEqual(parseCookie('toString=foo;valueOf=bar'), { + it('should parse native properties', (t) => { + t.assert.deepStrictEqual(parseCookie('toString=foo;valueOf=bar'), { name: 'toString', unparsed: [ 'valueOf=bar' diff --git a/test/cookie/to-imf-date.js b/test/cookie/to-imf-date.js index 3e48360919d..6bafd8d7c60 100644 --- a/test/cookie/to-imf-date.js +++ b/test/cookie/to-imf-date.js @@ -1,21 +1,20 @@ 'use strict' const { test, describe } = require('node:test') -const { strictEqual } = require('node:assert') const { toIMFDate } = require('../../lib/web/cookies/util') describe('toIMFDate', () => { - test('should return the same as Date.prototype.toGMTString()', () => { + test('should return the same as Date.prototype.toGMTString()', (t) => { for (let i = 1; i <= 1e6; i *= 2) { const date = new Date(i) - strictEqual(toIMFDate(date), date.toGMTString()) + t.assert.strictEqual(toIMFDate(date), date.toGMTString()) } for (let i = 0; i <= 1e6; i++) { const date = new Date(Math.trunc(Math.random() * 8640000000000000)) - strictEqual(toIMFDate(date), date.toGMTString()) + t.assert.strictEqual(toIMFDate(date), date.toGMTString()) } }) }) diff --git a/test/cookie/validate-cookie-name.js b/test/cookie/validate-cookie-name.js index 32e4d9d2b66..b5a5a5bb925 100644 --- a/test/cookie/validate-cookie-name.js +++ b/test/cookie/validate-cookie-name.js @@ -1,130 +1,129 @@ '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 CTLs', (t) => { + t.assert.throws(() => validateCookieName('\x00'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x01'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x02'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x03'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x04'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x05'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x06'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x07'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x08'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x09'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x0A'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x0B'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x0C'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x0D'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x0E'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x0F'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x10'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x11'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x12'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x13'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x14'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x15'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x16'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x17'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x18'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x19'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x1A'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x1B'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x1C'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x1D'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x1E'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x1F'), new Error('Invalid cookie name')) + t.assert.throws(() => validateCookieName('\x7F'), new Error('Invalid cookie name')) }) - test('should throw for " " character', () => { - throws(() => validateCookieName(' '), new Error('Invalid cookie name')) + test('should throw for " " character', (t) => { + t.assert.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 Horizontal Tab character', (t) => { + t.assert.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', (t) => { + t.assert.throws(() => validateCookieName(';'), new Error('Invalid cookie name')) }) - test('should throw for " character', () => { - throws(() => validateCookieName('"'), new Error('Invalid cookie name')) + test('should throw for " character', (t) => { + t.assert.throws(() => validateCookieName('"'), new Error('Invalid cookie name')) }) - test('should throw for , character', () => { - throws(() => validateCookieName(','), new Error('Invalid cookie name')) + test('should throw for , character', (t) => { + t.assert.throws(() => validateCookieName(','), new Error('Invalid cookie name')) }) - test('should throw for \\ character', () => { - throws(() => validateCookieName('\\'), new Error('Invalid cookie name')) + test('should throw for \\ character', (t) => { + t.assert.throws(() => validateCookieName('\\'), new Error('Invalid cookie name')) }) - test('should throw for ( character', () => { - throws(() => validateCookieName('('), new Error('Invalid cookie name')) + test('should throw for ( character', (t) => { + t.assert.throws(() => validateCookieName('('), new Error('Invalid cookie name')) }) - test('should throw for ) character', () => { - throws(() => validateCookieName(')'), new Error('Invalid cookie name')) + test('should throw for ) character', (t) => { + t.assert.throws(() => validateCookieName(')'), new Error('Invalid cookie name')) }) - test('should throw for < character', () => { - throws(() => validateCookieName('<'), new Error('Invalid cookie name')) + test('should throw for < character', (t) => { + t.assert.throws(() => validateCookieName('<'), new Error('Invalid cookie name')) }) - test('should throw for > character', () => { - throws(() => validateCookieName('>'), new Error('Invalid cookie name')) + test('should throw for > character', (t) => { + t.assert.throws(() => validateCookieName('>'), new Error('Invalid cookie name')) }) - test('should throw for @ character', () => { - throws(() => validateCookieName('@'), new Error('Invalid cookie name')) + test('should throw for @ character', (t) => { + t.assert.throws(() => validateCookieName('@'), new Error('Invalid cookie name')) }) - test('should throw for : character', () => { - throws(() => validateCookieName(':'), new Error('Invalid cookie name')) + test('should throw for : character', (t) => { + t.assert.throws(() => validateCookieName(':'), new Error('Invalid cookie name')) }) - test('should throw for / character', () => { - throws(() => validateCookieName('/'), new Error('Invalid cookie name')) + test('should throw for / character', (t) => { + t.assert.throws(() => validateCookieName('/'), new Error('Invalid cookie name')) }) - test('should throw for [ character', () => { - throws(() => validateCookieName('['), new Error('Invalid cookie name')) + test('should throw for [ character', (t) => { + t.assert.throws(() => validateCookieName('['), new Error('Invalid cookie name')) }) - test('should throw for ] character', () => { - throws(() => validateCookieName(']'), new Error('Invalid cookie name')) + test('should throw for ] character', (t) => { + t.assert.throws(() => validateCookieName(']'), new Error('Invalid cookie name')) }) - test('should throw for ? character', () => { - throws(() => validateCookieName('?'), new Error('Invalid cookie name')) + test('should throw for ? character', (t) => { + t.assert.throws(() => validateCookieName('?'), new Error('Invalid cookie name')) }) - test('should throw for = character', () => { - throws(() => validateCookieName('='), new Error('Invalid cookie name')) + test('should throw for = character', (t) => { + t.assert.throws(() => validateCookieName('='), new Error('Invalid cookie name')) }) - test('should throw for { character', () => { - throws(() => validateCookieName('{'), new Error('Invalid cookie name')) + test('should throw for { character', (t) => { + t.assert.throws(() => validateCookieName('{'), new Error('Invalid cookie name')) }) - test('should throw for } character', () => { - throws(() => validateCookieName('}'), new Error('Invalid cookie name')) + test('should throw for } character', (t) => { + t.assert.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) + t.assert.strictEqual(validateCookieName('A'), undefined) + t.assert.strictEqual(validateCookieName('Z'), undefined) + t.assert.strictEqual(validateCookieName('a'), undefined) + t.assert.strictEqual(validateCookieName('z'), undefined) + t.assert.strictEqual(validateCookieName('!'), undefined) }) }) diff --git a/test/cookie/validate-cookie-path.js b/test/cookie/validate-cookie-path.js index bcca0d2fc87..5f0640482d8 100644 --- a/test/cookie/validate-cookie-path.js +++ b/test/cookie/validate-cookie-path.js @@ -1,59 +1,58 @@ 'use strict' const { test, describe } = require('node:test') -const { throws, strictEqual } = require('node:assert') const { validateCookiePath } = require('../../lib/web/cookies/util') describe('validateCookiePath', () => { - test('should throw for CTLs', () => { - throws(() => validateCookiePath('\x00')) - throws(() => validateCookiePath('\x01')) - throws(() => validateCookiePath('\x02')) - throws(() => validateCookiePath('\x03')) - throws(() => validateCookiePath('\x04')) - throws(() => validateCookiePath('\x05')) - throws(() => validateCookiePath('\x06')) - throws(() => validateCookiePath('\x07')) - throws(() => validateCookiePath('\x08')) - throws(() => validateCookiePath('\x09')) - throws(() => validateCookiePath('\x0A')) - throws(() => validateCookiePath('\x0B')) - throws(() => validateCookiePath('\x0C')) - throws(() => validateCookiePath('\x0D')) - throws(() => validateCookiePath('\x0E')) - throws(() => validateCookiePath('\x0F')) - throws(() => validateCookiePath('\x10')) - throws(() => validateCookiePath('\x11')) - throws(() => validateCookiePath('\x12')) - throws(() => validateCookiePath('\x13')) - throws(() => validateCookiePath('\x14')) - throws(() => validateCookiePath('\x15')) - throws(() => validateCookiePath('\x16')) - throws(() => validateCookiePath('\x17')) - throws(() => validateCookiePath('\x18')) - throws(() => validateCookiePath('\x19')) - throws(() => validateCookiePath('\x1A')) - throws(() => validateCookiePath('\x1B')) - throws(() => validateCookiePath('\x1C')) - throws(() => validateCookiePath('\x1D')) - throws(() => validateCookiePath('\x1E')) - throws(() => validateCookiePath('\x1F')) - throws(() => validateCookiePath('\x7F')) + test('should throw for CTLs', (t) => { + t.assert.throws(() => validateCookiePath('\x00')) + t.assert.throws(() => validateCookiePath('\x01')) + t.assert.throws(() => validateCookiePath('\x02')) + t.assert.throws(() => validateCookiePath('\x03')) + t.assert.throws(() => validateCookiePath('\x04')) + t.assert.throws(() => validateCookiePath('\x05')) + t.assert.throws(() => validateCookiePath('\x06')) + t.assert.throws(() => validateCookiePath('\x07')) + t.assert.throws(() => validateCookiePath('\x08')) + t.assert.throws(() => validateCookiePath('\x09')) + t.assert.throws(() => validateCookiePath('\x0A')) + t.assert.throws(() => validateCookiePath('\x0B')) + t.assert.throws(() => validateCookiePath('\x0C')) + t.assert.throws(() => validateCookiePath('\x0D')) + t.assert.throws(() => validateCookiePath('\x0E')) + t.assert.throws(() => validateCookiePath('\x0F')) + t.assert.throws(() => validateCookiePath('\x10')) + t.assert.throws(() => validateCookiePath('\x11')) + t.assert.throws(() => validateCookiePath('\x12')) + t.assert.throws(() => validateCookiePath('\x13')) + t.assert.throws(() => validateCookiePath('\x14')) + t.assert.throws(() => validateCookiePath('\x15')) + t.assert.throws(() => validateCookiePath('\x16')) + t.assert.throws(() => validateCookiePath('\x17')) + t.assert.throws(() => validateCookiePath('\x18')) + t.assert.throws(() => validateCookiePath('\x19')) + t.assert.throws(() => validateCookiePath('\x1A')) + t.assert.throws(() => validateCookiePath('\x1B')) + t.assert.throws(() => validateCookiePath('\x1C')) + t.assert.throws(() => validateCookiePath('\x1D')) + t.assert.throws(() => validateCookiePath('\x1E')) + t.assert.throws(() => validateCookiePath('\x1F')) + t.assert.throws(() => validateCookiePath('\x7F')) }) - test('should throw for ; character', () => { - throws(() => validateCookiePath(';')) + test('should throw for ; character', (t) => { + t.assert.throws(() => validateCookiePath(';')) }) test('should pass for a printable character', t => { - strictEqual(validateCookiePath('A'), undefined) - strictEqual(validateCookiePath('Z'), undefined) - strictEqual(validateCookiePath('a'), undefined) - strictEqual(validateCookiePath('z'), undefined) - strictEqual(validateCookiePath('!'), undefined) - strictEqual(validateCookiePath(' '), undefined) + t.assert.strictEqual(validateCookiePath('A'), undefined) + t.assert.strictEqual(validateCookiePath('Z'), undefined) + t.assert.strictEqual(validateCookiePath('a'), undefined) + t.assert.strictEqual(validateCookiePath('z'), undefined) + t.assert.strictEqual(validateCookiePath('!'), undefined) + t.assert.strictEqual(validateCookiePath(' '), undefined) }) }) diff --git a/test/cookie/validate-cookie-value.js b/test/cookie/validate-cookie-value.js index 7511121fb08..4ad6c3f0ca7 100644 --- a/test/cookie/validate-cookie-value.js +++ b/test/cookie/validate-cookie-value.js @@ -1,78 +1,77 @@ 'use strict' const { test, describe } = require('node:test') -const { throws, strictEqual } = require('node:assert') const { validateCookieValue } = require('../../lib/web/cookies/util') describe('validateCookieValue', () => { - test('should throw for CTLs', () => { - throws(() => validateCookieValue('\x00'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x01'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x02'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x03'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x04'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x05'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x06'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x07'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x08'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x09'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x0A'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x0B'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x0C'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x0D'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x0E'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x0F'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x10'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x11'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x12'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x13'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x14'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x15'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x16'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x17'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x18'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x19'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x1A'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x1B'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x1C'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x1D'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x1E'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x1F'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('\x7F'), new Error('Invalid cookie value')) + test('should throw for CTLs', (t) => { + t.assert.throws(() => validateCookieValue('\x00'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x01'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x02'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x03'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x04'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x05'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x06'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x07'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x08'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x09'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x0A'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x0B'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x0C'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x0D'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x0E'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x0F'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x10'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x11'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x12'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x13'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x14'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x15'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x16'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x17'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x18'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x19'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x1A'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x1B'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x1C'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x1D'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x1E'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x1F'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('\x7F'), new Error('Invalid cookie value')) }) - test('should throw for ; character', () => { - throws(() => validateCookieValue(';'), new Error('Invalid cookie value')) + test('should throw for ; character', (t) => { + t.assert.throws(() => validateCookieValue(';'), new Error('Invalid cookie value')) }) - test('should throw for " character', () => { - throws(() => validateCookieValue('"'), new Error('Invalid cookie value')) + test('should throw for " character', (t) => { + t.assert.throws(() => validateCookieValue('"'), new Error('Invalid cookie value')) }) - test('should throw for , character', () => { - throws(() => validateCookieValue(','), new Error('Invalid cookie value')) + test('should throw for , character', (t) => { + t.assert.throws(() => validateCookieValue(','), new Error('Invalid cookie value')) }) - test('should throw for \\ character', () => { - throws(() => validateCookieValue('\\'), new Error('Invalid cookie value')) + test('should throw for \\ character', (t) => { + t.assert.throws(() => validateCookieValue('\\'), new Error('Invalid cookie value')) }) test('should pass for a printable character', t => { - strictEqual(validateCookieValue('A'), undefined) - strictEqual(validateCookieValue('Z'), undefined) - strictEqual(validateCookieValue('a'), undefined) - strictEqual(validateCookieValue('z'), undefined) - strictEqual(validateCookieValue('!'), undefined) - strictEqual(validateCookieValue('='), undefined) + t.assert.strictEqual(validateCookieValue('A'), undefined) + t.assert.strictEqual(validateCookieValue('Z'), undefined) + t.assert.strictEqual(validateCookieValue('a'), undefined) + t.assert.strictEqual(validateCookieValue('z'), undefined) + t.assert.strictEqual(validateCookieValue('!'), undefined) + t.assert.strictEqual(validateCookieValue('='), undefined) }) test('should handle strings wrapped in DQUOTE', t => { - strictEqual(validateCookieValue('""'), undefined) - strictEqual(validateCookieValue('"helloworld"'), undefined) - throws(() => validateCookieValue('"'), new Error('Invalid cookie value')) - throws(() => validateCookieValue('"""'), new Error('Invalid cookie value')) + t.assert.strictEqual(validateCookieValue('""'), undefined) + t.assert.strictEqual(validateCookieValue('"helloworld"'), undefined) + t.assert.throws(() => validateCookieValue('"'), new Error('Invalid cookie value')) + t.assert.throws(() => validateCookieValue('"""'), new Error('Invalid cookie value')) }) })