From bad3d16b4031b8a0f0dfce6e5b6aecab3938299d Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Wed, 18 Jan 2023 04:09:52 +0100 Subject: [PATCH] Fix the problem that the password reset email has to be confirmed twice --- .../structures/auth/ForgotPassword.tsx | 2 ++ .../structures/auth/ForgotPassword-test.tsx | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/components/structures/auth/ForgotPassword.tsx b/src/components/structures/auth/ForgotPassword.tsx index d6e0fea1c17..c6674d0e07e 100644 --- a/src/components/structures/auth/ForgotPassword.tsx +++ b/src/components/structures/auth/ForgotPassword.tsx @@ -261,6 +261,8 @@ export default class ForgotPassword extends React.Component { try { await this.reset.setNewPassword(this.state.password); + this.setState({ phase: Phase.Done }); + return; } catch (err: any) { if (err.httpStatus !== 401) { // 401 = waiting for email verification, else unknown error diff --git a/test/components/structures/auth/ForgotPassword-test.tsx b/test/components/structures/auth/ForgotPassword-test.tsx index 57eccec0148..275d5b9988e 100644 --- a/test/components/structures/auth/ForgotPassword-test.tsx +++ b/test/components/structures/auth/ForgotPassword-test.tsx @@ -283,6 +283,37 @@ describe("", () => { }); }); + describe("and confirm the email link and submitting the new password", () => { + beforeEach(async () => { + // fake link confirmed by resolving client.setPassword instead of raising an error + mocked(client.setPassword).mockResolvedValue({}); + await clickButton("Reset password"); + }); + + it("should send the new password (once)", () => { + expect(client.setPassword).toHaveBeenCalledWith( + { + type: "m.login.email.identity", + threepid_creds: { + client_secret: expect.any(String), + sid: testSid, + }, + threepidCreds: { + client_secret: expect.any(String), + sid: testSid, + }, + }, + testPassword, + false, + ); + + // be sure that the next attempt to set the password would have been sent + jest.advanceTimersByTime(3000); + // it should not retry to set the password + expect(client.setPassword).toHaveBeenCalledTimes(1); + }); + }); + describe("and submitting it", () => { beforeEach(async () => { await clickButton("Reset password");