From 5a7ec350ca6cf1c9a45a40aea7bb9dce947a07dd Mon Sep 17 00:00:00 2001 From: woodser Date: Tue, 21 Feb 2023 10:55:28 -0500 Subject: [PATCH] accountService.changePassword() requires old and new password --- src/HavenoClient.test.ts | 19 ++++++++++++++----- src/HavenoClient.ts | 7 +++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/HavenoClient.test.ts b/src/HavenoClient.test.ts index cfed5785..46561352 100644 --- a/src/HavenoClient.test.ts +++ b/src/HavenoClient.test.ts @@ -419,9 +419,18 @@ test("Can manage an account (CI)", async () => { assert(await user3.accountExists()); assert(await user3.isAccountOpen()); + // try changing incorrect password + try { + await user3.changePassword("wrongPassword", "abc123"); + throw new Error("Should have failed changing wrong password"); + } catch (err: any) { + assert.equal(err.message, "Incorrect password"); + } + // change password - password = "newPassword"; - await user3.changePassword(password); + const newPassword = "newPassword"; + await user3.changePassword(password, newPassword); + password = newPassword; assert(await user3.accountExists()); assert(await user3.isAccountOpen()); @@ -554,13 +563,13 @@ test("Can manage Monero daemon connections (CI)", async () => { testConnection(connection!, TestConfig.monerod2.url, OnlineStatus.ONLINE, AuthenticationStatus.AUTHENTICATED, 1); // change account password - const password = "newPassword"; - await user3.changePassword("newPassword"); + const newPassword = "newPassword"; + await user3.changePassword(TestConfig.defaultHavenod.accountPassword, newPassword); // restart user3 const appName = user3.getAppName(); await releaseHavenoProcess(user3); - user3 = await initHaveno({appName: appName, accountPassword: password}); + user3 = await initHaveno({appName: appName, accountPassword: newPassword}); // connection is restored, online, and authenticated connection = await user3.getMoneroConnection(); diff --git a/src/HavenoClient.ts b/src/HavenoClient.ts index 640b74e9..eafd698d 100644 --- a/src/HavenoClient.ts +++ b/src/HavenoClient.ts @@ -301,9 +301,12 @@ export default class HavenoClient { * * @param {string} password - the new account password */ - async changePassword(password: string): Promise { + async changePassword(oldPassword: string, newPassword: string): Promise { try { - await this._accountClient.changePassword(new ChangePasswordRequest().setPassword(password), {password: this._password}); + const request = new ChangePasswordRequest() + .setOldPassword(oldPassword) + .setNewPassword(newPassword); + await this._accountClient.changePassword(request, {password: this._password}); } catch (e: any) { throw new HavenoError(e.message, e.code); }