Add structured subject attribute editor

This commit is contained in:
2026-10-26 12:06:17 +08:00
parent f9e8915b77
commit e83dc42d3d
2 changed files with 235 additions and 42 deletions
+57
View File
@@ -83,3 +83,60 @@ test("explicit DN order, mandatory DN and template apply", async ({ page }) => {
// RFC 4514 renders the most specific RDN first, so CN follows O.
expect(created.subject).toBe(`O=KCA E2E,CN=${certName}`);
});
test("additional subject attributes use an XCA-style editor", async ({ page }) => {
const user = unique("subject-editor");
const vaultName = unique("Subject Editor Vault");
const certName = unique("attributes.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();
const vaultId = vaultUrl.split("/").pop();
await page.goto(`${vaultUrl}/certificates/new`);
const editor = page.locator(".additional-subject-attributes");
const add = editor.getByRole("button", { name: "Add", exact: true });
const rows = editor.locator(".subject-extra-row");
await expect(add).toBeEnabled();
await expect(editor.locator("textarea")).toHaveCount(0);
await add.click();
await expect(rows).toHaveCount(1);
await rows.nth(0).getByRole("combobox").selectOption("serialNumber");
await rows.nth(0).getByRole("textbox").fill("1234");
// A second row must not disturb the first row's nested input signals.
await add.click();
await expect(rows).toHaveCount(2);
await rows.nth(1).getByRole("combobox").selectOption("title");
await rows.nth(1).getByRole("textbox").fill("delete me");
await expect(rows.nth(0).getByRole("textbox")).toHaveValue("1234");
await rows.nth(1).getByRole("button", { name: "Delete", exact: true }).click();
await expect(rows).toHaveCount(1);
await expect(rows.nth(0).getByRole("textbox")).toHaveValue("1234");
await (await field(page, "Internal name")).fill(certName);
await (await field(page, "Common name (CN)")).fill(certName);
await page.locator("#new-key").check();
await page.getByRole("button", { name: "Create certificate" }).click();
await expect(page.getByRole("heading", { name: certName })).toBeVisible();
const certId = page.url().split("/").pop();
const detail = await api(page, "GET", `/api/vaults/${vaultId}/certificates/${certId}`);
expect(detail.status).toBe(200);
const entries = detail.json.subject_entries;
expect(entries.find((entry) => entry.name === "serialNumber")?.value).toBe("1234");
expect(entries.some((entry) => entry.name === "title")).toBe(false);
// Copying a certificate populates the structured editor with the extra row.
await page.goto(`${vaultUrl}/certificates/${certId}/similar`);
const copiedEditor = page.locator(".additional-subject-attributes");
const copiedRows = copiedEditor.locator(".subject-extra-row");
await expect(copiedRows).toHaveCount(1);
await expect(copiedRows.nth(0).getByRole("combobox")).toHaveValue("serialNumber");
await expect(copiedRows.nth(0).getByRole("textbox")).toHaveValue("1234");
});