diff --git a/packages/lib/services/e2ee/utils.test.ts b/packages/lib/services/e2ee/utils.test.ts index 95dfe048953..4a2191c064f 100644 --- a/packages/lib/services/e2ee/utils.test.ts +++ b/packages/lib/services/e2ee/utils.test.ts @@ -1,4 +1,4 @@ -import { afterAllCleanUp, setupDatabaseAndSynchronizer, switchClient, encryptionService } from '../../testing/test-utils'; +import { afterAllCleanUp, setupDatabaseAndSynchronizer, switchClient, encryptionService, expectNotThrow } from '../../testing/test-utils'; import MasterKey from '../../models/MasterKey'; import { showMissingMasterKeyMessage } from './utils'; import { localSyncInfo, setMasterKeyEnabled } from '../synchronizer/syncInfoUtils'; @@ -34,6 +34,8 @@ describe('e2ee/utils', function() { setMasterKeyEnabled(mk2.id, true); expect(showMissingMasterKeyMessage(localSyncInfo(), [mk1.id, mk2.id])).toBe(true); + await expectNotThrow(async () => showMissingMasterKeyMessage(localSyncInfo(), ['not_downloaded_yet'])); + const syncInfo = localSyncInfo(); syncInfo.masterKeys = []; expect(showMissingMasterKeyMessage(syncInfo, [mk1.id, mk2.id])).toBe(false); diff --git a/packages/lib/services/e2ee/utils.ts b/packages/lib/services/e2ee/utils.ts index 7280e5f1d94..9df4e570136 100644 --- a/packages/lib/services/e2ee/utils.ts +++ b/packages/lib/services/e2ee/utils.ts @@ -98,6 +98,14 @@ export function showMissingMasterKeyMessage(syncInfo: SyncInfo, notLoadedMasterK for (let i = notLoadedMasterKeys.length - 1; i >= 0; i--) { const mk = syncInfo.masterKeys.find(mk => mk.id === notLoadedMasterKeys[i]); + + // A "notLoadedMasterKey" is a key that either doesn't exist or for + // which a password hasn't been set yet. For the purpose of this + // function, we only want to notify the user about unset passwords. + // Master keys that haven't been downloaded yet should normally be + // downloaded at some point. + // https://github.com/laurent22/joplin/issues/5391 + if (!mk) continue; if (!masterKeyEnabled(mk)) notLoadedMasterKeys.pop(); }