import assert from "node:assert/strict"; import { chromium } from "playwright-core"; const password = process.env.MOCK_GOOGLE_USER_PASSWORD; assert.ok(password); const browser = await chromium.launch({ executablePath: process.env.CHROME_BIN ?? "/usr/bin/google-chrome", headless: true, args: ["--no-sandbox"], }); try { const page = await browser.newPage(); const tokenResponse = page.waitForResponse((response) => response.url().includes("/protocol/openid-connect/token") && response.request().postData()?.includes("grant_type=authorization_code"), ); await page.goto("http://localhost:8088/"); await page.locator("#login").click(); await page.locator('a[href*="/broker/mock-google/login"]').click(); await page.waitForURL(/\/realms\/mock-google\//u); await page.locator("#username").fill("mock-new-user"); await page.locator("#password").fill(password); await page.locator("#kc-login").click(); const response = await tokenResponse; assert.equal(response.status(), 200); const token = (await response.json()).access_token; const payload = JSON.parse( Buffer.from(token.split(".")[1], "base64url").toString(), ); assert.match(payload.preferred_username, /^mock-google\./u); assert.ok(payload.aud.includes("keycloak-pattern-api")); await page.waitForURL("http://localhost:8088/"); await page.locator('[data-authenticated="true"]').waitFor(); await page.locator("#call-api").click(); await page.waitForFunction(() => document.querySelector("#result")?.textContent.includes('"httpStatus": 200'), ); console.log("Google federation verified with the unchanged AP1 SPA/API contract"); } finally { await browser.close(); }