Skip to content

Commit f703a67

Browse files
authored
Fix cert sign not showing under certain instances (Stirling-Tools#6908)
1 parent 105af51 commit f703a67

2 files changed

Lines changed: 36 additions & 7 deletions

File tree

frontend/editor/src/core/tests/stubbed/cert-sign-wizard.spec.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async function mockHardwareEndpoints(page: Page) {
5959
}
6060

6161
test.describe("CertSign tool - certificate source model", () => {
62-
test("renders, accepts a PDF, and defaults to upload when no other sources exist", async ({
62+
test("skips the redundant source step and goes straight to certificate format when Upload is the only source", async ({
6363
page,
6464
}) => {
6565
await page.route("**/api/v1/security/cert-sign", (route) =>
@@ -76,12 +76,19 @@ test.describe("CertSign tool - certificate source model", () => {
7676
await uploadFiles(page, SAMPLE_PDF);
7777

7878
await expect(page).toHaveURL(/\/cert-sign/);
79-
// With no server/hardware sources, the picker collapses to a hint and the
80-
// flow proceeds in the default MANUAL (upload) mode — no lone Upload CTA.
79+
// With no server cert or hardware token there is nothing to choose, so the
80+
// whole "Certificate source" step is hidden and the format picker shows directly.
8181
await expect(
82-
page.getByText(/no other certificate sources are available/i).first(),
82+
page.getByRole("button", { name: /pkcs12/i }).first(),
8383
).toBeVisible({ timeout: 10_000 });
84-
await expect(page.getByRole("button", { name: /^upload$/i })).toHaveCount(
84+
await expect(page.getByText(/certificate source/i)).toHaveCount(0);
85+
await expect(
86+
page.getByText(/no other certificate sources are available/i),
87+
).toHaveCount(0);
88+
await expect(
89+
page.getByRole("button", { name: /this device/i }),
90+
).toHaveCount(0);
91+
await expect(page.getByRole("button", { name: /^server$/i })).toHaveCount(
8592
0,
8693
);
8794
});
@@ -93,9 +100,9 @@ test.describe("CertSign tool - certificate source model", () => {
93100
await page.waitForLoadState("domcontentloaded");
94101
await uploadFiles(page, SAMPLE_PDF);
95102

96-
// No alternative sources: the picker is a hint, and hardware is never offered.
103+
// No alternative sources: the source step is hidden, and hardware is never offered.
97104
await expect(
98-
page.getByText(/no other certificate sources are available/i).first(),
105+
page.getByRole("button", { name: /pkcs12/i }).first(),
99106
).toBeVisible({ timeout: 10_000 });
100107
await expect(
101108
page.getByRole("button", { name: /this device/i }),

frontend/editor/src/core/tools/CertSign.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { useEffect } from "react";
12
import { useTranslation } from "react-i18next";
23
import { createToolFlow } from "@app/components/tools/shared/createToolFlow";
4+
import { useAppConfig } from "@app/contexts/AppConfigContext";
35
import CertificateTypeSettings from "@app/components/tools/certSign/CertificateTypeSettings";
46
import CertificateFormatSettings from "@app/components/tools/certSign/CertificateFormatSettings";
57
import CertificateFilesSettings from "@app/components/tools/certSign/CertificateFilesSettings";
@@ -23,6 +25,25 @@ const CertSign = (props: BaseToolProps) => {
2325
props,
2426
);
2527

28+
const { config } = useAppConfig();
29+
// "Upload" is always available; the source chooser is only meaningful when a
30+
// server certificate or a hardware token gives the user an actual alternative.
31+
const hasCertSourceChoice =
32+
(config?.serverCertificateEnabled ?? false) ||
33+
(config?.hardwareSigningAvailable ?? false);
34+
35+
// With Upload as the only source, keep signMode on MANUAL even if a saved
36+
// automation set AUTO/DEVICE, so the hidden source step can't strand the flow.
37+
useEffect(() => {
38+
if (!hasCertSourceChoice && base.params.parameters.signMode !== "MANUAL") {
39+
base.params.updateParameter("signMode", "MANUAL");
40+
}
41+
}, [
42+
hasCertSourceChoice,
43+
base.params.parameters.signMode,
44+
base.params.updateParameter,
45+
]);
46+
2647
const certTypeTips = useCertificateTypeTips();
2748
const appearanceTips = useSignatureAppearanceTips();
2849
const signModeTips = useSignModeTips();
@@ -63,6 +84,7 @@ const CertSign = (props: BaseToolProps) => {
6384
steps: [
6485
{
6586
title: t("certSign.source.stepTitle", "Certificate source"),
87+
isVisible: hasCertSourceChoice,
6688
isCollapsed: base.settingsCollapsed,
6789
onCollapsedClick: base.settingsCollapsed
6890
? base.handleSettingsReset

0 commit comments

Comments
 (0)