Skip to content
Myr

feat(utils/cookie): Ability to set a priority to cookies in setCookie options (#3762)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Update cookie.ts * Integrated `priority` option into setCookie serialization tests

authored by Beyondo · committed by GitHub · parent efc8a46 · Browse files · 2 files+11 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+11 added−3 removed

  • tests:+6 added−3 removed
  • other:+5 added−0 removed

2 files+11 added−3 removed

modified:src/utils/cookie.test.ts+6 added-3 removed
168 unmodified lines
169 httpOnly: true,170 maxAge: 1000,171 expires: new Date(Date.UTC(2000, 11, 24, 10, 30, 59, 900)),172 sameSite: 'Strict',173 priority: 'High',174 partitioned: true,175 })176 expect(serialized).toBe(176 '__Secure-great_cookie=banana; Max-Age=1000; Domain=example.com; Path=/; Expires=Sun, 24 Dec 2000 10:30:59 GMT; HttpOnly; Secure; SameSite=Strict; Partitioned'177 '__Secure-great_cookie=banana; Max-Age=1000; Domain=example.com; Path=/; Expires=Sun, 24 Dec 2000 10:30:59 GMT; HttpOnly; Secure; SameSite=Strict; Priority=High; Partitioned'178 )179 })180181 it('Should serialize __Host- cookie with all valid options', () => {
3 unmodified lines
185 httpOnly: true,186 maxAge: 1000,187 expires: new Date(Date.UTC(2000, 11, 24, 10, 30, 59, 900)),188 sameSite: 'Strict',189 priority: 'High',190 partitioned: true,191 })192 expect(serialized).toBe(191 '__Host-great_cookie=banana; Max-Age=1000; Path=/; Expires=Sun, 24 Dec 2000 10:30:59 GMT; HttpOnly; Secure; SameSite=Strict; Partitioned'193 '__Host-great_cookie=banana; Max-Age=1000; Path=/; Expires=Sun, 24 Dec 2000 10:30:59 GMT; HttpOnly; Secure; SameSite=Strict; Priority=High; Partitioned'194 )195 })196197 it('Should serialize a signed cookie', async () => {
13 unmodified lines
211 httpOnly: true,212 maxAge: 1000,213 expires: new Date(Date.UTC(2000, 11, 24, 10, 30, 59, 900)),214 sameSite: 'Strict',215 priority: 'High',216 partitioned: true,217 })218 expect(serialized).toBe(216 'great_cookie=banana.hSo6gB7YT2db0WBiEAakEmh7dtwEL0DSp76G23WvHuQ%3D; Max-Age=1000; Domain=example.com; Path=/; Expires=Sun, 24 Dec 2000 10:30:59 GMT; HttpOnly; Secure; SameSite=Strict; Partitioned'219 'great_cookie=banana.hSo6gB7YT2db0WBiEAakEmh7dtwEL0DSp76G23WvHuQ%3D; Max-Age=1000; Domain=example.com; Path=/; Expires=Sun, 24 Dec 2000 10:30:59 GMT; HttpOnly; Secure; SameSite=Strict; Priority=High; Partitioned'220 )221 })222223 it('Should serialize cookie with maxAge is 0', () => {
43 unmodified lines
modified:src/utils/cookie.ts+5 added
22 unmodified lines
23 secure?: boolean24 signingSecret?: string25 sameSite?: 'Strict' | 'Lax' | 'None' | 'strict' | 'lax' | 'none'26 partitioned?: boolean27 priority?: 'Low' | 'Medium' | 'High'28 prefix?: CookiePrefixOptions29} & PartitionedCookieConstraint30export type CookiePrefixOptions = 'host' | 'secure'31
172 unmodified lines
204 if (opt.sameSite) {205 cookie += `; SameSite=${opt.sameSite.charAt(0).toUpperCase() + opt.sameSite.slice(1)}`206 }207208 if (opt.priority) {209 cookie += `; Priority=${opt.priority}`210 }211212 if (opt.partitioned) {213 // FIXME: replace link to RFC214 // https://www.ietf.org/archive/id/draft-cutler-httpbis-partitioned-cookies-01.html#section-2.3215 if (!opt.secure) {
28 unmodified lines