feat: display scan-ready enrollment QR codes for OTP tokens
This commit is contained in:
@@ -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",
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user