// Advanced extensions, preview/validation and vault ZIP export. const { test, expect } = require("@playwright/test"); function unique(prefix) { return `${prefix}-${Date.now()}-${Math.floor(Math.random() * 1000)}`; } async function field(page, label) { return page.locator("label").filter({ hasText: label }).first().locator("..").locator("input, select, textarea").first(); } async function login(page, username) { await page.goto("/login"); await page.getByRole("link", { name: "Sign in with default" }).click(); await page.getByPlaceholder("Enter any user/subject").fill(username); await page.getByRole("button", { name: "Sign-in" }).click(); await expect(page.getByRole("heading", { name: "Vaults" })).toBeVisible(); } test("advanced extensions, validation and vault export", async ({ page }) => { const user = unique("advanced"); const vaultName = unique("Advanced"); const certName = unique("advanced.example"); await login(page, user); await page.getByRole("button", { name: "New vault" }).click(); await page.getByPlaceholder("Production PKI").fill(vaultName); await page.getByRole("button", { name: "Create vault" }).click(); await page.getByRole("link", { name: vaultName }).click(); const vaultUrl = page.url(); await page.goto(`${vaultUrl}/certificates/new`); await expect(page.getByRole("heading", { name: "New certificate" })).toBeVisible(); await (await field(page, "Internal name")).fill(certName); await (await field(page, "Common name (CN)")).fill(certName); await (await field(page, "Organization (O)")).fill("KCA E2E"); await (await field(page, "Country (C)")).fill("DE"); await page.locator("#new-key").check(); await page.locator("textarea[placeholder='http://example.com/ca.crl']").fill("http://example.com/ca.crl"); await page.locator("#aia").fill("OCSP;URI:http://ocsp.example.com"); await page.locator("textarea[placeholder*='raw']").fill( '{"raw":[{"oid":"1.2.3.4","critical":false,"der_hex":"0c03616263"}]}' ); await page.getByRole("button", { name: "Validate extensions" }).click(); await expect(page.getByText("Extension preview")).toBeVisible(); await expect(page.getByText("CRL Distribution Points", { exact: false })).toBeVisible(); await expect(page.getByText("1.2.3.4", { exact: false })).toBeVisible(); await page.getByRole("button", { name: "Create certificate" }).click(); await expect(page.getByRole("heading", { name: certName })).toBeVisible(); const certUrl = page.url(); const certApiUrl = certUrl.replace(/\/vaults\//, "/api/vaults/"); await page.locator(".nav-tabs").getByRole("tab", { name: "Extensions", exact: true }).click(); await expect(page.getByText("CRL Distribution Points", { exact: false })).toBeVisible(); await expect(page.getByText("1.2.3.4", { exact: false })).toBeVisible(); // ZIP export prompts for the private-key password. await page.goto(vaultUrl); page.once("dialog", (dialog) => dialog.accept("secret")); const downloadPromise = page.waitForEvent("download"); await page.getByRole("button", { name: "Export ZIP" }).click(); const download = await downloadPromise; expect(download.suggestedFilename()).toMatch(/\.zip$/); // Import preview selection: a duplicate is deselected by default, but can // be selected explicitly and then reported as skipped by the commit. await page.goto(`${vaultUrl}/import`); await expect(page.getByRole("heading", { name: "Import" })).toBeVisible(); const pem = await page.evaluate(async (url) => { const response = await fetch(`${url}/export`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ format: "pem" }), }); const payload = await response.json(); return atob(payload.content_base64); }, certApiUrl); await page.locator("textarea[placeholder='-----BEGIN CERTIFICATE-----']").fill(pem); await page.getByRole("button", { name: "Preview", exact: true }).click(); await expect(page.getByText("duplicate", { exact: true })).toBeVisible(); await page.getByRole("button", { name: "All", exact: true }).click(); await page.getByRole("button", { name: "Import", exact: true }).click(); await expect(page.getByText(/skipped 1/)).toBeVisible(); });