1
0
forked from baron/baron-sso

테넌트 CSV 조직 설정 동기화 보완

This commit is contained in:
2026-05-12 18:02:55 +09:00
parent d4c48da426
commit e8a4d7544f
9 changed files with 252 additions and 14 deletions

View File

@@ -0,0 +1,73 @@
import { act } from "react";
import { type Root, createRoot } from "react-dom/client";
import { MemoryRouter } from "react-router-dom";
import { afterEach, describe, expect, it, vi } from "vitest";
import LoginPage from "./LoginPage";
const authState = {
isAuthenticated: false,
isLoading: false,
activeNavigator: undefined as string | undefined,
signinRedirect: vi.fn(),
};
vi.mock("react-oidc-context", () => ({
useAuth: () => authState,
}));
function renderLoginPage(initialEntry: string) {
const container = document.createElement("div");
document.body.appendChild(container);
const root = createRoot(container);
act(() => {
root.render(
<MemoryRouter initialEntries={[initialEntry]}>
<LoginPage />
</MemoryRouter>,
);
});
return { container, root };
}
function cleanupRendered(container: HTMLDivElement, root: Root) {
act(() => {
root.unmount();
});
container.remove();
}
describe("OrgFront LoginPage auto login", () => {
afterEach(() => {
vi.clearAllMocks();
authState.isAuthenticated = false;
authState.isLoading = false;
authState.activeNavigator = undefined;
});
it("does not start auto login again when the orgfront session is already authenticated", () => {
authState.isAuthenticated = true;
const rendered = renderLoginPage(
"/login?auto=1&returnTo=%2Fembed%2Fpicker%3Fmode%3Dsingle",
);
expect(authState.signinRedirect).not.toHaveBeenCalled();
cleanupRendered(rendered.container, rendered.root);
});
it("starts auto login once when auto mode is requested without an authenticated session", () => {
const rendered = renderLoginPage(
"/login?auto=1&returnTo=%2Fembed%2Fpicker%3Fmode%3Dsingle",
);
expect(authState.signinRedirect).toHaveBeenCalledTimes(1);
expect(authState.signinRedirect).toHaveBeenCalledWith({
state: {
returnTo: "/embed/picker?mode=single",
},
});
cleanupRendered(rendered.container, rendered.root);
});
});

View File

@@ -30,7 +30,12 @@ function LoginPage() {
if (!shouldAutoLogin) {
return;
}
if (autoStartedRef.current || auth.isLoading || auth.activeNavigator) {
if (
auth.isAuthenticated ||
autoStartedRef.current ||
auth.isLoading ||
auth.activeNavigator
) {
return;
}
@@ -40,7 +45,14 @@ function LoginPage() {
returnTo,
},
});
}, [auth, auth.activeNavigator, auth.isLoading, returnTo, shouldAutoLogin]);
}, [
auth,
auth.activeNavigator,
auth.isAuthenticated,
auth.isLoading,
returnTo,
shouldAutoLogin,
]);
const handleSSOLogin = async () => {
try {