mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-28 22:25:24 +00:00
fix(auth): allow retrying unavailable second-factor interfaces (#1549)
This commit is contained in:
1 parent
c66702deb1
commit
c9a1348836
6 files changed
+79
-7
No files matched your search
@@ -71,6 +71,7 @@ vi.mock("sonner", () => ({
|
||||
}));
|
||||
|
||||
import { Auth } from "../../auth/Auth";
|
||||
import { startPreLoginPlugins } from "@/plugin-host/loader";
|
||||
import {
|
||||
registerLoginMethod,
|
||||
registerSecondFactor,
|
||||
@@ -270,6 +271,30 @@ describe("login methods on the login screen", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("recovers an unavailable second-factor UI without restarting the login", async () => {
|
||||
window.history.replaceState({}, "", "/?second_factor=1&second_factors=pin");
|
||||
render(<Auth onLogin={vi.fn()} />);
|
||||
expect(await screen.findByText("auth.secondFactorNoUI")).toBeTruthy();
|
||||
let dispose = () => {};
|
||||
vi.mocked(startPreLoginPlugins).mockImplementationOnce(async () => {
|
||||
dispose = registerSecondFactor({
|
||||
id: "pin",
|
||||
pluginId: "corp",
|
||||
titleKey: "corp.pin",
|
||||
component: () => <span>recovered challenge</span>,
|
||||
});
|
||||
});
|
||||
try {
|
||||
fireEvent.click(screen.getByText("auth.retrySecondFactorUI"));
|
||||
expect(await screen.findByText("recovered challenge")).toBeTruthy();
|
||||
expect(startPreLoginPlugins).toHaveBeenLastCalledWith({
|
||||
retryFailed: true,
|
||||
});
|
||||
} finally {
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
|
||||
it("offers every registered factor when the server lists none", async () => {
|
||||
const dispose = registerSecondFactor({
|
||||
id: "pin",
|
||||
|
||||
@@ -232,6 +232,20 @@ describe("plugin loader", () => {
|
||||
expect(isPluginFrontendActive("alpha")).toBe(true);
|
||||
});
|
||||
|
||||
it("retries failed login bundles only when explicitly requested", async () => {
|
||||
vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
vi.spyOn(globalThis, "fetch").mockImplementation(
|
||||
async () => new Response(JSON.stringify([summary("login")])),
|
||||
);
|
||||
await startPreLoginPlugins();
|
||||
expect(isPluginFrontendActive("login")).toBe(false);
|
||||
modules.login = railPlugin("login");
|
||||
await startPreLoginPlugins();
|
||||
expect(isPluginFrontendActive("login")).toBe(false);
|
||||
await startPreLoginPlugins({ retryFailed: true });
|
||||
expect(isPluginFrontendActive("login")).toBe(true);
|
||||
});
|
||||
|
||||
it("ignores a pre-login load started after sign-in", async () => {
|
||||
modules.login = railPlugin("login");
|
||||
modules.alpha = railPlugin("alpha");
|
||||
|
||||
Reference in new issue
Block a user