Fix CI auth: inject token via localStorage + document.cookie
Some checks failed
CI/CD / detect-changes (pull_request) Successful in 4s
CI/CD / test-frontend (pull_request) Successful in 5s
CI/CD / e2e-smoke (pull_request) Failing after 1m31s
CI/CD / test-runners (pull_request) Failing after 2m40s
CI/CD / test-go-pg (pull_request) Successful in 3m17s
CI/CD / test-sqlite (pull_request) Successful in 3m27s
CI/CD / build-and-deploy (pull_request) Has been skipped
Some checks failed
CI/CD / detect-changes (pull_request) Successful in 4s
CI/CD / test-frontend (pull_request) Successful in 5s
CI/CD / e2e-smoke (pull_request) Failing after 1m31s
CI/CD / test-runners (pull_request) Failing after 2m40s
CI/CD / test-go-pg (pull_request) Successful in 3m17s
CI/CD / test-sqlite (pull_request) Successful in 3m27s
CI/CD / build-and-deploy (pull_request) Has been skipped
Playwright's addCookies (both domain-based and url-based) fails to send SameSite=Strict cookies in Docker DNS environments. The server middleware reads arm_token from cookies, but the cookie is originally set by client-side JS (document.cookie with SameSite=Strict). New approach: navigate to /login first, then inject the token into localStorage (key: arm_auth) and set the cookie via document.cookie in page context — exactly how the real login flow works. This ensures the cookie attributes match what the server expects. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -97,19 +97,28 @@ async function discoverSurfaces(page) {
|
|||||||
const browser = await chromium.launch({ headless: true });
|
const browser = await chromium.launch({ headless: true });
|
||||||
const context = await browser.newContext();
|
const context = await browser.newContext();
|
||||||
|
|
||||||
// Set auth cookie — use url instead of domain for reliable matching
|
|
||||||
await context.addCookies([{
|
|
||||||
name: 'arm_token',
|
|
||||||
value: TOKEN,
|
|
||||||
url: SERVER,
|
|
||||||
}]);
|
|
||||||
|
|
||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
|
|
||||||
|
// ── Authenticate via page context ─────────
|
||||||
|
// Navigate to login first, then inject tokens into localStorage
|
||||||
|
// and set the arm_token cookie via JS — same mechanism the login
|
||||||
|
// page uses. Playwright's addCookies doesn't reliably work with
|
||||||
|
// SameSite=Strict cookies in Docker DNS environments.
|
||||||
|
console.log('Setting up auth...');
|
||||||
|
await page.goto(SERVER + '/login', { waitUntil: 'networkidle', timeout: 30000 });
|
||||||
|
await page.evaluate((token) => {
|
||||||
|
localStorage.setItem('arm_auth', JSON.stringify({
|
||||||
|
accessToken: token,
|
||||||
|
refreshToken: token,
|
||||||
|
user: null,
|
||||||
|
cookieMaxAge: 604800,
|
||||||
|
}));
|
||||||
|
document.cookie = `arm_token=${token}; path=/; max-age=604800; SameSite=Strict`;
|
||||||
|
}, TOKEN);
|
||||||
|
|
||||||
// ── Discover surfaces ─────────────────────
|
// ── Discover surfaces ─────────────────────
|
||||||
console.log('Discovering surfaces...');
|
console.log('Discovering surfaces...');
|
||||||
|
|
||||||
// Navigate to a page first so cookies are sent with API call
|
|
||||||
await page.goto(SERVER + '/admin', { waitUntil: 'networkidle', timeout: 30000 });
|
await page.goto(SERVER + '/admin', { waitUntil: 'networkidle', timeout: 30000 });
|
||||||
|
|
||||||
const surfaces = await discoverSurfaces(page);
|
const surfaces = await discoverSurfaces(page);
|
||||||
|
|||||||
@@ -33,16 +33,23 @@ if (!TOKEN) {
|
|||||||
const browser = await chromium.launch({ headless: true });
|
const browser = await chromium.launch({ headless: true });
|
||||||
const context = await browser.newContext();
|
const context = await browser.newContext();
|
||||||
|
|
||||||
// Set auth cookie — use url instead of domain for reliable matching
|
|
||||||
// in Docker/CI where hostname is a Docker DNS name (e.g. "armature")
|
|
||||||
await context.addCookies([{
|
|
||||||
name: 'arm_token',
|
|
||||||
value: TOKEN,
|
|
||||||
url: SERVER,
|
|
||||||
}]);
|
|
||||||
|
|
||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
|
|
||||||
|
// Authenticate via page context — inject tokens into localStorage
|
||||||
|
// and set the arm_token cookie via JS. Playwright's addCookies
|
||||||
|
// doesn't reliably work with SameSite=Strict cookies in Docker.
|
||||||
|
console.log('Setting up auth...');
|
||||||
|
await page.goto(SERVER + '/login', { waitUntil: 'networkidle', timeout: 30000 });
|
||||||
|
await page.evaluate((token) => {
|
||||||
|
localStorage.setItem('arm_auth', JSON.stringify({
|
||||||
|
accessToken: token,
|
||||||
|
refreshToken: token,
|
||||||
|
user: null,
|
||||||
|
cookieMaxAge: 604800,
|
||||||
|
}));
|
||||||
|
document.cookie = `arm_token=${token}; path=/; max-age=604800; SameSite=Strict`;
|
||||||
|
}, TOKEN);
|
||||||
|
|
||||||
// Collect console errors
|
// Collect console errors
|
||||||
const consoleErrors = [];
|
const consoleErrors = [];
|
||||||
page.on('console', msg => {
|
page.on('console', msg => {
|
||||||
|
|||||||
Reference in New Issue
Block a user