fix: harden editorial registration flow
This commit is contained in:
1 parent
9b22752ef2
commit
a8d4e54ffb
8 files changed
+445
-109
No files matched your search
@@ -1,9 +1,50 @@
|
||||
import { expect, test } from "vitest";
|
||||
import { memoryAdapter } from "better-auth/adapters/memory";
|
||||
import { expect, test, vi } from "vitest";
|
||||
|
||||
import { auth } from "./auth";
|
||||
import { POST } from "@/app/api/auth/[...all]/route";
|
||||
|
||||
test("rejects direct Better Auth sign-up requests that bypass B2B registration", async () => {
|
||||
const response = await auth.handler(
|
||||
import { createPortalAuth } from "./auth";
|
||||
import { CURRENT_TERMS_VERSION } from "./registration";
|
||||
|
||||
test("allows the trusted registration service ingress while rejecting public direct sign-up", async () => {
|
||||
const registrationRepository = {
|
||||
createEditorial: vi.fn(),
|
||||
markPendingApproval: vi.fn(),
|
||||
removeUnverifiedAuthIdentity: vi.fn(),
|
||||
recordRegistrationCompensationFailure: vi.fn(),
|
||||
recordVerificationInconsistency: vi.fn(),
|
||||
canCreateSession: vi.fn().mockResolvedValue(false),
|
||||
};
|
||||
const { registrationService } = createPortalAuth({
|
||||
database: memoryAdapter({ user: [], account: [], session: [], verification: [] }),
|
||||
mailerService: {
|
||||
sendPasswordReset: vi.fn(),
|
||||
sendVerification: vi.fn(),
|
||||
},
|
||||
registrationRepository,
|
||||
});
|
||||
|
||||
await expect(
|
||||
registrationService.register({
|
||||
companyName: "Registration GmbH",
|
||||
contactName: "Registration Service",
|
||||
email: "registration@example.com",
|
||||
password: "sicheres-passwort-123",
|
||||
billingAddress: {
|
||||
addressLine1: "Presseweg 1",
|
||||
postalCode: "10115",
|
||||
city: "Berlin",
|
||||
countryCode: "DE",
|
||||
},
|
||||
actsForBusiness: true,
|
||||
termsVersion: CURRENT_TERMS_VERSION,
|
||||
privacyAcknowledged: true,
|
||||
}),
|
||||
).resolves.toEqual({ status: "pending_email" });
|
||||
|
||||
expect(registrationRepository.createEditorial).toHaveBeenCalledTimes(1);
|
||||
|
||||
const response = await POST(
|
||||
new Request("http://localhost:3000/api/auth/sign-up/email", {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
@@ -13,6 +54,7 @@ test("rejects direct Better Auth sign-up requests that bypass B2B registration",
|
||||
password: "sicheres-passwort-123",
|
||||
}),
|
||||
}),
|
||||
{ params: Promise.resolve({ all: ["sign-up", "email"] }) },
|
||||
);
|
||||
|
||||
expect(response.status).toBe(403);
|
||||
|
||||
Reference in new issue
Block a user