Consent compliance: docs, agent guide, skills, changelog, shared behaviour spec, browser check, reference e2e
- docs/consent.md: compliance defaults, Global Privacy Control, withdrawal, consent log on by default and the SQL migration; no more "UODO requirement" or "GPC not needed". docs/analytics.md: what Consent Mode advanced sends. - docs/consent-behaviour-spec.md: the behaviour IAPL and IAWL share, with the 13-item test list. - CHANGELOG 1.17.0: the SQL migration first, a before → after table for an existing site. - AGENT.md, iapl-setup / iapl-upgrade / iapl-reference / iapl-consent-check, PROGRAMISTA item 78; reference skills copy. - iapl-consent-check: Global Privacy Control, equal prominence and withdrawal runs; Google asset warnings. - Reference site uses the new defaults; e2e for GPC, a stale grant, equal prominence, withdrawal; e2e:built runs every consent test in both bundlers. YouTubeEmbed warns in development without a poster. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
99036eb70c
commit
f5c53e4523
@@ -385,6 +385,114 @@ test('consent: a click on the banner before the page has hydrated is not lost',
|
||||
expect((await context.cookies()).some((c) => c.name === 'cookie-consent')).toBe(true)
|
||||
})
|
||||
|
||||
// Consent compliance (1.17.0, docs/consent-behaviour-spec.md): Global Privacy Control, equal prominence, withdrawal.
|
||||
const withGpc = async (browser: import('@playwright/test').Browser, baseURL?: string) => {
|
||||
const context = await browser.newContext({ baseURL, extraHTTPHeaders: { 'Sec-GPC': '1' } })
|
||||
await context.addInitScript(() => Object.defineProperty(Navigator.prototype, 'globalPrivacyControl', { configurable: true, get: () => true }))
|
||||
return context
|
||||
}
|
||||
const consentRecord = async (context: import('@playwright/test').BrowserContext) => {
|
||||
const c = (await context.cookies()).find((x) => x.name === 'cookie-consent')
|
||||
return c ? (JSON.parse(decodeURIComponent(c.value)) as { gpc?: boolean; id: string; state: Record<string, boolean>; version: number }) : null
|
||||
}
|
||||
|
||||
test('consent: Global Privacy Control — no banner from the first paint, nothing stored, the same static HTML; opting in from the button wins', async ({ baseURL, browser, request }) => {
|
||||
const plain = await request.get('/pl')
|
||||
const signalled = await request.get('/pl', { headers: { 'Sec-GPC': '1' } })
|
||||
// the server never renders differently for the signal: one static page, no Vary on it
|
||||
const strip = (html: string) => html.replace(/ nonce="[^"]*"/g, '')
|
||||
expect(strip(await signalled.text())).toBe(strip(await plain.text()))
|
||||
expect(signalled.headers()['cache-control']).toMatch(/s-maxage=\d+/)
|
||||
expect(signalled.headers().vary ?? '').not.toMatch(/sec-gpc/i)
|
||||
|
||||
const context = await withGpc(browser, baseURL)
|
||||
const page = await context.newPage()
|
||||
const errors: string[] = []
|
||||
page.on('console', (m) => m.type() === 'error' && errors.push(m.text()))
|
||||
const trackers: string[] = []
|
||||
page.on('request', (r) => /googletagmanager|google-analytics|facebook|clarity\.ms|licdn|tiktok|doubleclick/.test(r.url()) && trackers.push(r.url()))
|
||||
await page.addInitScript(watchBanner)
|
||||
await page.goto('/pl')
|
||||
await expect(page.locator('[data-ipal="cookie-button"]')).toBeVisible()
|
||||
await expect(page.locator('[data-ipal="banner"]')).toHaveCount(0)
|
||||
expect(await page.evaluate(() => (window as unknown as { __bannerFrames: number }).__bannerFrames)).toBe(0)
|
||||
expect(await consentRecord(context)).toBeNull()
|
||||
expect(trackers).toEqual([])
|
||||
|
||||
// the visitor opens the settings: the line about the signal; "Accept all" there is their own choice for this site
|
||||
await page.locator('[data-ipal="cookie-button"]').click()
|
||||
await expect(page.locator('[data-ipal="gpc-notice"]').first()).toContainText('Global Privacy Control')
|
||||
const logged = page.waitForResponse((r) => r.url().endsWith('/api/ipal/consent') && r.request().method() === 'POST')
|
||||
await page.locator('[data-ipal="banner"] [data-ipal="accept"]').click()
|
||||
expect((await logged).status()).toBe(201)
|
||||
expect(await consentRecord(context)).toMatchObject({ gpc: true, state: { analytics: true, marketing: true } })
|
||||
await page.goto('/en')
|
||||
await expect(page.locator('[data-ipal="banner"]')).toHaveCount(0)
|
||||
expect((await consentRecord(context))!.state.analytics).toBe(true)
|
||||
expect(errors).toEqual([])
|
||||
await context.close()
|
||||
})
|
||||
|
||||
test('consent: the signal appears after an "Accept" made without it — analytics and marketing go off, the cookies with them', async ({ baseURL, browser, context, page }) => {
|
||||
await page.goto('/pl')
|
||||
await page.locator('[data-ipal="banner"] [data-ipal="accept"]').click()
|
||||
await expect(page.locator('[data-ipal="cookie-button"]')).toBeVisible()
|
||||
const record = (await consentRecord(context))!
|
||||
expect(record).toMatchObject({ gpc: false, state: { analytics: true, marketing: true } })
|
||||
const consent = (await context.cookies()).find((c) => c.name === 'cookie-consent')!
|
||||
|
||||
const gpc = await withGpc(browser, baseURL)
|
||||
const host = new URL(baseURL!).hostname
|
||||
await gpc.addCookies([{ ...consent }, { domain: host, name: '_ga', path: '/', value: 'GA1.1.1' }, { domain: host, name: '_fbp', path: '/', value: 'fb.1' }])
|
||||
const p = await gpc.newPage()
|
||||
const logged = p.waitForResponse((r) => r.url().endsWith('/api/ipal/consent') && r.request().method() === 'POST')
|
||||
await p.goto('/pl')
|
||||
expect((await logged).status()).toBe(201)
|
||||
const after = (await consentRecord(gpc))!
|
||||
expect(after).toMatchObject({ gpc: true, id: record.id, state: { analytics: false, functional: true, marketing: false } })
|
||||
const names = (await gpc.cookies()).map((c) => c.name)
|
||||
expect(names).not.toContain('_ga')
|
||||
expect(names).not.toContain('_fbp')
|
||||
await expect(p.locator('[data-ipal="banner"]')).toHaveCount(0)
|
||||
await gpc.close()
|
||||
})
|
||||
|
||||
for (const l of LOCALES) {
|
||||
test(`${l.code}: consent — "Reject" is as prominent as "Accept all" (same element, size and look)`, async ({ page }) => {
|
||||
for (const size of [{ height: 640, width: 360 }, { height: 800, width: 1280 }]) {
|
||||
await page.setViewportSize(size)
|
||||
await page.goto(l.home)
|
||||
const look = await page.evaluate(() => {
|
||||
const pick = (sel: string) => {
|
||||
const el = document.querySelector<HTMLElement>(sel)!
|
||||
const cs = getComputedStyle(el)
|
||||
const r = el.getBoundingClientRect()
|
||||
return { bg: cs.backgroundColor, color: cs.color, fontSize: cs.fontSize, fontWeight: cs.fontWeight, height: Math.round(r.height), padding: cs.padding, radius: cs.borderRadius, tag: el.tagName, visible: r.bottom <= innerHeight && r.top >= 0 }
|
||||
}
|
||||
return { accept: pick('[data-ipal="banner"] [data-ipal="accept"]'), reject: pick('[data-ipal="banner"] [data-ipal="reject"]') }
|
||||
})
|
||||
expect(look.reject, `${size.width}px`).toEqual(look.accept)
|
||||
expect(look.reject.tag).toBe('BUTTON')
|
||||
expect(look.reject.visible).toBe(true)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
test('consent: withdrawal — reopen, reject: analytics cookies and listed storage keys go, the record says so', async ({ context, page }) => {
|
||||
await page.goto('/pl')
|
||||
await page.locator('[data-ipal="banner"] [data-ipal="accept"]').click()
|
||||
const host = new URL(page.url()).hostname
|
||||
await context.addCookies([{ domain: host, name: '_ga', path: '/', value: 'GA1.1.1' }, { domain: host, name: '_ga_TEST', path: '/', value: '1' }])
|
||||
await page.reload()
|
||||
await page.locator('[data-ipal="cookie-button"]').click()
|
||||
const logged = page.waitForResponse((r) => r.url().endsWith('/api/ipal/consent') && r.request().method() === 'POST')
|
||||
await page.locator('[data-ipal="banner"] [data-ipal="reject"]').click()
|
||||
expect((await logged).status()).toBe(201)
|
||||
const names = (await context.cookies()).map((c) => c.name)
|
||||
expect(names.filter((n) => n.startsWith('_ga'))).toEqual([])
|
||||
expect((await consentRecord(context))!.state).toMatchObject({ analytics: false, functional: false, marketing: false })
|
||||
})
|
||||
|
||||
test('admin: sign in through 2FA, agency credit, panel link preview', async ({ page, request }) => {
|
||||
const head = await (await request.get('/admin/login')).text()
|
||||
expect(head).toMatch(/noindex/)
|
||||
|
||||
Reference in New Issue
Block a user