mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-10-07 18:02:30 +00:00
Merge internal Metadata integration for stacked Setup URI validation
This commit is contained in:
@@ -569,6 +569,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab {
|
||||
}
|
||||
}
|
||||
|
||||
// Internal Metadata encryption affects future Metadata writes and is not a rebuild requirement.
|
||||
isNeedRebuildLocal() {
|
||||
return this.isSomeDirty([
|
||||
"useIndexedDBAdapter",
|
||||
|
||||
@@ -116,7 +116,16 @@ export function paneRemoteConfig(
|
||||
.onClick(async () => {
|
||||
const setupManager = this.core.getModule(SetupManager);
|
||||
const originalSettings = getSettingsFromEditingSettings(this.editingSettings);
|
||||
await setupManager.onlyE2EEConfiguration(UserMode.Update, originalSettings);
|
||||
const applied = await setupManager.onlyE2EEConfiguration(UserMode.Update, originalSettings);
|
||||
if (applied) {
|
||||
this.editingSettings.encryptInternalMetadata =
|
||||
this.core.settings.encryptInternalMetadata;
|
||||
if (this.initialSettings) {
|
||||
this.initialSettings.encryptInternalMetadata =
|
||||
this.core.settings.encryptInternalMetadata;
|
||||
}
|
||||
this.requestUpdate();
|
||||
}
|
||||
updateE2EESummary();
|
||||
})
|
||||
.setButtonText("Configure")
|
||||
@@ -243,6 +252,7 @@ export function paneRemoteConfig(
|
||||
...DEFAULT_SETTINGS,
|
||||
encrypt: this.editingSettings.encrypt,
|
||||
usePathObfuscation: this.editingSettings.usePathObfuscation,
|
||||
encryptInternalMetadata: this.editingSettings.encryptInternalMetadata,
|
||||
passphrase: this.editingSettings.passphrase,
|
||||
configPassphraseStore: this.editingSettings.configPassphraseStore,
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const runtime = vi.hoisted(() => ({
|
||||
buttonClasses: [] as string[],
|
||||
clickHandlers: [] as Array<() => Promise<void> | void>,
|
||||
panels: [] as Array<{ destroy: ReturnType<typeof vi.fn> }>,
|
||||
settingClasses: [] as string[],
|
||||
}));
|
||||
@@ -51,7 +52,8 @@ vi.mock("./LiveSyncSetting.ts", () => ({
|
||||
setDestructive() {
|
||||
return this;
|
||||
},
|
||||
onClick() {
|
||||
onClick(callback: () => Promise<void> | void) {
|
||||
runtime.clickHandlers.push(callback);
|
||||
return this;
|
||||
},
|
||||
setButtonText() {
|
||||
@@ -97,6 +99,7 @@ vi.mock("@vrtmrz/livesync-commonlib/compat/common/ConnectionString", () => ({
|
||||
},
|
||||
}));
|
||||
vi.mock("@/modules/features/SetupWizard/dialogs/SetupRemote.svelte", () => ({ default: {} }));
|
||||
vi.mock("@/modules/features/SetupWizard/dialogs/SetupRemoteE2EE.svelte", () => ({ default: {} }));
|
||||
vi.mock("@/modules/features/SetupWizard/dialogs/SetupRemoteCouchDB.svelte", () => ({ default: {} }));
|
||||
vi.mock("@/modules/features/SetupWizard/dialogs/SetupRemoteBucket.svelte", () => ({ default: {} }));
|
||||
vi.mock("@/modules/features/SetupWizard/dialogs/SetupRemoteP2P.svelte", () => ({ default: {} }));
|
||||
@@ -114,6 +117,7 @@ function createPanelElement(): HTMLElement {
|
||||
|
||||
afterEach(() => {
|
||||
runtime.buttonClasses.length = 0;
|
||||
runtime.clickHandlers.length = 0;
|
||||
runtime.panels.length = 0;
|
||||
runtime.settingClasses.length = 0;
|
||||
vi.clearAllMocks();
|
||||
@@ -148,4 +152,46 @@ describe("paneRemoteConfig", () => {
|
||||
|
||||
expect(runtime.panels[0].destroy).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("applies an internal Metadata preference change without scheduling setup initialisation", async () => {
|
||||
const originalSettings = {
|
||||
encrypt: true,
|
||||
passphrase: "passphrase",
|
||||
E2EEAlgorithm: "v2",
|
||||
usePathObfuscation: true,
|
||||
encryptInternalMetadata: false,
|
||||
remoteConfigurations: {},
|
||||
};
|
||||
const setupManager = {
|
||||
onlyE2EEConfiguration: vi.fn(async () => {
|
||||
host.core.settings.encryptInternalMetadata = true;
|
||||
return true;
|
||||
}),
|
||||
};
|
||||
const host = {
|
||||
editingSettings: { ...originalSettings },
|
||||
initialSettings: { ...originalSettings },
|
||||
core: {
|
||||
settings: { ...originalSettings },
|
||||
getModule: vi.fn(() => setupManager),
|
||||
},
|
||||
lifetimeComponent: { register: vi.fn() },
|
||||
requestUpdate: vi.fn(),
|
||||
};
|
||||
const addPanel = vi.fn((_parent: HTMLElement, heading: string) => ({
|
||||
then(callback: (paneEl: HTMLElement) => void) {
|
||||
if (heading === "E2EE Configuration") {
|
||||
callback(createPanelElement());
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
paneRemoteConfig.call(host as never, {} as HTMLElement, { addPanel } as never);
|
||||
await runtime.clickHandlers[0]();
|
||||
|
||||
expect(setupManager.onlyE2EEConfiguration).toHaveBeenCalledOnce();
|
||||
expect(host.editingSettings.encryptInternalMetadata).toBe(true);
|
||||
expect(host.initialSettings.encryptInternalMetadata).toBe(true);
|
||||
expect(host.requestUpdate).toHaveBeenCalledOnce();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -336,6 +336,31 @@ export class SetupManager extends AbstractModule {
|
||||
this._log("E2EE configuration cancelled.", LOG_LEVEL_NOTICE);
|
||||
return false;
|
||||
}
|
||||
const onlyInternalMetadataPreferenceChanged =
|
||||
currentSetting.encryptInternalMetadata !== e2eeConf.encryptInternalMetadata &&
|
||||
currentSetting.encrypt === e2eeConf.encrypt &&
|
||||
currentSetting.passphrase === e2eeConf.passphrase &&
|
||||
currentSetting.E2EEAlgorithm === e2eeConf.E2EEAlgorithm &&
|
||||
currentSetting.usePathObfuscation === e2eeConf.usePathObfuscation;
|
||||
if (userMode === UserMode.Update && onlyInternalMetadataPreferenceChanged) {
|
||||
if (e2eeConf.encryptInternalMetadata && currentSetting.remoteType === REMOTE_COUCHDB) {
|
||||
const proceed = "Enable without rebuilding — update every other device first";
|
||||
const choice = await this.core.confirm.askSelectStringDialogue(
|
||||
"A manual remote Rebuild is strongly recommended to protect existing file properties. " +
|
||||
"Before continuing without rebuilding, update every other synchronising device to a version " +
|
||||
"which supports this option, including devices currently running LiveSync. " +
|
||||
"Existing properties remain unchanged until they are rewritten or rebuilt.",
|
||||
[proceed, "Cancel"],
|
||||
{ title: "Encrypt internal file Properties", defaultAction: "Cancel" }
|
||||
);
|
||||
if (choice !== proceed) return false;
|
||||
}
|
||||
await this.services.setting.applyPartial(
|
||||
{ encryptInternalMetadata: e2eeConf.encryptInternalMetadata },
|
||||
true
|
||||
);
|
||||
return true;
|
||||
}
|
||||
const newSetting = {
|
||||
...currentSetting,
|
||||
...e2eeConf,
|
||||
|
||||
@@ -659,3 +659,23 @@ describe("SetupManager", () => {
|
||||
expect(setting.currentSettings().P2P_ActiveRemoteConfigurationId).toBe("existing");
|
||||
});
|
||||
});
|
||||
|
||||
describe("internal Metadata configuration", () => {
|
||||
it.each([true, false])(
|
||||
"applies the preference only after accepting the no-Rebuild warning (%s)",
|
||||
async (accept) => {
|
||||
const { manager, setting, dialogManager, core } = createSetupManager();
|
||||
const current = { ...setting.settings, encryptInternalMetadata: false, remoteType: REMOTE_COUCHDB };
|
||||
dialogManager.openWithExplicitCancel.mockResolvedValue({ ...current, encryptInternalMetadata: true });
|
||||
const ask = vi.fn(async (_message: string, choices: string[]) => (accept ? choices[0] : "Cancel"));
|
||||
core.confirm = { askSelectStringDialogue: ask };
|
||||
const apply = vi.spyOn(setting, "applyPartial").mockResolvedValue(undefined);
|
||||
await expect(manager.onlyE2EEConfiguration(UserMode.Update, current)).resolves.toBe(accept);
|
||||
expect(ask.mock.calls[0][1][0]).toContain("update every other device first");
|
||||
expect(ask.mock.calls[0][0]).toContain("currently running LiveSync");
|
||||
expect(apply).toHaveBeenCalledTimes(accept ? 1 : 0);
|
||||
expect(core.rebuilder.scheduleRebuild).not.toHaveBeenCalled();
|
||||
expect(core.rebuilder.scheduleFetch).not.toHaveBeenCalled();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@@ -26,7 +26,8 @@
|
||||
passphrase: "",
|
||||
E2EEAlgorithm: DEFAULT_SETTINGS.E2EEAlgorithm,
|
||||
usePathObfuscation: true,
|
||||
} as EncryptionSettings;
|
||||
encryptInternalMetadata: true,
|
||||
};
|
||||
|
||||
let encryptionSettings = $state<EncryptionSettings>({ ...default_encryption });
|
||||
|
||||
@@ -42,6 +43,11 @@
|
||||
if (!encryptionSettings.encrypt) return true;
|
||||
return encryptionSettings.passphrase.trim().length >= 1;
|
||||
});
|
||||
let canEncryptInternalMetadata = $derived(
|
||||
encryptionSettings.encrypt &&
|
||||
encryptionSettings.E2EEAlgorithm === E2EEAlgorithms.V2 &&
|
||||
encryptionSettings.usePathObfuscation
|
||||
);
|
||||
|
||||
function commit() {
|
||||
setResult(pickEncryptionSettings(encryptionSettings));
|
||||
@@ -87,6 +93,24 @@
|
||||
</InfoNote>
|
||||
{/if}
|
||||
|
||||
<InputRow label="Encrypt internal file Properties">
|
||||
<input
|
||||
type="checkbox"
|
||||
bind:checked={encryptionSettings.encryptInternalMetadata}
|
||||
disabled={!canEncryptInternalMetadata}
|
||||
/>
|
||||
</InputRow>
|
||||
<InfoNote>
|
||||
This option encrypts file properties used by Hidden File Sync and Customisation Sync.
|
||||
<br />
|
||||
It applies only to CouchDB and requires End-to-End Encryption, the V2 algorithm, and Property Encryption
|
||||
(Obfuscate Properties). The remote type is selected later in this setup wizard.
|
||||
<br />
|
||||
It protects properties written after the option is enabled; existing properties are not rewritten. A manual remote
|
||||
Rebuild is strongly recommended to protect existing properties. Update every other synchronising device to a compatible
|
||||
version before enabling this option, including devices currently running LiveSync.
|
||||
</InfoNote>
|
||||
|
||||
<ExtraItems title={translateMessage("Advanced")}>
|
||||
<InputRow label={translateMessage("Encryption Algorithm")}>
|
||||
<select bind:value={encryptionSettings.E2EEAlgorithm} disabled={!encryptionSettings.encrypt}>
|
||||
|
||||
Reference in New Issue
Block a user