feat: display scan-ready enrollment QR codes for OTP tokens

This commit is contained in:
2026-10-04 12:14:26 +02:00
parent 12696657a0
commit f309809eba
16 changed files with 334 additions and 30 deletions
+29
View File
@@ -0,0 +1,29 @@
import { render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { TokenQrDialog } from "../../src/components/otp/TokenQrDialog";
import { parseOtpAuth } from "../../src/otp/profile";
describe("token QR display", () => {
it("reports encoder limits without displaying an empty QR or allowing download", () => {
const { profile } = parseOtpAuth(
`otpauth://totp/${"a".repeat(500)}?secret=JBSWY3DPEHPK3PXP`,
);
render(<TokenQrDialog profile={profile} onClose={vi.fn()} />);
expect(screen.getByRole("alert")).toHaveTextContent(/version 10/iu);
expect(screen.queryByRole("img")).not.toBeInTheDocument();
expect(screen.getByRole("button", { name: "Download QR" })).toBeDisabled();
});
it("identifies nonportable time parameters without showing the plaintext seed", () => {
const { profile } = parseOtpAuth(
"otpauth://totp/Example:alice?secret=JBSWY3DPEHPK3PXP&issuer=Example&t0=100",
);
render(<TokenQrDialog profile={profile} onClose={vi.fn()} />);
expect(
screen.getByText(/Some authenticators ignore/iu),
).toBeInTheDocument();
expect(screen.getByRole("dialog").textContent).not.toContain(
"JBSWY3DPEHPK3PXP",
);
});
});