mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-18 05:52:51 +00:00
# Which Problems Are Solved Invalid formatting in the login codebase due to invalid prettier configuration # How the Problems Are Solved Fxed .prettierignore wildcards for login source files # Additional Changes Removed .prettierrc file because there is already a prettier.config.mjs file # Additional Context
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
import { beforeEach, describe, expect, test, vi } from "vitest";
|
|
import { getNextUrl } from "./client";
|
|
|
|
// Mock next/headers
|
|
vi.mock("next/headers", () => ({
|
|
headers: vi.fn(),
|
|
}));
|
|
|
|
// Mock host helper
|
|
vi.mock("./server/host", () => ({
|
|
getPublicHostWithProtocol: vi.fn(),
|
|
}));
|
|
|
|
describe("getNextUrl", () => {
|
|
const command = { loginName: "test-user" };
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
delete (process.env as any).DEFAULT_REDIRECT_URI;
|
|
delete (process.env as any).NEXT_PUBLIC_BASE_PATH;
|
|
});
|
|
|
|
test("should use DEFAULT_REDIRECT_URI if set", async () => {
|
|
process.env.DEFAULT_REDIRECT_URI = "https://env-override.com";
|
|
const result = await getNextUrl(command);
|
|
expect(result).toBe("https://env-override.com");
|
|
});
|
|
|
|
test("should use host-based redirect if DEFAULT_REDIRECT_URI is set to a path (starting with '/')", async () => {
|
|
const { headers } = await import("next/headers");
|
|
const { getPublicHostWithProtocol } = await import("./server/host");
|
|
|
|
process.env.DEFAULT_REDIRECT_URI = "/dashboard";
|
|
vi.mocked(headers).mockResolvedValue({} as any);
|
|
vi.mocked(getPublicHostWithProtocol).mockReturnValue("https://my-host.com");
|
|
process.env.NEXT_PUBLIC_BASE_PATH = "/ui/v2/login";
|
|
|
|
const result = await getNextUrl(command);
|
|
expect(result).toBe("https://my-host.com/dashboard");
|
|
});
|
|
|
|
test("should use defaultRedirectUri if env is NOT set", async () => {
|
|
const result = await getNextUrl(command, "https://settings.com");
|
|
expect(result).toBe("https://settings.com");
|
|
});
|
|
|
|
test("should fallback to relative signedin page if everything else fails (the new default)", async () => {
|
|
const { headers } = await import("next/headers");
|
|
vi.mocked(headers).mockRejectedValue(new Error("No headers"));
|
|
|
|
const result = await getNextUrl(command);
|
|
expect(result).toBe("/signedin?loginName=test-user");
|
|
});
|
|
});
|