Spend login, invite, and email-change links only after a confirm POST so mail scanners cannot use them up.
GET still shows a one-button page, a used invitation can resend or reopen for the signed-in invitee, and an email-change GET no longer signs the account out.
This commit is contained in:
1 parent
600056499c
commit
a725cf1a32
33 files changed
+1002
-89
No files matched your search
@@ -0,0 +1,77 @@
|
||||
import { describe, expect, it, vi, beforeEach } from "vitest";
|
||||
import { renderWithProviders as render, screen } from "../utils/test-utils";
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import { ConfirmLinkScreen } from "../../app/(app)/_components/ConfirmLinkScreen";
|
||||
|
||||
const { navMock } = vi.hoisted(() => ({
|
||||
navMock: {
|
||||
push: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("next/navigation", () => ({
|
||||
useRouter: () => ({
|
||||
push: navMock.push,
|
||||
replace: vi.fn(),
|
||||
prefetch: vi.fn(),
|
||||
refresh: vi.fn(),
|
||||
back: vi.fn(),
|
||||
forward: vi.fn(),
|
||||
}),
|
||||
useSearchParams: () => new URLSearchParams(),
|
||||
usePathname: () => "/login/confirm",
|
||||
}));
|
||||
|
||||
const baseProps = {
|
||||
title: "Open this login link",
|
||||
description: "Press continue to log in.",
|
||||
buttonLabel: "Continue",
|
||||
action: "/api/auth/magic-link/verify?token=abcdefghijkl",
|
||||
token: "abcdefghijkl",
|
||||
backHref: "/",
|
||||
backLabel: "← Back to home",
|
||||
missingTitle: "This login link is missing",
|
||||
missingDescription: "Request a new login link from the login page.",
|
||||
missingHref: "/login",
|
||||
missingButtonLabel: "Go to log in",
|
||||
};
|
||||
|
||||
describe("ConfirmLinkScreen", () => {
|
||||
beforeEach(() => {
|
||||
navMock.push.mockReset();
|
||||
});
|
||||
|
||||
it("posts the token when Continue is pressed", () => {
|
||||
const { container } = render(<ConfirmLinkScreen {...baseProps} />);
|
||||
|
||||
expect(
|
||||
screen.getByRole("heading", { name: "Open this login link" }),
|
||||
).toBeInTheDocument();
|
||||
const form = container.querySelector("form");
|
||||
expect(form).toHaveAttribute("method", "POST");
|
||||
expect(form).toHaveAttribute(
|
||||
"action",
|
||||
"/api/auth/magic-link/verify?token=abcdefghijkl",
|
||||
);
|
||||
expect(container.querySelector('input[name="token"]')).toHaveValue(
|
||||
"abcdefghijkl",
|
||||
);
|
||||
expect(screen.getByRole("button", { name: "Continue" })).toHaveAttribute(
|
||||
"type",
|
||||
"submit",
|
||||
);
|
||||
});
|
||||
|
||||
it("offers a way back when the token is missing", () => {
|
||||
render(<ConfirmLinkScreen {...baseProps} token="" action="" />);
|
||||
|
||||
expect(
|
||||
screen.getByRole("heading", { name: "This login link is missing" }),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: "Continue" })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("link", { name: "Go to log in" })).toHaveAttribute(
|
||||
"href",
|
||||
"/login",
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user