forked from baron/baron-sso
테넌트 목록 및 조직 계층 구조 개선
This commit is contained in:
@@ -1,79 +1,84 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
test.describe('Authentication', () => {
|
||||
test.describe("Authentication", () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
// Mock OIDC configuration
|
||||
await page.route('**/oidc/.well-known/openid-configuration', async route => {
|
||||
await route.fulfill({
|
||||
json: {
|
||||
issuer: "http://localhost:5000/oidc",
|
||||
authorization_endpoint: "http://localhost:5000/oidc/auth",
|
||||
token_endpoint: "http://localhost:5000/oidc/token",
|
||||
jwks_uri: "http://localhost:5000/oidc/jwks",
|
||||
response_types_supported: ["code"],
|
||||
subject_types_supported: ["public"],
|
||||
id_token_signing_alg_values_supported: ["RS256"]
|
||||
}
|
||||
});
|
||||
});
|
||||
await page.route(
|
||||
"**/oidc/.well-known/openid-configuration",
|
||||
async (route) => {
|
||||
await route.fulfill({
|
||||
json: {
|
||||
issuer: "http://localhost:5000/oidc",
|
||||
authorization_endpoint: "http://localhost:5000/oidc/auth",
|
||||
token_endpoint: "http://localhost:5000/oidc/token",
|
||||
jwks_uri: "http://localhost:5000/oidc/jwks",
|
||||
response_types_supported: ["code"],
|
||||
subject_types_supported: ["public"],
|
||||
id_token_signing_alg_values_supported: ["RS256"],
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('should redirect unauthorized users to login page', async ({ page }) => {
|
||||
await page.goto('/');
|
||||
test("should redirect unauthorized users to login page", async ({ page }) => {
|
||||
await page.goto("/");
|
||||
// Should be redirected to /login
|
||||
await expect(page).toHaveURL(/\/login/);
|
||||
await expect(page.locator('h1')).toContainText('Baron SSO');
|
||||
await expect(page.locator("h1")).toContainText("Baron SSO");
|
||||
});
|
||||
|
||||
test('should allow access to dashboard when authenticated', async ({ page }) => {
|
||||
test("should allow access to dashboard when authenticated", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.addInitScript(() => {
|
||||
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 User',
|
||||
email: 'admin@example.com'
|
||||
access_token: "fake-token",
|
||||
token_type: "Bearer",
|
||||
profile: {
|
||||
sub: "admin-user",
|
||||
name: "Admin User",
|
||||
email: "admin@example.com",
|
||||
},
|
||||
expires_at: Math.floor(Date.now() / 1000) + 3600,
|
||||
};
|
||||
window.localStorage.setItem(key, JSON.stringify(authData));
|
||||
});
|
||||
|
||||
await page.goto('/');
|
||||
|
||||
await page.goto("/");
|
||||
|
||||
// Wait for the auth loading to finish
|
||||
await expect(page.locator('.animate-spin')).not.toBeVisible();
|
||||
|
||||
await expect(page.locator(".animate-spin")).not.toBeVisible();
|
||||
|
||||
// Should be on the dashboard/overview
|
||||
await expect(page.locator('aside')).toBeVisible();
|
||||
await expect(page.locator('h1')).toContainText('Admin Control');
|
||||
await expect(page.locator("aside")).toBeVisible();
|
||||
await expect(page.locator("h1")).toContainText("Admin Control");
|
||||
});
|
||||
|
||||
test('should logout and redirect to login page', async ({ page }) => {
|
||||
test("should logout and redirect to login page", async ({ page }) => {
|
||||
// Start authenticated
|
||||
await page.addInitScript(() => {
|
||||
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' },
|
||||
access_token: "fake-token",
|
||||
token_type: "Bearer",
|
||||
profile: { sub: "admin-user", name: "Admin" },
|
||||
expires_at: Math.floor(Date.now() / 1000) + 3600,
|
||||
};
|
||||
window.localStorage.setItem(key, JSON.stringify(authData));
|
||||
});
|
||||
|
||||
await page.goto('/');
|
||||
await expect(page.locator('aside')).toBeVisible();
|
||||
await page.goto("/");
|
||||
await expect(page.locator("aside")).toBeVisible();
|
||||
|
||||
// Mock window.confirm
|
||||
page.on('dialog', dialog => dialog.accept());
|
||||
|
||||
page.on("dialog", (dialog) => dialog.accept());
|
||||
|
||||
// Click logout button (label: ui.admin.nav.logout)
|
||||
await page.click('button:has-text("Logout"), button:has-text("로그아웃")');
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
test.describe('Tenants Management', () => {
|
||||
test.describe("Tenants Management", () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
// Authenticate
|
||||
await page.addInitScript(() => {
|
||||
@@ -8,68 +8,90 @@ test.describe('Tenants Management', () => {
|
||||
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 User', email: 'admin@example.com' },
|
||||
access_token: "fake-token",
|
||||
token_type: "Bearer",
|
||||
profile: {
|
||||
sub: "admin-user",
|
||||
name: "Admin User",
|
||||
email: "admin@example.com",
|
||||
},
|
||||
expires_at: Math.floor(Date.now() / 1000) + 3600,
|
||||
};
|
||||
window.localStorage.setItem(key, JSON.stringify(authData));
|
||||
});
|
||||
|
||||
// Mock OIDC config to avoid redirects
|
||||
await page.route('**/oidc/.well-known/openid-configuration', async route => {
|
||||
await route.fulfill({ json: { issuer: "http://localhost:5000/oidc" } });
|
||||
});
|
||||
await page.route(
|
||||
"**/oidc/.well-known/openid-configuration",
|
||||
async (route) => {
|
||||
await route.fulfill({ json: { issuer: "http://localhost:5000/oidc" } });
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('should list tenants', async ({ page }) => {
|
||||
await page.route('**/api/v1/admin/tenants*', async route => {
|
||||
test("should list tenants", async ({ page }) => {
|
||||
await page.route("**/api/v1/admin/tenants*", async (route) => {
|
||||
await route.fulfill({
|
||||
json: {
|
||||
items: [
|
||||
{ id: '1', name: 'Tenant A', slug: 'tenant-a', status: 'active', type: 'COMPANY', updatedAt: new Date().toISOString() },
|
||||
{
|
||||
id: "1",
|
||||
name: "Tenant A",
|
||||
slug: "tenant-a",
|
||||
status: "active",
|
||||
type: "COMPANY",
|
||||
updatedAt: new Date().toISOString(),
|
||||
},
|
||||
],
|
||||
total: 1,
|
||||
limit: 1000,
|
||||
offset: 0
|
||||
}
|
||||
offset: 0,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
await page.goto('/tenants');
|
||||
await expect(page.locator('h2')).toContainText('테넌트 목록');
|
||||
await expect(page.locator('table')).toContainText('Tenant A');
|
||||
await page.goto("/tenants");
|
||||
await expect(page.locator("h2")).toContainText("테넌트 목록");
|
||||
await expect(page.locator("table")).toContainText("Tenant A");
|
||||
});
|
||||
|
||||
test('should create a new tenant', async ({ page }) => {
|
||||
test("should create a new tenant", async ({ page }) => {
|
||||
// Mock GET for list (empty) and for parents
|
||||
await page.route('**/api/v1/admin/tenants*', async route => {
|
||||
if (route.request().method() === 'GET') {
|
||||
await route.fulfill({ json: { items: [], total: 0, limit: 100, offset: 0 } });
|
||||
} else if (route.request().method() === 'POST') {
|
||||
await route.fulfill({
|
||||
json: { id: '2', name: 'New Tenant', slug: 'new-tenant', status: 'active', type: 'COMPANY' }
|
||||
await page.route("**/api/v1/admin/tenants*", async (route) => {
|
||||
if (route.request().method() === "GET") {
|
||||
await route.fulfill({
|
||||
json: { items: [], total: 0, limit: 100, offset: 0 },
|
||||
});
|
||||
} else if (route.request().method() === "POST") {
|
||||
await route.fulfill({
|
||||
json: {
|
||||
id: "2",
|
||||
name: "New Tenant",
|
||||
slug: "new-tenant",
|
||||
status: "active",
|
||||
type: "COMPANY",
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
await page.goto('/tenants/new');
|
||||
|
||||
await page.fill('input >> nth=0', 'New Tenant');
|
||||
await page.fill('input >> nth=1', 'new-tenant');
|
||||
await page.fill('textarea', 'Description');
|
||||
|
||||
await page.goto("/tenants/new");
|
||||
|
||||
await page.fill("input >> nth=0", "New Tenant");
|
||||
await page.fill("input >> nth=1", "new-tenant");
|
||||
await page.fill("textarea", "Description");
|
||||
|
||||
await page.click('button:has-text("생성")');
|
||||
|
||||
await expect(page).toHaveURL(/\/tenants$/);
|
||||
});
|
||||
|
||||
test('should show validation error on empty name', async ({ page }) => {
|
||||
await page.goto('/tenants/new');
|
||||
test("should show validation error on empty name", async ({ page }) => {
|
||||
await page.goto("/tenants/new");
|
||||
const submitBtn = page.locator('button:has-text("생성")');
|
||||
await expect(submitBtn).toBeDisabled();
|
||||
|
||||
await page.fill('input >> nth=0', 'Valid Name');
|
||||
|
||||
await page.fill("input >> nth=0", "Valid Name");
|
||||
await expect(submitBtn).not.toBeDisabled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user