65 lines
2.8 KiB
TypeScript
65 lines
2.8 KiB
TypeScript
import { vi, describe, it, expect } from "vitest";
|
|
import "@testing-library/jest-dom";
|
|
import { render, fireEvent, waitFor } from "@testing-library/react";
|
|
import { BrowserRouter as Router } from "react-router";
|
|
import { buildVaultDetailVM } from "@hivegrid/view-models";
|
|
|
|
import { HrVaultDetailPage } from "./HrVaultDetailPage";
|
|
|
|
vi.mock("react-i18next", () => ({
|
|
useTranslation: () => ({ t: (str: string) => str, i18n: { language: "de" } }),
|
|
}));
|
|
|
|
function vault(overrides: Record<string, unknown> = {}) {
|
|
return buildVaultDetailVM({
|
|
vaultId: "v1",
|
|
vaultName: "Team Vault",
|
|
accessLevel: "admin",
|
|
exportHref: "/acme/hr/password-safe/v1/export",
|
|
rows: [
|
|
{ id: "e1", title: "GitHub", tags: ["dev"], url: "https://github.com", hasUsername: true, hasPassword: true, hasNotes: false, revealHref: "/acme/hr/password-safe/v1/reveal" },
|
|
],
|
|
...overrides,
|
|
});
|
|
}
|
|
|
|
const noopActions = {
|
|
onReveal: vi.fn(async () => null),
|
|
onCreateEntry: vi.fn(),
|
|
onArchiveEntry: vi.fn(),
|
|
onGrantAccess: vi.fn(),
|
|
};
|
|
|
|
describe("HrVaultDetailPage (interim-UI, security-critical)", () => {
|
|
it("never renders secret values in the entry list — only reveal controls", () => {
|
|
const { container, queryByText } = render(
|
|
<Router>
|
|
<HrVaultDetailPage vm={vault()} backHref=".." submitting={false} actions={noopActions} />
|
|
</Router>,
|
|
);
|
|
// The entry surface renders...
|
|
expect(container.querySelector('[data-row-id="e1"]')).toBeInTheDocument();
|
|
// ...with reveal controls, but no plaintext secret anywhere before an explicit reveal.
|
|
expect(container.querySelectorAll('[data-ui-id="ui.hr.vault.reveal"]').length).toBeGreaterThan(0);
|
|
expect(queryByText("s3cret")).not.toBeInTheDocument();
|
|
expect(container.querySelector('[data-ui-id="ui.hr.vault.revealed"]')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("reveals a single field on demand via the injected onReveal action and then offers copy", async () => {
|
|
const onReveal = vi.fn(async () => "s3cret");
|
|
const { container, findByText } = render(
|
|
<Router>
|
|
<HrVaultDetailPage vm={vault()} backHref=".." submitting={false} actions={{ ...noopActions, onReveal }} />
|
|
</Router>,
|
|
);
|
|
const revealBtn = container.querySelector('[data-ui-id="ui.hr.vault.reveal"]') as HTMLElement;
|
|
fireEvent.click(revealBtn);
|
|
await waitFor(() => expect(onReveal).toHaveBeenCalledWith("e1", "username"));
|
|
// The plaintext now appears next to a copy control; the 30s clipboard wipe is
|
|
// driven by that CopyToClipboardButton's onCopy (exercised end-to-end in the
|
|
// browser — the Subframe copy primitive is not reliably triggerable in jsdom).
|
|
expect(await findByText("s3cret")).toBeInTheDocument();
|
|
expect(container.querySelector('[data-ui-id="ui.hr.vault.revealed"]')).toBeInTheDocument();
|
|
});
|
|
});
|