Skip to content
Myr

fix(helper/cookie): make default `Path=/` for `setCookie()`/`setSignedCookie()` (#1742)

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

* fix(helper/cookie): make default `path` as `/` for `setCookie()`/`setSignedCookie()` * denoify * fixed test

authored by Yusuke Wada · committed by GitHub · parent c3275ee · Browse files · 4 files+42 added−11 removed
This commit

State

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

Diff stats

4 files+42 added−11 removed

  • tests:+38 added−7 removed
  • other:+4 added−4 removed

4 files+42 added−11 removed

modified:deno_dist/helper/cookie/index.ts+2 added-2 removed
modified:runtime_tests/lambda/index.test.ts+2 added-2 removed
93 unmodified lines
94 const testCookie1 = {95 key: 'id',96 value: crypto.randomUUID(),97 get serialized() {98 return `${this.key}=${this.value}`98 return `${this.key}=${this.value}; Path=/`99 },100 }101 const testCookie2 = {102 key: 'secret',103 value: crypto.randomUUID(),104 get serialized() {105 return `${this.key}=${this.value}`105 return `${this.key}=${this.value}; Path=/`106 },107 }108109 app.post('/cookie', (c) => {
440 unmodified lines
modified:src/helper/cookie/index.test.ts+36 added-5 removed
146 unmodified lines
147 it('Set cookie with setCookie()', async () => {148 const res = await app.request('http://localhost/set-cookie')149 expect(res.status).toBe(200)150 const header = res.headers.get('Set-Cookie')151 expect(header).toBe('delicious_cookie=macha')151 expect(header).toBe('delicious_cookie=macha; Path=/')152 })153154 app.get('/a/set-cookie-path', (c) => {155 setCookie(c, 'delicious_cookie', 'macha', { path: '/a' })156 return c.text('Give cookie')157 })158159 it('Set cookie with setCookie() and path option', async () => {160 const res = await app.request('http://localhost/a/set-cookie-path')161 expect(res.status).toBe(200)162 const header = res.headers.get('Set-Cookie')163 expect(header).toBe('delicious_cookie=macha; Path=/a')164 })165166 app.get('/set-signed-cookie', async (c) => {167 const secret = 'secret chocolate chips'168 await setSignedCookie(c, 'delicious_cookie', 'macha', secret)169 return c.text('Give signed cookie')
2 unmodified lines
172 it('Set signed cookie with setSignedCookie()', async () => {173 const res = await app.request('http://localhost/set-signed-cookie')174 expect(res.status).toBe(200)175 const header = res.headers.get('Set-Cookie')164 expect(header).toBe('delicious_cookie=macha.diubJPY8O7hI1pLa42QSfkPiyDWQ0I4DnlACH%2FN2HaA%3D')176 expect(header).toBe(177 'delicious_cookie=macha.diubJPY8O7hI1pLa42QSfkPiyDWQ0I4DnlACH%2FN2HaA%3D; Path=/'178 )179 })180181 app.get('/a/set-signed-cookie-path', async (c) => {182 const secret = 'secret chocolate chips'183 await setSignedCookie(c, 'delicious_cookie', 'macha', secret, { path: '/a' })184 return c.text('Give signed cookie')185 })186187 it('Set signed cookie with setSignedCookie() and path option', async () => {188 const res = await app.request('http://localhost/a/set-signed-cookie-path')189 expect(res.status).toBe(200)190 const header = res.headers.get('Set-Cookie')191 expect(header).toBe(192 'delicious_cookie=macha.diubJPY8O7hI1pLa42QSfkPiyDWQ0I4DnlACH%2FN2HaA%3D; Path=/a'193 )194 })195196 app.get('/set-cookie-complex', (c) => {197 setCookie(c, 'great_cookie', 'banana', {198 path: '/',199 secure: true,
47 unmodified lines
247 it('Multiple values', async () => {248 const res = await app.request('http://localhost/set-cookie-multiple')249 expect(res.status).toBe(200)250 const header = res.headers.get('Set-Cookie')222 expect(header).toBe('delicious_cookie=macha, delicious_cookie=choco')251 expect(header).toBe('delicious_cookie=macha; Path=/, delicious_cookie=choco; Path=/')252 })253 })254255 describe('Delete cookie', () => {
7 unmodified lines
263 it('Delete cookie', async () => {264 const res2 = await app.request('http://localhost/delete-cookie')265 expect(res2.status).toBe(200)266 const header2 = res2.headers.get('Set-Cookie')238 expect(header2).toBe('delicious_cookie=; Max-Age=0')267 expect(header2).toBe('delicious_cookie=; Max-Age=0; Path=/')268 })269270 app.get('/delete-cookie-multiple', (c) => {271 deleteCookie(c, 'delicious_cookie')
4 unmodified lines
276 it('Delete multiple cookies', async () => {277 const res2 = await app.request('http://localhost/delete-cookie-multiple')278 expect(res2.status).toBe(200)279 const header2 = res2.headers.get('Set-Cookie')251 expect(header2).toBe('delicious_cookie=; Max-Age=0, delicious_cookie2=; Max-Age=0')280 expect(header2).toBe(281 'delicious_cookie=; Max-Age=0; Path=/, delicious_cookie2=; Max-Age=0; Path=/'282 )283 })284285 app.get('/delete-cookie-with-options', (c) => {286 deleteCookie(c, 'delicious_cookie', {
15 unmodified lines
modified:src/helper/cookie/index.ts+2 added-2 removed