diff --git a/tests/private-redirect.test.ts b/tests/private-redirect.test.ts index 2681f1f..6ff8ba7 100644 --- a/tests/private-redirect.test.ts +++ b/tests/private-redirect.test.ts @@ -187,6 +187,16 @@ async function userSession(token: string, userId: string): Promise { }; } +function expectPrivateNoStoreHeaders(response: Response): void { + expect(response.headers.get('cache-control')).toBe('no-store'); + expect( + response.headers + .get('vary') + ?.split(',') + .map((value) => value.trim().toLowerCase()), + ).toContain('cookie'); +} + describe('my.heygo.cc private shortlinks', () => { it('returns 404 with a login link when unauthenticated', async () => { const { response, db } = await fetchWorker('https://my.heygo.cc/foo', { @@ -207,6 +217,7 @@ describe('my.heygo.cc private shortlinks', () => { expect(response.status).toBe(404); expect(response.headers.get('content-type')).toContain('text/html'); + expectPrivateNoStoreHeaders(response); const body = await response.text(); expect(body).toContain('Login to use your private links'); expect(body).toContain('https://heygo.cc/app/login'); @@ -237,6 +248,7 @@ describe('my.heygo.cc private shortlinks', () => { expect(response.status).toBe(302); expect(response.headers.get('location')).toBe('https://example.com/foo-a'); + expectPrivateNoStoreHeaders(response); expect(ctx.promises).toHaveLength(1); await Promise.all(ctx.promises); expect(db.runCalls).toHaveLength(1); @@ -324,6 +336,7 @@ describe('my.heygo.cc private shortlinks', () => { }); expect(response.status).toBe(404); + expectPrivateNoStoreHeaders(response); const body = await response.text(); expect(body).toContain('Create this private link'); // Must never query the public scope on my.heygo.cc. @@ -353,6 +366,7 @@ describe('my.heygo.cc private shortlinks', () => { expect(response.status).toBe(200); expect(response.headers.get('content-type')).toContain('text/html'); + expectPrivateNoStoreHeaders(response); const html = await response.text(); expect(html).toContain('Private Note'); expect(html).not.toContain('