mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-09-21 18:17:05 +00:00
Integrate merged E2EE rebuild fix
# Conflicts: # updates.md
This commit is contained in:
@@ -291,6 +291,15 @@ export async function adjustSettingToRemote(
|
||||
return true;
|
||||
}
|
||||
|
||||
if (operation === "rebuild") {
|
||||
// An overwrite makes this device authoritative for both the Vault contents and the
|
||||
// shared synchronisation settings. The remote lookup above remains a connection
|
||||
// preflight, but settings from the database which is about to be replaced must not
|
||||
// overwrite intentional local changes such as enabling E2EE.
|
||||
log("Rebuild will use this device's synchronisation settings.", LOG_LEVEL_NOTICE);
|
||||
return true;
|
||||
}
|
||||
|
||||
const remoteTweaks = remoteResult.values;
|
||||
const necessary = extractObject(TweakValuesShouldMatchedTemplate, remoteTweaks);
|
||||
// Check if any necessary tweak value is different from current config.
|
||||
|
||||
@@ -1149,6 +1149,33 @@ describe("Red Flag Feature", () => {
|
||||
});
|
||||
|
||||
describe("Remote configuration adjustment", () => {
|
||||
it("keeps this device's E2EE settings when preparing to overwrite the remote", async () => {
|
||||
const host = createHostMock();
|
||||
Object.assign(host.mocks.setting.settings, TweakValuesShouldMatchedTemplate, {
|
||||
encrypt: true,
|
||||
passphrase: "local-encryption-passphrase",
|
||||
});
|
||||
host.mocks.tweakValue.fetchRemotePreferred.mockResolvedValueOnce(
|
||||
availableRemoteTweaks({
|
||||
...TweakValuesShouldMatchedTemplate,
|
||||
encrypt: false,
|
||||
})
|
||||
);
|
||||
|
||||
const result = await adjustSettingToRemote(
|
||||
host as any,
|
||||
createLoggerMock(),
|
||||
host.mocks.setting.currentSettings(),
|
||||
"rebuild"
|
||||
);
|
||||
|
||||
expect(result).toBe(true);
|
||||
expect(host.mocks.tweakValue.fetchRemotePreferred).toHaveBeenCalledOnce();
|
||||
expect(host.mocks.setting.currentSettings().encrypt).toBe(true);
|
||||
expect(host.mocks.setting.currentSettings().passphrase).toBe("local-encryption-passphrase");
|
||||
expect(host.mocks.setting.applyExternalSettings).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should skip remote configuration fetch when preventFetchingConfig is true", async () => {
|
||||
const host = createHostMock();
|
||||
const config = { preventFetchingConfig: true } as any;
|
||||
@@ -1855,8 +1882,15 @@ describe("Red Flag Feature", () => {
|
||||
it("should handle rebuildAll flag with flagHandlerToEventHandler", async () => {
|
||||
const host = createHostMock();
|
||||
const log = createLoggerMock();
|
||||
Object.assign(host.mocks.setting.settings, TweakValuesShouldMatchedTemplate, {
|
||||
encrypt: true,
|
||||
passphrase: "local-encryption-passphrase",
|
||||
});
|
||||
host.mocks.tweakValue.fetchRemotePreferred.mockResolvedValueOnce(
|
||||
availableRemoteTweaks({ customChunkSize: 1 })
|
||||
availableRemoteTweaks({
|
||||
...TweakValuesShouldMatchedTemplate,
|
||||
encrypt: false,
|
||||
})
|
||||
);
|
||||
|
||||
host.mocks.storageAccess.files.add(FlagFilesOriginal.REBUILD_ALL);
|
||||
@@ -1868,6 +1902,8 @@ describe("Red Flag Feature", () => {
|
||||
await Promise.resolve(eventHandler());
|
||||
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||
expect(host.mocks.rebuilder.$rebuildEverything).toHaveBeenCalled();
|
||||
expect(host.mocks.setting.currentSettings().encrypt).toBe(true);
|
||||
expect(host.mocks.setting.applyExternalSettings).not.toHaveBeenCalled();
|
||||
|
||||
expect(host.mocks.ui.dialogManager.openWithExplicitCancel).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user