forked from baron/baron-sso
Playwright 테스트 오류 수정
This commit is contained in:
@@ -6,15 +6,22 @@ test.describe("Authentication", () => {
|
||||
await page.addInitScript(() => {
|
||||
window.localStorage.setItem("locale", "ko");
|
||||
window.localStorage.setItem("admin_session", "fake-token");
|
||||
(window as any)._IS_TEST_MODE = true;
|
||||
|
||||
(
|
||||
window as Window & typeof globalThis & { _IS_TEST_MODE?: boolean }
|
||||
)._IS_TEST_MODE = true;
|
||||
|
||||
const authority = "http://localhost:5000/oidc";
|
||||
const client_id = "adminfront";
|
||||
const key = `oidc.user:${authority}:${client_id}`;
|
||||
const authData = {
|
||||
access_token: "fake-token",
|
||||
token_type: "Bearer",
|
||||
profile: { sub: "admin-user", name: "Admin", email: "admin@test.com", role: "super_admin" },
|
||||
profile: {
|
||||
sub: "admin-user",
|
||||
name: "Admin",
|
||||
email: "admin@test.com",
|
||||
role: "super_admin",
|
||||
},
|
||||
expires_at: Math.floor(Date.now() / 1000) + 36000,
|
||||
};
|
||||
window.localStorage.setItem(key, JSON.stringify(authData));
|
||||
@@ -23,8 +30,13 @@ test.describe("Authentication", () => {
|
||||
// 2. High-priority Mocks
|
||||
await page.route("**/api/v1/user/me", async (route) => {
|
||||
await route.fulfill({
|
||||
json: { id: "admin-user", name: "Admin", role: "super_admin", manageableTenants: [] },
|
||||
headers: { 'Access-Control-Allow-Origin': '*' }
|
||||
json: {
|
||||
id: "admin-user",
|
||||
name: "Admin",
|
||||
role: "super_admin",
|
||||
manageableTenants: [],
|
||||
},
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
});
|
||||
});
|
||||
|
||||
@@ -40,15 +52,19 @@ test.describe("Authentication", () => {
|
||||
userinfo_endpoint: "http://localhost:5000/oidc/userinfo",
|
||||
end_session_endpoint: "http://localhost:5000/oidc/session/end",
|
||||
},
|
||||
headers: { 'Access-Control-Allow-Origin': '*' }
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
});
|
||||
} else if (url.includes("/jwks")) {
|
||||
await route.fulfill({
|
||||
json: { keys: [] },
|
||||
headers: { 'Access-Control-Allow-Origin': '*' }
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
});
|
||||
} else {
|
||||
await route.fulfill({ status: 200, body: "ok", headers: { 'Access-Control-Allow-Origin': '*' } });
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
body: "ok",
|
||||
headers: { "Access-Control-Allow-Origin": "*" },
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -65,23 +81,33 @@ test.describe("Authentication", () => {
|
||||
test("should redirect unauthorized users to login page", async ({ page }) => {
|
||||
await page.addInitScript(() => {
|
||||
window.localStorage.clear();
|
||||
(window as any)._IS_TEST_MODE = false;
|
||||
(
|
||||
window as Window & typeof globalThis & { _IS_TEST_MODE?: boolean }
|
||||
)._IS_TEST_MODE = false;
|
||||
});
|
||||
await page.goto("/");
|
||||
await expect(page).toHaveURL(/.*\/login.*/, { timeout: 15000 });
|
||||
});
|
||||
|
||||
test("should allow access to dashboard when authenticated", async ({ page }) => {
|
||||
test("should allow access to dashboard when authenticated", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto("/");
|
||||
// strict mode violation 피하기 위해 .last() 사용하거나 더 구체적인 셀렉터 사용
|
||||
await expect(page.locator("h1").last()).toContainText(/Admin Control|운영 도구/i, { timeout: 15000 });
|
||||
await expect(page.locator("h1").last()).toContainText(
|
||||
/Admin Control|운영 도구/i,
|
||||
{ timeout: 15000 },
|
||||
);
|
||||
});
|
||||
|
||||
test("should logout and redirect to login page", async ({ page }) => {
|
||||
await page.goto("/");
|
||||
page.on("dialog", (dialog) => dialog.accept());
|
||||
const logoutBtn = page.locator('button').filter({ hasText: /Logout|로그아웃/i }).first();
|
||||
await logoutBtn.waitFor({ state: 'visible' });
|
||||
const logoutBtn = page
|
||||
.locator("button")
|
||||
.filter({ hasText: /Logout|로그아웃/i })
|
||||
.first();
|
||||
await logoutBtn.waitFor({ state: "visible" });
|
||||
await logoutBtn.click();
|
||||
await expect(page).toHaveURL(/.*\/login.*/, { timeout: 15000 });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user