test: verify federation keeps the AP1 contract

This commit is contained in:
donghyeon-ka
2026-07-25 16:39:01 +09:00
parent c15aeabb87
commit 49863532e1
4 changed files with 75 additions and 1 deletions
+46
View File
@@ -0,0 +1,46 @@
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();
}
+2 -1
View File
@@ -5,7 +5,8 @@
"type": "module",
"scripts": {
"test:pattern1": "node pattern1.mjs",
"test:role-mapping": "node role-mapping.mjs"
"test:role-mapping": "node role-mapping.mjs",
"test:federation-zero-change": "node federation-zero-change.mjs"
},
"devDependencies": {
"playwright-core": "1.62.0"