Update portal dependencies for security advisories
This commit is contained in:
1 parent
69264ce165
commit
f899417b1e
6 files changed
+703
-743
No files matched your search
@@ -24,14 +24,19 @@ export function TwoFactorWizard({ initiallyEnabled }: { initiallyEnabled: boolea
|
||||
const password = readPassword(event.currentTarget);
|
||||
|
||||
try {
|
||||
const result = await authClient.twoFactor.enable({ password });
|
||||
const result = await authClient.twoFactor.enable({ password, method: "totp" });
|
||||
if (result.error) {
|
||||
setError(twoFactorErrorMessage(result.error.code));
|
||||
return;
|
||||
}
|
||||
const uri = result.data?.totpURI;
|
||||
setSecret(uri ? new URL(uri).searchParams.get("secret") ?? undefined : undefined);
|
||||
setBackupCodes(result.data?.backupCodes ?? []);
|
||||
if (result.data?.method !== "totp") {
|
||||
setError("Das Einrichten ist fehlgeschlagen. Bitte versuchen Sie es erneut.");
|
||||
return;
|
||||
}
|
||||
const setupSecret = new URL(result.data.totpURI).searchParams.get("secret");
|
||||
if (!setupSecret) throw new Error("Missing TOTP secret");
|
||||
setSecret(setupSecret);
|
||||
setBackupCodes(result.data.backupCodes);
|
||||
setStep("scan");
|
||||
} catch {
|
||||
setError("Das Einrichten ist fehlgeschlagen. Bitte versuchen Sie es erneut.");
|
||||
|
||||
@@ -137,9 +137,10 @@ test("Better Auth grants admin access only to the session that completed MFA", a
|
||||
verification: [],
|
||||
twoFactor: [] as Array<{ secret: string }>,
|
||||
};
|
||||
const sendPasswordReset = vi.fn<(input: { to: string; resetUrl: string }) => Promise<void>>();
|
||||
const { auth } = createPortalAuth({
|
||||
database: memoryAdapter(state),
|
||||
mailerService: { sendPasswordReset: vi.fn(), sendVerification: vi.fn() },
|
||||
mailerService: { sendPasswordReset, sendVerification: vi.fn() },
|
||||
registrationRepository: {
|
||||
createEditorial: vi.fn(), markPendingApproval: vi.fn(), removeUnverifiedAuthIdentity: vi.fn(),
|
||||
recordRegistrationCompensationFailure: vi.fn(), recordVerificationInconsistency: vi.fn(),
|
||||
@@ -171,9 +172,10 @@ test("Better Auth grants admin access only to the session that completed MFA", a
|
||||
const first = responseCookie(await login(), "session_token");
|
||||
const second = responseCookie(await login(), "session_token");
|
||||
expect(first).not.toEqual(second);
|
||||
const setup = await post("two-factor/enable", { password }, first);
|
||||
const setup = await post("two-factor/enable", { password, method: "totp" }, first);
|
||||
expect(setup.status).toBe(200);
|
||||
const { backupCodes } = await setup.json();
|
||||
const { method, backupCodes } = await setup.json();
|
||||
expect(method).toBe("totp");
|
||||
const secret = await symmetricDecrypt({
|
||||
key: (await auth.$context).secretConfig, data: state.twoFactor[0].secret,
|
||||
});
|
||||
@@ -200,6 +202,25 @@ test("Better Auth grants admin access only to the session that completed MFA", a
|
||||
await expect(guard.requireAdmin(headers(responseCookie(backup, "session_token"))))
|
||||
.resolves.toMatchObject({ userId });
|
||||
|
||||
expect((await post("two-factor/disable", { password }, signedInCookie)).status).toBe(200);
|
||||
const disabled = await post("two-factor/disable", { password }, signedInCookie);
|
||||
expect(disabled.status).toBe(200);
|
||||
expect(await auth.api.getSession({ headers: headers(rotated) })).toBeNull();
|
||||
const preResetCookie = responseCookie(disabled, "session_token");
|
||||
|
||||
const resetRequest = await post("request-password-reset", {
|
||||
email, redirectTo: "http://localhost:3000/passwort-zuruecksetzen",
|
||||
});
|
||||
expect(resetRequest.status).toBe(200);
|
||||
expect(sendPasswordReset).toHaveBeenCalledOnce();
|
||||
const resetUrl = new URL(sendPasswordReset.mock.calls[0][0].resetUrl);
|
||||
const token = resetUrl.pathname.split("/").at(-1);
|
||||
const newPassword = "dummy-updated-admin-password";
|
||||
expect((await post("reset-password", { token, newPassword })).status).toBe(200);
|
||||
expect(await auth.api.getSession({ headers: headers(preResetCookie) })).toBeNull();
|
||||
|
||||
const afterReset = responseCookie(await post("sign-in/email", { email, password: newPassword }), "session_token");
|
||||
const signedOut = await post("sign-out", {}, afterReset);
|
||||
expect(signedOut.status).toBe(200);
|
||||
await expect(signedOut.json()).resolves.toMatchObject({ success: true });
|
||||
expect(await auth.api.getSession({ headers: headers(afterReset) })).toBeNull();
|
||||
});
|
||||
@@ -116,10 +116,21 @@ test("server-rendered login and reset forms use POST for native submissions", as
|
||||
|
||||
test("the enrollment confirmation code form uses POST", async () => {
|
||||
const { TwoFactorWizard } = await import("@/app/zwei-faktor/wizard");
|
||||
enableTwoFactor.mockResolvedValueOnce({ data: { totpURI: "otpauth://totp/dummy?secret=DUMMY", backupCodes: [] } });
|
||||
enableTwoFactor.mockResolvedValueOnce({ data: { method: "totp", totpURI: "otpauth://totp/dummy?secret=DUMMY", backupCodes: [] } });
|
||||
render(<TwoFactorWizard initiallyEnabled={false} />);
|
||||
fireEvent.submit(screen.getByRole("button", { name: "Einrichtung starten" }).closest("form")!);
|
||||
expect(enableTwoFactor).toHaveBeenCalledWith({ password: "", method: "totp" });
|
||||
const field = await screen.findByLabelText<HTMLInputElement>("Code aus der App");
|
||||
expect(field.form?.method).toBe("post");
|
||||
expect([...new FormData(field.form!).keys()]).toEqual([]);
|
||||
});
|
||||
|
||||
test("reports a non-TOTP setup response and leaves enrollment retryable", async () => {
|
||||
const { TwoFactorWizard } = await import("@/app/zwei-faktor/wizard");
|
||||
enableTwoFactor.mockResolvedValueOnce({ data: { method: "otp" } });
|
||||
render(<TwoFactorWizard initiallyEnabled={false} />);
|
||||
const button = screen.getByRole("button", { name: "Einrichtung starten" });
|
||||
fireEvent.submit(button.closest("form")!);
|
||||
expect((await screen.findByRole("alert")).textContent).toMatch(/fehlgeschlagen/i);
|
||||
expect((screen.getByRole("button", { name: "Einrichtung starten" }) as HTMLButtonElement).disabled).toBe(false);
|
||||
});
|
||||
Reference in new issue
Block a user