A local-first personal finance app
Return an error when changing password with no password method (#8603)
Gautam Singh19ae5da8b560
diff --git a/packages/sync-server/src/accounts/password.js b/packages/sync-server/src/accounts/password.jsindex 1240dbe39d..9c3573cf8d 100644--- a/packages/sync-server/src/accounts/password.js+++ b/packages/sync-server/src/accounts/password.js@@ -161,9 +161,13 @@ export async function changePassword(newPassword) {}const hashed = await hashPassword(newPassword);- accountDb.mutate("UPDATE auth SET extra_data = ? WHERE method = 'password'", [- hashed,- ]);+ const result = accountDb.mutate(+ "UPDATE auth SET extra_data = ? WHERE method = 'password'",+ [hashed],+ );+ if (result.changes === 0) {+ return { error: 'no-password-method' };+ }return {};}diff --git a/packages/sync-server/src/accounts/password.test.js b/packages/sync-server/src/accounts/password.test.jsindex 68b0eca27d..4c895c4e6b 100644--- a/packages/sync-server/src/accounts/password.test.js+++ b/packages/sync-server/src/accounts/password.test.js@@ -22,6 +22,17 @@ function getStoredPasswordHash() {return row ? row.extra_data : null;}+function getAuthMethods() {+ return getAccountDb().all('SELECT method, active FROM auth ORDER BY method');+}++function insertOpenIdAuth(extraData) {+ getAccountDb().mutate(+ 'INSERT INTO auth (method, display_name, extra_data, active) VALUES (?, ?, ?, ?)',+ ['openid', 'OpenID', JSON.stringify(extraData), 1],+ );+}+function ensureOwner() {const db = getAccountDb();const owner = db.first("SELECT id FROM users WHERE user_name = ''");@@ -158,6 +169,25 @@ describe('bootstrapPassword / changePassword', () => {});});+describe('changePassword on an OIDC-only instance', () => {+ it('reports an error instead of silently succeeding', async () => {+ insertOpenIdAuth({ issuer: 'https://issuer.example.com' });++ expect(await changePassword('new password')).toEqual({+ error: 'no-password-method',+ });+ expect(getStoredPasswordHash()).toBeNull();+ });++ it('does not disable the existing openid method', async () => {+ insertOpenIdAuth({ issuer: 'https://issuer.example.com' });++ await changePassword('new password');++ expect(getAuthMethods()).toEqual([{ method: 'openid', active: 1 }]);+ });+});+describe('checkPassword', () => {it('returns true for the correct stored password and false otherwise', async () => {await bootstrapPassword('correct horse');diff --git a/upcoming-release-notes/change-password-no-password-method.md b/upcoming-release-notes/change-password-no-password-method.mdnew file mode 100644index 0000000000..bd7aecab50--- /dev/null+++ b/upcoming-release-notes/change-password-no-password-method.md@@ -0,0 +1,6 @@+---+category: Bugfixes+authors: [Gautamstar]+---++Report an error when changing the password on an instance with no password auth method configured, instead of reporting success without saving.