import { test, before, after } from "node:test"; import assert from "node:assert/strict"; import { startApi } from "./support/nextcloud.js"; // The dashboard at /status: the browser's sign-in window, a lockout after ten wrong passwords, // the page under the strict CSP, and its data. let api; before(async () => { api = await startApi({ DASHBOARD_PASSWORD: "пароль-123" }); }); after(() => api?.stop()); const basic = (user, password) => ({ Authorization: "Basic " + Buffer.from(`${user}:${password}`).toString("base64") }); const get = (path, headers = {}) => fetch(api.base + path, { headers }); test("Дашборд: без пароля — окно входа браузера", async () => { const response = await get("/status/"); assert.equal(response.status, 401); assert.match(response.headers.get("www-authenticate"), /^Basic realm=/); assert.equal(response.headers.get("cache-control"), "no-store"); assert.equal(response.headers.get("x-robots-tag"), "noindex"); assert.equal((await get("/status/data.json")).status, 401); }); test("Дашборд: с паролем — страница, её файлы и данные", async () => { const auth = basic("любой", "пароль-123"); const page = await get("/status/", auth); assert.equal(page.status, 200); const html = await page.text(); assert.match(html, /