72 lines
3.0 KiB
TypeScript
72 lines
3.0 KiB
TypeScript
import AxeBuilder from "@axe-core/playwright";
|
|
import { expect, test } from "@playwright/test";
|
|
import { authenticatedStatePath } from "../global-setup";
|
|
import { expectAuthenticatedShell, fillMarkdown, openNewKnowledgePage } from "./support/v2";
|
|
|
|
test.use({ storageState: authenticatedStatePath });
|
|
|
|
// A minimal valid PNG signature — enough for the server's byte-signature detector to
|
|
// recognize it as image/png (docs/13-attachments.md); it does not need to be a
|
|
// structurally complete PNG for this purpose.
|
|
const PNG_BYTES = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x01, 0x02, 0x03]);
|
|
|
|
test.describe("attachments", () => {
|
|
test("an editor can upload a file to a page, see it listed, and download it back", async ({ page }) => {
|
|
const uniqueTitle = `E2E-bijlagepagina ${Date.now()}`;
|
|
|
|
await page.goto("/");
|
|
await expectAuthenticatedShell(page);
|
|
await openNewKnowledgePage(page);
|
|
await page.getByLabel("Paginatitel").fill(uniqueTitle);
|
|
await fillMarkdown(page, "Pagina met een bijlage.");
|
|
await page.getByRole("button", { name: "Publiceren", exact: true }).click();
|
|
await expect(page.getByRole("heading", { name: uniqueTitle })).toBeVisible();
|
|
|
|
await page.getByText("Bijlagen").click();
|
|
|
|
const accessibility = await new AxeBuilder({ page }).analyze();
|
|
expect(accessibility.violations).toEqual([]);
|
|
|
|
await page.getByLabel("Bijlage toevoegen").setInputFiles({
|
|
name: "foto.png",
|
|
mimeType: "image/png",
|
|
buffer: PNG_BYTES
|
|
});
|
|
|
|
const attachmentLink = page.getByRole("link", { name: "foto.png" });
|
|
await expect(attachmentLink).toBeVisible();
|
|
|
|
const href = await attachmentLink.getAttribute("href");
|
|
expect(href).toContain("/api/v1/attachments/");
|
|
|
|
const downloadResponse = await page.request.get(href!);
|
|
expect(downloadResponse.ok()).toBeTruthy();
|
|
expect(downloadResponse.headers()["content-type"]).toBe("image/png");
|
|
const body = await downloadResponse.body();
|
|
expect(Buffer.compare(body, PNG_BYTES)).toBe(0);
|
|
});
|
|
|
|
test("an executable disguised with a document extension is rejected", async ({ page }) => {
|
|
const uniqueTitle = `E2E-bijlageweigering ${Date.now()}`;
|
|
|
|
await page.goto("/");
|
|
await expectAuthenticatedShell(page);
|
|
await openNewKnowledgePage(page);
|
|
await page.getByLabel("Paginatitel").fill(uniqueTitle);
|
|
await fillMarkdown(page, "Pagina zonder toegestane bijlage.");
|
|
await page.getByRole("button", { name: "Publiceren", exact: true }).click();
|
|
await expect(page.getByRole("heading", { name: uniqueTitle })).toBeVisible();
|
|
|
|
await page.getByText("Bijlagen").click();
|
|
|
|
await page.getByLabel("Bijlage toevoegen").setInputFiles({
|
|
name: "factuur.pdf.exe",
|
|
mimeType: "application/pdf",
|
|
buffer: Buffer.from([0x4d, 0x5a, 0x90, 0x00, 0x03, 0x00, 0x00, 0x00])
|
|
});
|
|
|
|
await expect(page.getByRole("alert")).toBeVisible();
|
|
await expect(page.getByRole("link", { name: "factuur.pdf.exe" })).not.toBeVisible();
|
|
});
|
|
});
|