33 lines
875 B
TypeScript
33 lines
875 B
TypeScript
|
|
import { describe, it, expect } from "vitest";
|
||
|
|
import { safeRedirectTo } from "../check-email";
|
||
|
|
|
||
|
|
describe("safeRedirectTo", () => {
|
||
|
|
it("returns / for null", () => {
|
||
|
|
expect(safeRedirectTo(null)).toBe("/");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("returns / for empty string", () => {
|
||
|
|
expect(safeRedirectTo("")).toBe("/");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("allows a root-relative path", () => {
|
||
|
|
expect(safeRedirectTo("/dashboard")).toBe("/dashboard");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("allows a nested path", () => {
|
||
|
|
expect(safeRedirectTo("/leagues/123/draft/456")).toBe("/leagues/123/draft/456");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("rejects an absolute URL", () => {
|
||
|
|
expect(safeRedirectTo("https://evil.com")).toBe("/");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("rejects a protocol-relative URL", () => {
|
||
|
|
expect(safeRedirectTo("//evil.com")).toBe("/");
|
||
|
|
});
|
||
|
|
|
||
|
|
it("rejects a path starting with //", () => {
|
||
|
|
expect(safeRedirectTo("//not-a-host")).toBe("/");
|
||
|
|
});
|
||
|
|
});
|