mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-29 14:45:24 +00:00
feat: add auth extension points and one ssh connect pipeline
This commit is contained in:
1 parent
d3c209af13
commit
d774df8b41
159 files changed
+43243
-7451
No files matched your search
@@ -0,0 +1,56 @@
|
||||
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const api = vi.hoisted(() => ({
|
||||
getUserSecondFactors: vi.fn(),
|
||||
resetUserSecondFactors: vi.fn(),
|
||||
}));
|
||||
vi.mock("@/api/auth-methods-api", () => api);
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({
|
||||
t: (key: string, opts?: Record<string, unknown>) =>
|
||||
opts?.plugin ? `${key}:${opts.plugin}` : key,
|
||||
}),
|
||||
}));
|
||||
vi.mock("sonner", () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
|
||||
|
||||
import { AdminSecondFactorsSection } from "@/sidebar/AdminSecondFactorsSection";
|
||||
|
||||
afterEach(() => vi.clearAllMocks());
|
||||
|
||||
describe("AdminSecondFactorsSection", () => {
|
||||
it("shows a factor whose plugin is off and resets after confirming", async () => {
|
||||
api.getUserSecondFactors.mockResolvedValue([
|
||||
{
|
||||
pluginId: "core",
|
||||
factorId: "totp",
|
||||
labelKey: "auth.totpFactor",
|
||||
available: true,
|
||||
},
|
||||
{ pluginId: "yubi", factorId: "otp", labelKey: null, available: false },
|
||||
]);
|
||||
api.resetUserSecondFactors.mockResolvedValue(undefined);
|
||||
const onReset = vi.fn();
|
||||
const requestConfirm = vi.fn((_message: string, onConfirm: () => void) =>
|
||||
onConfirm(),
|
||||
);
|
||||
render(
|
||||
<AdminSecondFactorsSection
|
||||
userId="u1"
|
||||
username="alice"
|
||||
heading={<h2>factors</h2>}
|
||||
requestConfirm={requestConfirm}
|
||||
onReset={onReset}
|
||||
/>,
|
||||
);
|
||||
expect(
|
||||
await screen.findByText("admin.secondFactorUnavailable:yubi"),
|
||||
).toBeTruthy();
|
||||
fireEvent.click(screen.getByText("admin.resetSecondFactors"));
|
||||
expect(requestConfirm).toHaveBeenCalled();
|
||||
await waitFor(() =>
|
||||
expect(api.resetUserSecondFactors).toHaveBeenCalledWith("u1"),
|
||||
);
|
||||
expect(onReset).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user