|
| 1 | +import { SESSION_STORE_KEY, SESSION_TIME_OUT_DELAY } from '@datadog/browser-core' |
1 | 2 | import { RecordType } from '@datadog/browser-rum/src/types' |
2 | 3 | import { test, expect } from '@playwright/test' |
| 4 | +import { setCookie } from '../../lib/helpers/browser' |
3 | 5 | import { expireSession, findSessionCookie, renewSession } from '../../lib/helpers/session' |
4 | 6 | import { createTest, waitForRequests } from '../../lib/framework' |
5 | 7 |
|
@@ -165,6 +167,39 @@ test.describe('rum sessions', () => { |
165 | 167 | }) |
166 | 168 | }) |
167 | 169 |
|
| 170 | + test.describe('session cookie alteration', () => { |
| 171 | + createTest('after cookie is altered to isExpired, a user interaction starts a new session with a new anonymous id') |
| 172 | + .withRum() |
| 173 | + .run(async ({ flushEvents, browserContext, page }) => { |
| 174 | + const initialCookie = await findSessionCookie(browserContext) |
| 175 | + const initialSessionId = initialCookie?.id |
| 176 | + const initialAid = initialCookie?.aid |
| 177 | + |
| 178 | + expect(initialSessionId).toBeDefined() |
| 179 | + expect(initialAid).toBeDefined() |
| 180 | + |
| 181 | + // Simulate cookie being altered to isExpired=1 without preserving aid |
| 182 | + await setCookie(page, SESSION_STORE_KEY, 'isExpired=1', SESSION_TIME_OUT_DELAY) |
| 183 | + |
| 184 | + // Cookies are cached for 1s, wait until the cache expires |
| 185 | + await page.waitForTimeout(1100) |
| 186 | + |
| 187 | + await page.locator('html').click() |
| 188 | + |
| 189 | + // The session is not created right away, let's wait until we see a cookie |
| 190 | + await page.waitForTimeout(1000) |
| 191 | + |
| 192 | + await flushEvents() |
| 193 | + |
| 194 | + const newCookie = await findSessionCookie(browserContext) |
| 195 | + expect(newCookie?.isExpired).not.toEqual('1') |
| 196 | + expect(newCookie?.id).toBeDefined() |
| 197 | + expect(newCookie?.id).not.toEqual(initialSessionId) |
| 198 | + expect(newCookie?.aid).toBeDefined() |
| 199 | + expect(newCookie?.aid).not.toEqual(initialAid) |
| 200 | + }) |
| 201 | + }) |
| 202 | + |
168 | 203 | test.describe('third party cookie clearing', () => { |
169 | 204 | createTest('after a 3rd party clears the cookies, do not restart a session on user interaction') |
170 | 205 | .withRum() |
|
0 commit comments