diff options
author | Yasser A.Idrissi <spookyframework@gmail.com> | 2020-11-17 21:06:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-17 21:06:06 +0100 |
commit | f7afe2b78f39fb635991a638885052108741727d (patch) | |
tree | ea862aee05b3066e11a8206c759b995d7c51212a /std/http/cookie_test.ts | |
parent | 4e99d8fb6f0c7e2b112e57c6664d9bc352806284 (diff) |
feat(std/http): Check if cookie property is valid (#7189)
Co-authored-by: Nayeem Rahman <nayeemrmn99@gmail.com>
Diffstat (limited to 'std/http/cookie_test.ts')
-rw-r--r-- | std/http/cookie_test.ts | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/std/http/cookie_test.ts b/std/http/cookie_test.ts index 0f7c68635..0f42a9381 100644 --- a/std/http/cookie_test.ts +++ b/std/http/cookie_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { Response, ServerRequest } from "./server.ts"; import { deleteCookie, getCookies, setCookie } from "./cookie.ts"; -import { assert, assertEquals } from "../testing/asserts.ts"; +import { assert, assertEquals, assertThrows } from "../testing/asserts.ts"; Deno.test({ name: "Cookie parser", @@ -32,6 +32,40 @@ Deno.test({ }); Deno.test({ + name: "Cookie Name Validation", + fn(): void { + const res: Response = {}; + const tokens = [ + '"id"', + "id\t", + "i\td", + "i d", + "i;d", + "{id}", + "[id]", + '"', + "id\u0091", + ]; + res.headers = new Headers(); + tokens.forEach((name) => { + assertThrows( + (): void => { + setCookie(res, { + name, + value: "Cat", + httpOnly: true, + secure: true, + maxAge: 3, + }); + }, + Error, + 'Invalid cookie name: "' + name + '".', + ); + }); + }, +}); + +Deno.test({ name: "Cookie Delete", fn(): void { const res: Response = {}; |