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
@@ -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();
|
||||
});
|
||||
Reference in new issue
Block a user