Безопасность довёл до ума — Cursor-генерацию переписал руками. IDOR закрыл, CSRF задушил, refresh rotation теперь как надо. HSTS на staging, ENABLE_DOCS=false, install.env recovery протестил. Backend: - jwt_denylist + auth_epoch: мгновенный revoke access JWT (logout/block/reset) - auth/admin/users: bump epoch, logout с Bearer, forgot_password skip для blocked - install_secrets: путь всегда apps/api/data/secrets/ (bootstrap из корня не ломает Docker) - seed: SEED_DEMO_USERS=false на prod/staging - тесты: jwt revoke, integration, coverage gate 90% Frontend: - logout шлёт Bearer, обработка TOKEN_REVOKED - guards TypeScript fix - E2E: blocked user → 401 сразу после block Infra: - staging/prod compose, TLS nginx, deploy-скрипты - k6 §17.2, backup/health/smoke scripts Docs: - docs/ на русском: project, security, deploy, release (старые md слили) - README короткий + план ТЗ + стандартные логины dev Код готов к плаванию. Капитан может идти писать фронт.
84 lines
3.4 KiB
TypeScript
84 lines
3.4 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
import { API_URL, adminLogin, loginViaUi, registerVerifyLogin, uniqueEmail } from "../helpers/api";
|
|
|
|
test.describe("§15.7 scenarios 5 & 9: Admin users", () => {
|
|
test("blocked user access token rejected immediately after block", async ({ request }) => {
|
|
const email = uniqueEmail("e2e-block-jwt");
|
|
const session = await registerVerifyLogin(request, email);
|
|
const admin = await adminLogin(request);
|
|
const adminToken = (await admin.json()).access_token;
|
|
|
|
const patch = await request.patch(`${API_URL}/api/v1/admin/users/${session.user.id}`, {
|
|
headers: { Authorization: `Bearer ${adminToken}` },
|
|
data: { status: "blocked" }
|
|
});
|
|
expect(patch.ok()).toBeTruthy();
|
|
|
|
const me = await request.get(`${API_URL}/api/v1/users/me`, {
|
|
headers: { Authorization: `Bearer ${session.accessToken}` }
|
|
});
|
|
expect(me.status()).toBe(401);
|
|
expect((await me.json()).detail).toBe("TOKEN_REVOKED");
|
|
});
|
|
|
|
test("admin blocks user → blocked user cannot login", async ({ page, request }) => {
|
|
const email = uniqueEmail("e2e-block");
|
|
const session = await registerVerifyLogin(request, email);
|
|
const admin = await adminLogin(request);
|
|
const adminToken = (await admin.json()).access_token;
|
|
|
|
const patch = await request.patch(`${API_URL}/api/v1/admin/users/${session.user.id}`, {
|
|
headers: { Authorization: `Bearer ${adminToken}` },
|
|
data: { status: "blocked" }
|
|
});
|
|
expect(patch.ok()).toBeTruthy();
|
|
|
|
await loginViaUi(page, email, "Valid1234");
|
|
await expect(page).toHaveURL(/\/login$/);
|
|
});
|
|
|
|
test("admin can open admin users page", async ({ page }) => {
|
|
await loginViaUi(page, "admin@compton.example", "Admin1234");
|
|
await expect(page).toHaveURL(/\/admin$/);
|
|
await expect(page.getByRole("heading", { name: "Users" })).toBeVisible();
|
|
});
|
|
|
|
test("admin session survives reload on /admin", async ({ page }) => {
|
|
await loginViaUi(page, "admin@compton.example", "Admin1234");
|
|
await expect(page).toHaveURL(/\/admin$/);
|
|
await page.goto("/admin");
|
|
await expect(page.getByRole("heading", { name: "Users" })).toBeVisible();
|
|
});
|
|
|
|
test("non-admin cannot open admin page", async ({ page, request }) => {
|
|
const email = uniqueEmail("e2e-nonadmin");
|
|
await registerVerifyLogin(request, email);
|
|
await loginViaUi(page, email, "Valid1234");
|
|
await expect(page).toHaveURL(/\/profile$/);
|
|
await page.goto("/admin");
|
|
await expect(page).toHaveURL(/\/$/);
|
|
});
|
|
|
|
test("admin cannot block self", async ({ request }) => {
|
|
const admin = await adminLogin(request);
|
|
const body = await admin.json();
|
|
const response = await request.patch(`${API_URL}/api/v1/admin/users/${body.user.id}`, {
|
|
headers: { Authorization: `Bearer ${body.access_token}` },
|
|
data: { status: "blocked" }
|
|
});
|
|
expect(response.status()).toBe(400);
|
|
expect((await response.json()).detail).toBe("SELF_BLOCK_FORBIDDEN");
|
|
});
|
|
|
|
test("admin cannot demote self", async ({ request }) => {
|
|
const admin = await adminLogin(request);
|
|
const body = await admin.json();
|
|
const response = await request.patch(`${API_URL}/api/v1/admin/users/${body.user.id}`, {
|
|
headers: { Authorization: `Bearer ${body.access_token}` },
|
|
data: { role: "user" }
|
|
});
|
|
expect(response.status()).toBe(400);
|
|
expect((await response.json()).detail).toBe("SELF_DEMOTION_FORBIDDEN");
|
|
});
|
|
});
|