'use strict'; // Reproduces a user with a STALE/invalid session cookie and confirms the app // now redirects to login gracefully instead of dead-ending on 401 errors. const { chromium } = require('playwright'); const BASE = 'http://localhost:3000'; (async () => { const browser = await chromium.launch({ channel: 'msedge', headless: true }); const log = []; async function scenario(name, urlPath, setBadCookie) { const context = await browser.newContext(); if (setBadCookie) { await context.addCookies([ { name: 'connect.sid', value: 's%3Abogus-stale-session-id.signature', url: BASE }, ]); } const page = await context.newPage(); const errs = []; page.on('console', (m) => { if (m.type() === 'error') errs.push(m.text()); }); page.on('pageerror', (e) => errs.push('pageerror: ' + e.message)); await page.goto(`${BASE}${urlPath}`, { waitUntil: 'networkidle' }); await page.waitForTimeout(800); log.push(`\n=== ${name} ===`); log.push(` start: ${urlPath} (badCookie=${!!setBadCookie})`); log.push(` ended on: ${page.url()}`); log.push(` console errors: ${errs.length ? errs.join(' | ') : 'none'}`); await context.close(); } await scenario('Stale cookie visits /', '/', true); await scenario('Stale cookie opens /admin.html directly', '/admin.html', true); await scenario('No session opens /admin.html directly', '/admin.html', false); console.log(log.join('\n')); await browser.close(); })().catch((e) => { console.error('SCRIPT ERROR:', e); process.exit(1); });