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
@@ -74,6 +74,41 @@ describe("POST /api/invites/rule-stakeholder/resend", () => {
|
||||
expect(sendInviteMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("rotates the token and sends mail after the original link was used", async () => {
|
||||
findUniqueMock.mockResolvedValueOnce({
|
||||
id: "st-1",
|
||||
email: "inv@example.com",
|
||||
inviteTokenHash: "hash-old",
|
||||
inviteExpiresAt: null,
|
||||
acceptedAt: new Date(),
|
||||
invitedBy: { email: "owner@example.com" },
|
||||
rule: {
|
||||
title: "Juniper Street Food Share",
|
||||
summary: null,
|
||||
document: {},
|
||||
user: { email: "owner@example.com" },
|
||||
},
|
||||
});
|
||||
|
||||
const res = await POST(
|
||||
new NextRequest("https://x.test/api/invites/rule-stakeholder/resend", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: "a".repeat(12),
|
||||
email: "inv@example.com",
|
||||
}),
|
||||
headers: { "content-type": "application/json" },
|
||||
}),
|
||||
undefined,
|
||||
);
|
||||
expect(res.status).toBe(200);
|
||||
expect(sendInviteMock).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
to: "inv@example.com",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("rotates the token and sends mail when email matches", async () => {
|
||||
findUniqueMock.mockResolvedValueOnce({
|
||||
id: "st-1",
|
||||
|
||||
Reference in new issue
Block a user